realm-js/src/rpc.hpp

42 lines
878 B
C++
Raw Normal View History

/* Copyright 2015 Realm Inc - All Rights Reserved
* Proprietary and Confidential
*/
2015-10-22 10:44:10 -07:00
#pragma once
#import "json.hpp"
#import <JavaScriptCore/JavaScriptCore.h>
namespace realm {
class ObjectSchema;
}
namespace realm_js {
using json = nlohmann::json;
using RPCObjectID = u_int64_t;
using RPCRequest = std::function<json(const json)>;
class RPCServer {
public:
RPCServer();
~RPCServer();
2015-10-22 16:49:32 -07:00
json perform_request(std::string name, json &args);
2015-10-22 10:44:10 -07:00
private:
2015-10-22 17:59:05 -07:00
JSGlobalContextRef m_context;
std::map<std::string, RPCRequest> m_requests;
std::map<RPCObjectID, JSObjectRef> m_objects;
RPCObjectID m_session_id;
2015-10-22 10:44:10 -07:00
RPCObjectID store_object(JSObjectRef object);
json serialize_json_value(JSValueRef value);
JSValueRef deserialize_json_value(const json dict);
2015-10-26 15:27:43 -07:00
json serialize_object_schema(const realm::ObjectSchema &objectSchema);
2015-10-22 10:44:10 -07:00
};
}