Skip to content

Commit

Permalink
Merge pull request #97 from blu3beri/fix/use-multiple-turbo-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
berendsliedrecht authored Feb 13, 2023
2 parents 1b1d0ad + d4c6a7b commit 904c3a8
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct AriesAskarModule : jni::JavaClass<AriesAskarModule> {
auto runtime = reinterpret_cast<jsi::Runtime*>(jsiRuntimePointer);
auto jsCallInvoker = jsCallInvokerHolder->cthis()->getCallInvoker();

turboModuleUtility::registerTurboModule(*runtime, jsCallInvoker);
ariesAskarTurboModuleUtility::registerTurboModule(*runtime, jsCallInvoker);
}
};

Expand Down
20 changes: 10 additions & 10 deletions wrappers/javascript/aries-askar-react-native/cpp/HostObject.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

#include <HostObject.h>
#include <algorithm>
#include <vector>

TurboModuleHostObject::TurboModuleHostObject(jsi::Runtime &rt) { return; }
FunctionMap TurboModuleHostObject::functionMapping(jsi::Runtime &rt) {

AriesAskarTurboModuleHostObject::AriesAskarTurboModuleHostObject(jsi::Runtime &rt) { return; }
FunctionMap AriesAskarTurboModuleHostObject::functionMapping(jsi::Runtime &rt) {
FunctionMap fMap;

fMap.insert(std::make_tuple("version", &ariesAskar::version));
Expand Down Expand Up @@ -130,21 +130,21 @@ FunctionMap TurboModuleHostObject::functionMapping(jsi::Runtime &rt) {
return fMap;
}

jsi::Function TurboModuleHostObject::call(jsi::Runtime &rt, const char *name,
jsi::Function AriesAskarTurboModuleHostObject::call(jsi::Runtime &rt, const char *name,
Cb cb) {
return jsi::Function::createFromHostFunction(
rt, jsi::PropNameID::forAscii(rt, name), 1,
[this, cb](jsi::Runtime &rt, const jsi::Value &thisValue,
const jsi::Value *arguments, size_t count) -> jsi::Value {
const jsi::Value *val = &arguments[0];
turboModuleUtility::assertValueIsObject(rt, val);
ariesAskarTurboModuleUtility::assertValueIsObject(rt, val);
return (*cb)(rt, val->getObject(rt));
});
};

std::vector<jsi::PropNameID>
TurboModuleHostObject::getPropertyNames(jsi::Runtime &rt) {
auto fMap = TurboModuleHostObject::functionMapping(rt);
AriesAskarTurboModuleHostObject::getPropertyNames(jsi::Runtime &rt) {
auto fMap = AriesAskarTurboModuleHostObject::functionMapping(rt);
std::vector<jsi::PropNameID> result;
for (FunctionMap::iterator it = fMap.begin(); it != fMap.end(); ++it) {
result.push_back(jsi::PropNameID::forUtf8(rt, it->first));
Expand All @@ -153,13 +153,13 @@ TurboModuleHostObject::getPropertyNames(jsi::Runtime &rt) {
return result;
}

jsi::Value TurboModuleHostObject::get(jsi::Runtime &rt,
jsi::Value AriesAskarTurboModuleHostObject::get(jsi::Runtime &rt,
const jsi::PropNameID &propNameId) {
auto propName = propNameId.utf8(rt);
auto fMap = TurboModuleHostObject::functionMapping(rt);
auto fMap = AriesAskarTurboModuleHostObject::functionMapping(rt);
for (FunctionMap::iterator it = fMap.begin(); it != fMap.end(); ++it) {
if (it->first == propName) {
return TurboModuleHostObject::call(rt, it->first, it->second);
return AriesAskarTurboModuleHostObject::call(rt, it->first, it->second);
}
}

Expand Down
4 changes: 2 additions & 2 deletions wrappers/javascript/aries-askar-react-native/cpp/HostObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ using namespace facebook;
typedef jsi::Value (*Cb)(jsi::Runtime &rt, jsi::Object options);
typedef std::map<const char *, Cb> FunctionMap;

class JSI_EXPORT TurboModuleHostObject : public jsi::HostObject {
class JSI_EXPORT AriesAskarTurboModuleHostObject : public jsi::HostObject {
public:
TurboModuleHostObject(jsi::Runtime &rt);
AriesAskarTurboModuleHostObject(jsi::Runtime &rt);
jsi::Function call(jsi::Runtime &rt, const char *name, Cb cb);
FunctionMap functionMapping(jsi::Runtime &rt);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <include/libaries_askar.h>

using namespace turboModuleUtility;
using namespace ariesAskarTurboModuleUtility;

namespace ariesAskar {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <turboModuleUtility.h>

namespace turboModuleUtility {
namespace ariesAskarTurboModuleUtility {

using byteVector = std::vector<uint8_t>;

Expand All @@ -13,7 +13,7 @@ void registerTurboModule(jsi::Runtime &rt,
// Setting the callInvoker for async code
invoker = jsCallInvoker;
// Create a TurboModuleRustHostObject
auto instance = std::make_shared<TurboModuleHostObject>(rt);
auto instance = std::make_shared<AriesAskarTurboModuleHostObject>(rt);
// Create a JS equivalent object of the instance
jsi::Object jsInstance = jsi::Object::createFromHostObject(rt, instance);
// Register the object on global
Expand Down Expand Up @@ -325,4 +325,4 @@ jsi::ArrayBuffer secretBufferToArrayBuffer(jsi::Runtime &rt, SecretBuffer sb) {
return arrayBuffer;
}

} // namespace turboModuleUtility
} // namespace ariesAskarTurboModuleUtility
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

using namespace facebook;

namespace turboModuleUtility {
namespace ariesAskarTurboModuleUtility {

static const std::string errorPrefix = "Value `";
static const std::string errorInfix = "` is not of type ";
Expand Down Expand Up @@ -47,4 +47,4 @@ void callbackWithResponse(CallbackId result, ErrorCode code, T response);
jsi::ArrayBuffer byteBufferToArrayBuffer(jsi::Runtime &rt, ByteBuffer bb);
jsi::ArrayBuffer secretBufferToArrayBuffer(jsi::Runtime &rt, SecretBuffer sb);

} // namespace turboModuleUtility
} // namespace ariesAskarTurboModuleUtility
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ @implementation AriesAskar
}

auto callInvoker = bridge.jsCallInvoker;
turboModuleUtility::registerTurboModule(*jsiRuntime, callInvoker);
ariesAskarTurboModuleUtility::registerTurboModule(*jsiRuntime, callInvoker);
return @true;
}

Expand Down

0 comments on commit 904c3a8

Please sign in to comment.