Skip to content
Snippets Groups Projects
Commit e900f27c authored by Ramin Yaghoubzadeh Torky's avatar Ramin Yaghoubzadeh Torky
Browse files

C++: reestablishing legacy compatibility / convenience functions

parent 05a29b0a
No related branches found
No related tags found
No related merge requests found
......@@ -110,6 +110,7 @@ IPAACA_HEADER_EXPORT class PayloadDocumentEntry//{{{
//IPAACA_HEADER_EXPORT PayloadDocumentEntry(const std::string& source): modified(false), json_source(source), {};
IPAACA_HEADER_EXPORT std::string to_json_string_representation();
IPAACA_HEADER_EXPORT static std::shared_ptr<PayloadDocumentEntry> from_json_string_representation(const std::string& input);
IPAACA_HEADER_EXPORT static std::shared_ptr<PayloadDocumentEntry> from_unquoted_string_value(const std::string& input);
IPAACA_HEADER_EXPORT static std::shared_ptr<PayloadDocumentEntry> create_null();
IPAACA_HEADER_EXPORT std::shared_ptr<PayloadDocumentEntry> clone();
IPAACA_HEADER_EXPORT rapidjson::Value& get_or_create_nested_value_from_proxy_path(PayloadEntryProxy* pep);
......@@ -211,6 +212,8 @@ IPAACA_HEADER_EXPORT class Payload//{{{
// to be more precise: types of map<string, T> with T several interesting things (string, list<string>, etc.)
//IPAACA_HEADER_EXPORT inline void set(const std::map<std::string, const rapidjson::Document&>& all_elems) { _internal_replace_all(all_elems); }
//IPAACA_HEADER_EXPORT inline void merge(const std::map<std::string, const rapidjson::Document&>& elems_to_merge) { _internal_merge(elems_to_merge); }
// legacy / convenience setter
IPAACA_HEADER_EXPORT void set(const std::map<std::string, std::string>& all_elems);
protected:
IPAACA_HEADER_EXPORT PayloadDocumentEntry::ptr get_entry(const std::string& k); // json, changed str to proxy here, too
public:
......
......@@ -406,6 +406,7 @@ IPAACA_EXPORT Informer<AnyType>::Ptr OutputBuffer::_get_informer(const std::stri
} else {
//IPAACA_INFO("Making new informer for category " << category)
std::string scope_string = "/ipaaca/channel/" + _channel + "/category/" + category;
IPAACA_INFO("Adding informer on " << scope_string)
Informer<AnyType>::Ptr informer = getFactory().createInformer<AnyType> ( Scope(scope_string));
_informer_store[category] = informer;
......@@ -591,17 +592,15 @@ IPAACA_EXPORT RemoteServerPtr InputBuffer::_get_remote_server(const std::string&
IPAACA_EXPORT ListenerPtr InputBuffer::_create_category_listener_if_needed(const std::string& category)
{
IPAACA_INFO("Entering ...")
std::map<std::string, ListenerPtr>::iterator it = _listener_store.find(category);
if (it!=_listener_store.end()) {
IPAACA_INFO("... exiting.")
return it->second;
}
//IPAACA_INFO("Creating a new listener for category " << category)
std::string scope_string = "/ipaaca/channel/" + _channel + "/category/" + category;
ListenerPtr listener = getFactory().createListener( Scope(scope_string) );
IPAACA_INFO("Adding handler")
IPAACA_INFO("Adding listener on " << scope_string)
HandlerPtr event_handler = HandlerPtr(
new EventFunctionHandler(
boost::bind(&InputBuffer::_handle_iu_events, this, _1)
......@@ -609,7 +608,6 @@ IPAACA_EXPORT ListenerPtr InputBuffer::_create_category_listener_if_needed(const
);
listener->addHandler(event_handler);
_listener_store[category] = listener;
IPAACA_INFO("... exiting.")
return listener;
}
IPAACA_EXPORT void InputBuffer::_trigger_resend_request(EventPtr event) {
......
......@@ -218,6 +218,13 @@ IPAACA_EXPORT PayloadDocumentEntry::ptr PayloadDocumentEntry::from_json_string_r
entry->json_source = json_str;
return entry;
}
IPAACA_EXPORT PayloadDocumentEntry::ptr PayloadDocumentEntry::from_unquoted_string_value(const std::string& str)
{
PayloadDocumentEntry::ptr entry = std::make_shared<ipaaca::PayloadDocumentEntry>();
entry->document.SetString(str.c_str(), entry->document.GetAllocator());
entry->update_json_source();
return entry;
}
/// update json_source after a write operation (on newly cloned entries)
IPAACA_EXPORT void PayloadDocumentEntry::update_json_source()
......@@ -642,6 +649,20 @@ IPAACA_EXPORT std::string Payload::get(const std::string& k) { // DEPRECATED
if (_document_store.count(k)>0) return _document_store[k]->document.GetString();
return "";
}
IPAACA_EXPORT void Payload::set(const std::map<std::string, std::string>& all_elems)
{
std::map<std::string, PayloadDocumentEntry::ptr> newmap;
for (auto& kv: all_elems) {
/*PayloadDocumentEntry::ptr newit = PayloadDocumentEntry::create_null();
newit->document.SetString(kv.second, newit->document.GetAllocator());
newit->update_json_source();
newmap[kv.first] = newit;*/
newmap[kv.first] = PayloadDocumentEntry::from_unquoted_string_value(kv.second);
}
_internal_replace_all(newmap);
}
IPAACA_EXPORT void Payload::_remotely_enforced_wipe()
{
_document_store.clear();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment