transaction rpc methods, return size when creating results

This commit is contained in:
Ari Lazier 2015-10-07 18:09:00 -06:00
parent a0f098bff3
commit 18641994c7
2 changed files with 35 additions and 1 deletions

View File

@ -26,6 +26,9 @@
#include "RJSRealm.hpp"
#include "RJSUtil.hpp"
#include "shared_realm.hpp"
#include "results.hpp"
using RPCObjectID = long;
using RPCRequest = std::function<std::string(NSDictionary *dictionary)>;
static std::map<std::string, RPCRequest> s_requests;
@ -48,6 +51,21 @@ static RPCObjectID s_id_counter = 0;
s_objects[realmId] = RealmConstructor(s_context, NULL, 1, &value, NULL);
return "{\"realmId\":" + std::to_string(realmId) + "}";
};
s_requests["/begin_transaction"] = [=](NSDictionary *dict) {
RPCObjectID realmId = [dict[@"realmId"] longValue];
RJSGetInternal<realm::SharedRealm *>(s_objects[realmId])->get()->begin_transaction();
return "{}";
};
s_requests["/cancel_transaction"] = [=](NSDictionary *dict) {
RPCObjectID realmId = [dict[@"realmId"] longValue];
RJSGetInternal<realm::SharedRealm *>(s_objects[realmId])->get()->cancel_transaction();
return "{}";
};
s_requests["/commit_transaction"] = [=](NSDictionary *dict) {
RPCObjectID realmId = [dict[@"realmId"] longValue];
RJSGetInternal<realm::SharedRealm *>(s_objects[realmId])->get()->commit_transaction();
return "{}";
};
s_requests["/create_object"] = [=](NSDictionary *dict) {
RPCObjectID newOid = s_id_counter++;
RPCObjectID realmId = [dict[@"realmId"] longValue];
@ -107,7 +125,8 @@ static RPCObjectID s_id_counter = 0;
JSValueRef results = RealmObjects(s_context, NULL, s_objects[realmId], argumentCount, arguments, &exception);
JSValueProtect(s_context, results);
s_objects[newOid] = (JSObjectRef)results;
return "{\"resultsId\":" + std::to_string(realmId) + "}";
size_t size = RJSGetInternal<realm::Results *>((JSObjectRef)results)->size();
return "{\"resultsId\":" + std::to_string(realmId) + ", \"size\":" + std::to_string(size) + "}";
};
s_requests["/get_results_size"] = [=](NSDictionary *dict) {
RPCObjectID resultsId = [dict[@"resultsId"] longValue];

View File

@ -604,6 +604,11 @@
"$(SRCROOT)/examples/ReactExample/node_modules/react-native/React/",
);
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
OTHER_CPLUSPLUSFLAGS = (
"$(OTHER_CFLAGS)",
"-isystem",
core/include,
);
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
@ -624,6 +629,11 @@
"$(SRCROOT)/examples/ReactExample/node_modules/react-native/React/",
);
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
OTHER_CPLUSPLUSFLAGS = (
"$(OTHER_CFLAGS)",
"-isystem",
core/include,
);
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
@ -644,6 +654,11 @@
"$(SRCROOT)/examples/ReactExample/node_modules/react-native/React/",
);
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
OTHER_CPLUSPLUSFLAGS = (
"$(OTHER_CFLAGS)",
"-isystem",
core/include,
);
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;