diff --git a/ipaacalib/cpp/CMakeLists.txt b/ipaacalib/cpp/CMakeLists.txt index 688725b7a861ba801a9b2fd3b1f73c67f78b87cb..2f6243105a687126e0ef5e586c78e04507b4b0e7 100644 --- a/ipaacalib/cpp/CMakeLists.txt +++ b/ipaacalib/cpp/CMakeLists.txt @@ -13,6 +13,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DIPAACA_DEBUG_MESSAGES") # !! NOTE: at the moment required in any ipaaca cpp project in Windows !! set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DIPAACA_EXPOSE_FULL_RSB_API") +## use the following line to enable building mock IUs (FakeIU) +#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DIPAACA_BUILD_MOCK_OBJECTS") + # find cmake modules locally too set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules ) diff --git a/ipaacalib/cpp/include/ipaaca/ipaaca-buffers.h b/ipaacalib/cpp/include/ipaaca/ipaaca-buffers.h index ec57c3b8ee650c76016b3ef7ca77feb2f019c5fb..f5e4476bf447dc078f95af09af8fc42fc380605c 100644 --- a/ipaacalib/cpp/include/ipaaca/ipaaca-buffers.h +++ b/ipaacalib/cpp/include/ipaaca/ipaaca-buffers.h @@ -44,7 +44,7 @@ IPAACA_HEADER_EXPORT class IUStore: public std::map<std::string, boost::shared_p { }; /// Store for RemotePushIUs (used in InputBuffer) -IPAACA_HEADER_EXPORT class RemotePushIUStore: public std::map<std::string, boost::shared_ptr<RemotePushIU> > // TODO genericize to all remote IU types +IPAACA_HEADER_EXPORT class RemotePushIUStore: public std::map<std::string, boost::shared_ptr<RemotePushIU> > { }; @@ -142,7 +142,6 @@ IPAACA_HEADER_EXPORT class IUEventHandler {//{{{ public: IPAACA_HEADER_EXPORT IUEventHandler(IUEventHandlerFunction function, IUEventType event_mask, const std::string& category); IPAACA_HEADER_EXPORT IUEventHandler(IUEventHandlerFunction function, IUEventType event_mask, const std::set<std::string>& categories); - //void call(Buffer* buffer, const std::string& uid, bool local, IUEventType event_type, const std::string& category); IPAACA_HEADER_EXPORT void call(Buffer* buffer, boost::shared_ptr<IUInterface> iu, bool local, IUEventType event_type, const std::string& category); typedef boost::shared_ptr<IUEventHandler> ptr; };//}}} @@ -160,7 +159,6 @@ IPAACA_HEADER_EXPORT class Buffer { //: public boost::enable_shared_from_this<Bu friend class CallbackIUCommission; friend class CallbackIUResendRequest; protected: - //Lock _handler_lock; IPAACA_MEMBER_VAR_EXPORT std::string _uuid; IPAACA_MEMBER_VAR_EXPORT std::string _basename; IPAACA_MEMBER_VAR_EXPORT std::string _unique_name; @@ -174,7 +172,6 @@ IPAACA_HEADER_EXPORT class Buffer { //: public boost::enable_shared_from_this<Bu IPAACA_HEADER_EXPORT _IPAACA_ABSTRACT_ virtual void _send_iu_link_update(IUInterface* iu, bool is_delta, revision_t revision, const LinkMap& new_links, const LinkMap& links_to_remove, const std::string& writer_name="undef") = 0; IPAACA_HEADER_EXPORT _IPAACA_ABSTRACT_ virtual void _send_iu_payload_update(IUInterface* iu, bool is_delta, revision_t revision, const std::map<std::string, PayloadDocumentEntry::ptr>& new_items, const std::vector<std::string>& keys_to_remove, const std::string& writer_name="undef") = 0; IPAACA_HEADER_EXPORT _IPAACA_ABSTRACT_ virtual void _send_iu_commission(IUInterface* iu, revision_t revision, const std::string& writer_name="undef") = 0; -// IPAACA_HEADER_EXPORT _IPAACA_ABSTRACT_ virtual void _send_iu_resendrequest(IUInterface* iu, revision_t revision, const std::string& writer_name="undef") = 0; IPAACA_HEADER_EXPORT void _allocate_unique_name(const std::string& basename, const std::string& function); IPAACA_HEADER_EXPORT inline Buffer(const std::string& basename, const std::string& function) { _allocate_unique_name(basename, function); @@ -228,7 +225,6 @@ IPAACA_HEADER_EXPORT class Buffer { //: public boost::enable_shared_from_this<Bu * */ IPAACA_HEADER_EXPORT void register_handler(IUEventHandlerFunction function, IUEventType event_mask = IU_ALL_EVENTS, const std::string& category=""); - //_IPAACA_ABSTRACT_ virtual void add(boost::shared_ptr<IUInterface> iu) = 0; IPAACA_HEADER_EXPORT _IPAACA_ABSTRACT_ virtual boost::shared_ptr<IUInterface> get(const std::string& iu_uid) = 0; IPAACA_HEADER_EXPORT _IPAACA_ABSTRACT_ virtual std::set<boost::shared_ptr<IUInterface> > get_ius() = 0; @@ -253,7 +249,6 @@ IPAACA_HEADER_EXPORT class OutputBuffer: public Buffer { //, public boost::enabl friend class OutputBufferRsbAdaptor; protected: protected: - //OutputBufferRsbAdaptor _rsb; IPAACA_MEMBER_VAR_EXPORT IUStore _iu_store; IPAACA_MEMBER_VAR_EXPORT Lock _iu_id_counter_lock; #ifdef IPAACA_EXPOSE_FULL_RSB_API @@ -263,17 +258,10 @@ IPAACA_HEADER_EXPORT class OutputBuffer: public Buffer { //, public boost::enabl IPAACA_HEADER_EXPORT rsb::Informer<rsb::AnyType>::Ptr _get_informer(const std::string& category); #endif protected: - // informing functions IPAACA_HEADER_EXPORT void _send_iu_link_update(IUInterface* iu, bool is_delta, revision_t revision, const LinkMap& new_links, const LinkMap& links_to_remove, const std::string& writer_name="undef") _IPAACA_OVERRIDE_; IPAACA_HEADER_EXPORT void _publish_iu_resend(boost::shared_ptr<IU> iu, const std::string& hidden_scope_name) _IPAACA_OVERRIDE_; - IPAACA_HEADER_EXPORT void _send_iu_payload_update(IUInterface* iu, bool is_delta, revision_t revision, const std::map<std::string, PayloadDocumentEntry::ptr>& new_items, const std::vector<std::string>& keys_to_remove, const std::string& writer_name="undef") _IPAACA_OVERRIDE_; IPAACA_HEADER_EXPORT void _send_iu_commission(IUInterface* iu, revision_t revision, const std::string& writer_name) _IPAACA_OVERRIDE_; - //IPAACA_HEADER_EXPORT void _send_iu_resendrequest(IUInterface* iu, revision_t revision, const std::string& writer_name); - // remote access functions - // _remote_update_links(IULinkUpdate) - // _remote_update_payload(IUPayloadUpdate) - // _remote_commit(protobuf::IUCommission) IPAACA_HEADER_EXPORT void _publish_iu(boost::shared_ptr<IU> iu); /// mark and send IU retraction on own IU (removal from buffer is in remove(IU)) IPAACA_HEADER_EXPORT void _retract_iu(boost::shared_ptr<IU> iu); @@ -309,12 +297,11 @@ IPAACA_HEADER_EXPORT class InputBuffer: public Buffer { //, public boost::enable friend class IU; friend class RemotePushIU; friend class InputBufferRsbAdaptor; - //InputBufferRsbAdaptor _rsb; #ifdef IPAACA_EXPOSE_FULL_RSB_API protected: IPAACA_MEMBER_VAR_EXPORT std::map<std::string, rsb::ListenerPtr> _listener_store; IPAACA_MEMBER_VAR_EXPORT std::map<std::string, rsb::patterns::RemoteServerPtr> _remote_server_store; - IPAACA_MEMBER_VAR_EXPORT RemotePushIUStore _iu_store; // TODO genericize + IPAACA_MEMBER_VAR_EXPORT RemotePushIUStore _iu_store; IPAACA_HEADER_EXPORT rsb::patterns::RemoteServerPtr _get_remote_server(const std::string& unique_server_name); IPAACA_HEADER_EXPORT rsb::ListenerPtr _create_category_listener_if_needed(const std::string& category); IPAACA_HEADER_EXPORT void _handle_iu_events(rsb::EventPtr event); @@ -363,8 +350,6 @@ IPAACA_HEADER_EXPORT class InputBuffer: public Buffer { //, public boost::enable IPAACA_HEADER_EXPORT static boost::shared_ptr<InputBuffer> create(const std::string& basename, const std::set<std::string>& category_interests); /// Create InputBuffer from name and vector of category interests IPAACA_HEADER_EXPORT static boost::shared_ptr<InputBuffer> create(const std::string& basename, const std::vector<std::string>& category_interests); - // /// Create InputBuffer from name and initializer_list of category interests - // IPAACA_HEADER_EXPORT static boost::shared_ptr<InputBuffer> create(const std::string& basename, const std::initializer_list<std::string>& category_interests); /// Convenience function: create InputBuffer from name and one category interest IPAACA_HEADER_EXPORT static boost::shared_ptr<InputBuffer> create(const std::string& basename, const std::string& category_interest1); /// Convenience function: create InputBuffer from name and two category interests [DEPRECATED] diff --git a/ipaacalib/cpp/include/ipaaca/ipaaca-definitions.h b/ipaacalib/cpp/include/ipaaca/ipaaca-definitions.h index 6d9104e6bbf6973a2a83d862586ec25af32ad5f8..e91b9c31b966b34c9100aa64b403d5199f3d073f 100644 --- a/ipaacalib/cpp/include/ipaaca/ipaaca-definitions.h +++ b/ipaacalib/cpp/include/ipaaca/ipaaca-definitions.h @@ -49,9 +49,6 @@ #error "Please do not include this file directly, use ipaaca.h instead" #endif -// LAST FIXME LAST -//typedef boost::shared_ptr<rapidjson::Document> JsonDocPtr; - typedef uint32_t revision_t; /// Type of the IU event. Realized as an integer to enable bit masks for filters. One of: IU_ADDED, IU_COMMITTED, IU_DELETED, IU_RETRACTED, IU_UPDATED, IU_LINKSUPDATED, IU_MESSAGE @@ -139,7 +136,7 @@ IPAACA_HEADER_EXPORT class IUPublishedError: public Exception//{{{ { public: IPAACA_HEADER_EXPORT inline ~IUPublishedError() throw() { } - IPAACA_HEADER_EXPORT inline IUPublishedError() { //boost::shared_ptr<IU> iu) { + IPAACA_HEADER_EXPORT inline IUPublishedError() { _description = "IUPublishedError"; } };//}}} @@ -148,7 +145,7 @@ IPAACA_HEADER_EXPORT class IUCommittedError: public Exception//{{{ { public: IPAACA_HEADER_EXPORT inline ~IUCommittedError() throw() { } - IPAACA_HEADER_EXPORT inline IUCommittedError() { //boost::shared_ptr<IU> iu) { + IPAACA_HEADER_EXPORT inline IUCommittedError() { _description = "IUCommittedError"; } };//}}} @@ -157,7 +154,7 @@ IPAACA_HEADER_EXPORT class IURetractedError: public Exception//{{{ { public: IPAACA_HEADER_EXPORT inline ~IURetractedError() throw() { } - IPAACA_HEADER_EXPORT inline IURetractedError() { //boost::shared_ptr<IU> iu) { + IPAACA_HEADER_EXPORT inline IURetractedError() { _description = "IURetractedError"; } };//}}} @@ -166,7 +163,7 @@ IPAACA_HEADER_EXPORT class IUUpdateFailedError: public Exception//{{{ { public: IPAACA_HEADER_EXPORT inline ~IUUpdateFailedError() throw() { } - IPAACA_HEADER_EXPORT inline IUUpdateFailedError() { //boost::shared_ptr<IU> iu) { + IPAACA_HEADER_EXPORT inline IUUpdateFailedError() { _description = "IUUpdateFailedError"; } };//}}} @@ -175,7 +172,7 @@ IPAACA_HEADER_EXPORT class IUResendRequestFailedError: public Exception//{{{ { public: IPAACA_HEADER_EXPORT inline ~IUResendRequestFailedError() throw() { } - IPAACA_HEADER_EXPORT inline IUResendRequestFailedError() { //boost::shared_ptr<IU> iu) { + IPAACA_HEADER_EXPORT inline IUResendRequestFailedError() { _description = "IUResendRequestFailedError"; } };//}}} @@ -184,7 +181,7 @@ IPAACA_HEADER_EXPORT class IUReadOnlyError: public Exception//{{{ { public: IPAACA_HEADER_EXPORT inline ~IUReadOnlyError() throw() { } - IPAACA_HEADER_EXPORT inline IUReadOnlyError() { //boost::shared_ptr<IU> iu) { + IPAACA_HEADER_EXPORT inline IUReadOnlyError() { _description = "IUReadOnlyError"; } };//}}} @@ -193,7 +190,7 @@ IPAACA_HEADER_EXPORT class IUAlreadyInABufferError: public Exception//{{{ { public: IPAACA_HEADER_EXPORT inline ~IUAlreadyInABufferError() throw() { } - IPAACA_HEADER_EXPORT inline IUAlreadyInABufferError() { //boost::shared_ptr<IU> iu) { + IPAACA_HEADER_EXPORT inline IUAlreadyInABufferError() { _description = "IUAlreadyInABufferError"; } };//}}} @@ -202,7 +199,7 @@ IPAACA_HEADER_EXPORT class IUUnpublishedError: public Exception//{{{ { public: IPAACA_HEADER_EXPORT inline ~IUUnpublishedError() throw() { } - IPAACA_HEADER_EXPORT inline IUUnpublishedError() { //boost::shared_ptr<IU> iu) { + IPAACA_HEADER_EXPORT inline IUUnpublishedError() { _description = "IUUnpublishedError"; } };//}}} @@ -211,7 +208,7 @@ IPAACA_HEADER_EXPORT class IUAlreadyHasAnUIDError: public Exception//{{{ { public: IPAACA_HEADER_EXPORT inline ~IUAlreadyHasAnUIDError() throw() { } - IPAACA_HEADER_EXPORT inline IUAlreadyHasAnUIDError() { //boost::shared_ptr<IU> iu) { + IPAACA_HEADER_EXPORT inline IUAlreadyHasAnUIDError() { _description = "IUAlreadyHasAnUIDError"; } };//}}} @@ -220,7 +217,7 @@ IPAACA_HEADER_EXPORT class IUAlreadyHasAnOwnerNameError: public Exception//{{{ { public: IPAACA_HEADER_EXPORT inline ~IUAlreadyHasAnOwnerNameError() throw() { } - IPAACA_HEADER_EXPORT inline IUAlreadyHasAnOwnerNameError() { //boost::shared_ptr<IU> iu) { + IPAACA_HEADER_EXPORT inline IUAlreadyHasAnOwnerNameError() { _description = "IUAlreadyHasAnOwnerNameError"; } };//}}} @@ -229,7 +226,7 @@ IPAACA_HEADER_EXPORT class UUIDGenerationError: public Exception//{{{ { public: IPAACA_HEADER_EXPORT inline ~UUIDGenerationError() throw() { } - IPAACA_HEADER_EXPORT inline UUIDGenerationError() { //boost::shared_ptr<IU> iu) { + IPAACA_HEADER_EXPORT inline UUIDGenerationError() { _description = "UUIDGenerationError"; } };//}}} @@ -238,7 +235,7 @@ IPAACA_HEADER_EXPORT class NotImplementedError: public Exception//{{{ { public: IPAACA_HEADER_EXPORT inline ~NotImplementedError() throw() { } - IPAACA_HEADER_EXPORT inline NotImplementedError() { //boost::shared_ptr<IU> iu) { + IPAACA_HEADER_EXPORT inline NotImplementedError() { _description = "NotImplementedError"; } };//}}} @@ -247,7 +244,7 @@ IPAACA_HEADER_EXPORT class PayloadTypeConversionError: public Exception//{{{ { public: IPAACA_HEADER_EXPORT inline ~PayloadTypeConversionError() throw() { } - IPAACA_HEADER_EXPORT inline PayloadTypeConversionError() { //boost::shared_ptr<IU> iu) { + IPAACA_HEADER_EXPORT inline PayloadTypeConversionError() { _description = "PayloadTypeConversionError"; } };//}}} @@ -256,7 +253,7 @@ IPAACA_HEADER_EXPORT class PayloadAddressingError: public Exception//{{{ { public: IPAACA_HEADER_EXPORT inline ~PayloadAddressingError() throw() { } - IPAACA_HEADER_EXPORT inline PayloadAddressingError() { //boost::shared_ptr<IU> iu) { + IPAACA_HEADER_EXPORT inline PayloadAddressingError() { _description = "PayloadAddressingError"; } };//}}} @@ -265,7 +262,7 @@ IPAACA_HEADER_EXPORT class JsonParsingError: public Exception//{{{ { public: IPAACA_HEADER_EXPORT inline ~JsonParsingError() throw() { } - IPAACA_HEADER_EXPORT inline JsonParsingError() { //boost::shared_ptr<IU> iu) { + IPAACA_HEADER_EXPORT inline JsonParsingError() { _description = "JsonParsingError"; } };//}}} @@ -274,7 +271,7 @@ IPAACA_HEADER_EXPORT class PayloadEntryProxyInvalidatedError: public Exception// { public: IPAACA_HEADER_EXPORT inline ~PayloadEntryProxyInvalidatedError() throw() { } - IPAACA_HEADER_EXPORT inline PayloadEntryProxyInvalidatedError() { //boost::shared_ptr<IU> iu) { + IPAACA_HEADER_EXPORT inline PayloadEntryProxyInvalidatedError() { _description = "PayloadEntryProxyInvalidatedError"; } };//}}} @@ -283,7 +280,7 @@ IPAACA_HEADER_EXPORT class PayloadIteratorInvalidError: public Exception//{{{ { public: IPAACA_HEADER_EXPORT inline ~PayloadIteratorInvalidError() throw() { } - IPAACA_HEADER_EXPORT inline PayloadIteratorInvalidError() { //boost::shared_ptr<IU> iu) { + IPAACA_HEADER_EXPORT inline PayloadIteratorInvalidError() { _description = "PayloadIteratorInvalidError"; } };//}}} @@ -300,11 +297,18 @@ IPAACA_HEADER_EXPORT class Initializer /// Initialize the backend [DEPRECATED] (old name, use initialize_backend() instead) [[deprecated("Use initialize_backend() instead")]] IPAACA_HEADER_EXPORT static void initialize_ipaaca_rsb_if_needed(); - /// Explicitly initialize the backend. No effect if already initialized. Automatically called during first Buffer construction. + /// Explicitly initialize the backend (usually not required). No effect if already initialized. Automatically called during first Buffer construction. IPAACA_HEADER_EXPORT static void initialize_backend(); IPAACA_HEADER_EXPORT static bool initialized(); IPAACA_HEADER_EXPORT static void dump_current_default_config(); protected: + /** Perform rsb pre-setup before the implicit initialization + * (when first instantiating something). Pre-setup includes + * finding the RSB plugin dir, looking through several parent + * directories for a path "deps/lib/rsb*"/plugins. The path + * can also be set directly (env var RSB_PLUGINS_CPP_PATH), + * which disables the automatic search. + */ IPAACA_HEADER_EXPORT static void auto_configure_rsb(); IPAACA_MEMBER_VAR_EXPORT static bool _initialized; }; @@ -332,10 +336,8 @@ IPAACA_HEADER_EXPORT class Initializer IPAACA_HEADER_EXPORT class CommandLineOptions { public: IPAACA_HEADER_EXPORT inline CommandLineOptions() - //: _unconsumed_argc(0), _unconsumed_argv(nullptr) { } IPAACA_HEADER_EXPORT inline ~CommandLineOptions() { - //if (_unconsumed_argv) delete[] _unconsumed_argv; } IPAACA_MEMBER_VAR_EXPORT std::map<std::string, std::string> param_opts; IPAACA_MEMBER_VAR_EXPORT std::map<std::string, bool> param_set; @@ -347,13 +349,7 @@ IPAACA_HEADER_EXPORT class CommandLineOptions { IPAACA_HEADER_EXPORT bool is_set(const std::string& o); IPAACA_HEADER_EXPORT void dump(); public: - //IPAACA_HEADER_EXPORT inline int unconsumed_argc() { return _unconsumed_argc; } - //IPAACA_HEADER_EXPORT inline char** unconsumed_argv() { return _unconsumed_argv; } - protected: - //IPAACA_MEMBER_VAR_EXPORT int _unconsumed_argc; - //IPAACA_MEMBER_VAR_EXPORT char** _unconsumed_argv; - public: - typedef boost::shared_ptr<CommandLineOptions> ptr; + typedef boost::shared_ptr<CommandLineOptions> ptr; }; /** @@ -407,7 +403,8 @@ class CommandLineParser { * The remaining options are packaged into a CommandLineOptions object. */ IPAACA_HEADER_EXPORT CommandLineOptions::ptr parse(int argc, char* const* argv); - typedef boost::shared_ptr<CommandLineParser> ptr; + public: + typedef boost::shared_ptr<CommandLineParser> ptr; }; //}}} // in ipaaca-string-utils.cc diff --git a/ipaacalib/cpp/include/ipaaca/ipaaca-forwards.h b/ipaacalib/cpp/include/ipaaca/ipaaca-forwards.h index 0d91d66fcb604b9bea353a8af46ba55b8eec49a3..f490dd9eb6a6d44356c133aa13201423981c7956 100644 --- a/ipaacalib/cpp/include/ipaaca/ipaaca-forwards.h +++ b/ipaacalib/cpp/include/ipaaca/ipaaca-forwards.h @@ -53,7 +53,6 @@ * forward declarations */ class PayloadDocumentEntry; -//class PayloadDocumentStore; class PayloadBatchUpdateLock; class PayloadEntryProxy; diff --git a/ipaacalib/cpp/include/ipaaca/ipaaca-internal.h b/ipaacalib/cpp/include/ipaaca/ipaaca-internal.h index b5609fde3d2a301c1c76fe9fe1067e74d4f05c4a..311d768a2f537e36b14d02f2bdc665e8efe53048 100644 --- a/ipaacalib/cpp/include/ipaaca/ipaaca-internal.h +++ b/ipaacalib/cpp/include/ipaaca/ipaaca-internal.h @@ -59,8 +59,6 @@ #ifdef IPAACA_EXPOSE_FULL_RSB_API -// ??? ///IPAACA_HEADER_EXPORT inline std::string json_to_string(PayloadDocumentEntry::ptr entry); - IPAACA_HEADER_EXPORT class CallbackIUPayloadUpdate: public rsb::patterns::Server::Callback<IUPayloadUpdate, int> {//{{{ protected: IPAACA_MEMBER_VAR_EXPORT Buffer* _buffer; diff --git a/ipaacalib/cpp/include/ipaaca/ipaaca-ius.h b/ipaacalib/cpp/include/ipaaca/ipaaca-ius.h index d19d7d0c358fd93edb0cd4e457d8f62b9b357530..7d7bc93ac2b2ccb909dc4fbe47dfbb3591f8662e 100644 --- a/ipaacalib/cpp/include/ipaaca/ipaaca-ius.h +++ b/ipaacalib/cpp/include/ipaaca/ipaaca-ius.h @@ -176,7 +176,6 @@ IPAACA_HEADER_EXPORT class IU: public IUInterface {//{{{ IPAACA_HEADER_EXPORT IU(const std::string& category, IUAccessMode access_mode=IU_ACCESS_PUSH, bool read_only=false, const std::string& payload_type="" ); // __ipaaca_static_option_default_payload_type public: IPAACA_HEADER_EXPORT inline ~IU() { - //IPAACA_IMPLEMENT_ME } [[deprecated("Please use the new argument order: category, payload_type, read_only")]] IPAACA_HEADER_EXPORT static boost::shared_ptr<IU> create(const std::string& category, IUAccessMode access_mode, bool read_only=false, const std::string& payload_type="" ); @@ -186,9 +185,6 @@ IPAACA_HEADER_EXPORT class IU: public IUInterface {//{{{ IPAACA_HEADER_EXPORT void commit() _IPAACA_OVERRIDE_; protected: IPAACA_HEADER_EXPORT virtual void _modify_links(bool is_delta, const LinkMap& new_links, const LinkMap& links_to_remove, const std::string& writer_name = "") _IPAACA_OVERRIDE_; - - //IPAACA_HEADER_EXPORT virtual void _publish_resend(boost::shared_ptr<IU> iu, const std::string& hidden_scope_name); - IPAACA_HEADER_EXPORT virtual void _modify_payload(bool is_delta, const std::map<std::string, PayloadDocumentEntry::ptr>& new_items, const std::vector<std::string>& keys_to_remove, const std::string& writer_name = "") _IPAACA_OVERRIDE_; protected: IPAACA_HEADER_EXPORT virtual void _internal_commit(const std::string& writer_name = ""); @@ -219,7 +215,6 @@ IPAACA_HEADER_EXPORT class Message: public IU {//{{{ IPAACA_HEADER_EXPORT Message(const std::string& category, IUAccessMode access_mode=IU_ACCESS_MESSAGE, bool read_only=true, const std::string& payload_type="" ); public: IPAACA_HEADER_EXPORT inline ~Message() { - //IPAACA_IMPLEMENT_ME } [[deprecated("Please use the new argument order: category, payload_type")]] IPAACA_HEADER_EXPORT static boost::shared_ptr<Message> create(const std::string& category, IUAccessMode access_mode, bool read_only=true, const std::string& payload_type="" ); @@ -247,7 +242,6 @@ IPAACA_HEADER_EXPORT class RemotePushIU: public IUInterface {//{{{ IPAACA_HEADER_EXPORT static boost::shared_ptr<RemotePushIU> create(); public: IPAACA_HEADER_EXPORT inline ~RemotePushIU() { - //IPAACA_IMPLEMENT_ME } IPAACA_HEADER_EXPORT inline Payload& payload() _IPAACA_OVERRIDE_ { return _payload; } IPAACA_HEADER_EXPORT inline const Payload& const_payload() const _IPAACA_OVERRIDE_ { return _payload; } @@ -276,7 +270,6 @@ IPAACA_HEADER_EXPORT class RemoteMessage: public IUInterface {//{{{ IPAACA_HEADER_EXPORT static boost::shared_ptr<RemoteMessage> create(); public: IPAACA_HEADER_EXPORT inline ~RemoteMessage() { - //IPAACA_IMPLEMENT_ME } IPAACA_HEADER_EXPORT inline Payload& payload() _IPAACA_OVERRIDE_ { return _payload; } IPAACA_HEADER_EXPORT inline const Payload& const_payload() const _IPAACA_OVERRIDE_ { return _payload; } @@ -292,6 +285,7 @@ IPAACA_HEADER_EXPORT class RemoteMessage: public IUInterface {//{{{ typedef boost::shared_ptr<RemoteMessage> ptr; };//}}} +#ifdef IPAACA_BUILD_MOCK_OBJECTS /// Mock IU for testing purposes. [INTERNAL] IPAACA_HEADER_EXPORT class FakeIU: public IUInterface {//{{{ friend class Buffer; @@ -320,5 +314,6 @@ IPAACA_HEADER_EXPORT class FakeIU: public IUInterface {//{{{ public: typedef boost::shared_ptr<FakeIU> ptr; };//}}} +#endif #endif diff --git a/ipaacalib/cpp/include/ipaaca/ipaaca-json.h b/ipaacalib/cpp/include/ipaaca/ipaaca-json.h deleted file mode 100644 index 30cac6c0594617ea28efd941bee08840b07eac93..0000000000000000000000000000000000000000 --- a/ipaacalib/cpp/include/ipaaca/ipaaca-json.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of IPAACA, the - * "Incremental Processing Architecture - * for Artificial Conversational Agents". - * - * Copyright (c) 2009-2015 Social Cognitive Systems Group - * (formerly the Sociable Agents Group) - * CITEC, Bielefeld University - * - * http://opensource.cit-ec.de/projects/ipaaca/ - * http://purl.org/net/ipaaca - * - * This file may be licensed under the terms of of the - * GNU Lesser General Public License Version 3 (the ``LGPL''), - * or (at your option) any later version. - * - * Software distributed under the License is distributed - * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either - * express or implied. See the LGPL for the specific language - * governing rights and limitations. - * - * You should have received a copy of the LGPL along with this - * program. If not, go to http://www.gnu.org/licenses/lgpl.html - * or write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The development of this software was supported by the - * Excellence Cluster EXC 277 Cognitive Interaction Technology. - * The Excellence Cluster EXC 277 is a grant of the Deutsche - * Forschungsgemeinschaft (DFG) in the context of the German - * Excellence Initiative. - */ - -/** - * \file ipaaca-json.h - * - * \brief Header file for JSON tests. [superfluous] - * - * Users should not include this file directly, but use ipaaca.h - * - * \author Ramin Yaghoubzadeh (ryaghoubzadeh@uni-bielefeld.de) - * \date March, 2015 - */ - -#ifndef __ipaaca_json_H__ -#define __ipaaca_json_H__ - -#include "rapidjson/document.h" -#include "rapidjson/prettywriter.h" -#include "rapidjson/filestream.h" -#include <cstdio> - -// Notes: -// - From http://stackoverflow.com/questions/10426924/json-root-element -// Actually there are two different JSON specifications. RFC 4627 requires a JSON text to be -// an object or an array. ECMA-262, 5th edition, section 15.12 does not impose this restriction. - - - -#endif // __IPAACA_JSON_H__ - diff --git a/ipaacalib/cpp/include/ipaaca/ipaaca-payload.h b/ipaacalib/cpp/include/ipaaca/ipaaca-payload.h index eaf8f43418ca2476299b85e665c41eadb9934eb2..f346f3f5b80384a12004500cf4e5c869a40f5b83 100644 --- a/ipaacalib/cpp/include/ipaaca/ipaaca-payload.h +++ b/ipaacalib/cpp/include/ipaaca/ipaaca-payload.h @@ -111,12 +111,6 @@ IPAACA_HEADER_EXPORT template<typename T> void pack_into_json_value(rapidjson::V valueobject.AddMember(key, newv, allocator); } } -/*IPAACA_HEADER_EXPORT template<> void pack_into_json_value(rapidjson::Value&, rapidjson::Document::AllocatorType&, const std::vector<std::string>&); -IPAACA_HEADER_EXPORT template<> void pack_into_json_value(rapidjson::Value&, rapidjson::Document::AllocatorType&, const std::list<std::string>&); -IPAACA_HEADER_EXPORT template<> void pack_into_json_value(rapidjson::Value&, rapidjson::Document::AllocatorType&, const std::map<std::string, std::string>&); -*/ - -// FIXME TODO locking / invalidating proxy on first write of a payload entry /// Single payload entry wrapping a rapidjson::Document with some conversion glue. Also handles copy-on-write Document cloning. <b>Internal type</b> - users generally do not see this. IPAACA_HEADER_EXPORT class PayloadDocumentEntry//{{{ @@ -125,18 +119,15 @@ IPAACA_HEADER_EXPORT class PayloadDocumentEntry//{{{ public: IPAACA_MEMBER_VAR_EXPORT ipaaca::Lock lock; IPAACA_MEMBER_VAR_EXPORT bool modified; - //IPAACA_MEMBER_VAR_EXPORT std::string json_source; IPAACA_MEMBER_VAR_EXPORT rapidjson::Document document; IPAACA_HEADER_EXPORT inline PayloadDocumentEntry(): modified(false) { } IPAACA_HEADER_EXPORT inline ~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); - //IPAACA_HEADER_EXPORT void update_json_source(); typedef std::shared_ptr<PayloadDocumentEntry> ptr; }; //}}} @@ -144,22 +135,6 @@ IPAACA_HEADER_EXPORT class PayloadDocumentEntry//{{{ typedef std::map<std::string, PayloadDocumentEntry::ptr> PayloadDocumentStore; -#if 0 -/** \brief Lock to accumulate payload changes into one single update transaction - * - */ -IPAACA_HEADER_EXPORT class PayloadBatchUpdateLock: public ipaaca::Lock -{ - friend class Payload; - protected: - Payload* _payload; - public: - IPAACA_HEADER_EXPORT inline PayloadBatchUpdateLock(): Lock() { } - IPAACA_HEADER_EXPORT void on_lock() override; - IPAACA_HEADER_EXPORT void on_unlock() override; -}; -#endif - /** \brief Central class containing the user-set payload of any IUInterface class (IU, Message, RemotePushIU or RemoteMessage) * * Obtained by calling payload() on any IUInterface derived object. Created during IU creation. @@ -178,17 +153,11 @@ IPAACA_HEADER_EXPORT class Payload: public Lock //{{{ friend class PayloadEntryProxy; friend class PayloadIterator; friend class FakeIU; - //friend class PayloadBatchUpdateLock; protected: IPAACA_MEMBER_VAR_EXPORT std::string _owner_name; - //IPAACA_MEMBER_VAR_EXPORT rapidjson::Document _json_document; - //IPAACA_MEMBER_VAR_EXPORT std::map<std::string, rapidjson::Document> _json_store; IPAACA_MEMBER_VAR_EXPORT PayloadDocumentStore _document_store; IPAACA_MEMBER_VAR_EXPORT boost::weak_ptr<IUInterface> _iu; - //IPAACA_MEMBER_VAR_EXPORT PayloadBatchUpdateLock _batch_update_lock; - // IPAACA_MEMBER_VAR_EXPORT Lock _payload_operation_mode_lock; //< enforcing atomicity wrt the bool flag below - // IPAACA_MEMBER_VAR_EXPORT bool _update_on_every_change; //< true: batch update not active; false: collecting updates (payload locked) IPAACA_MEMBER_VAR_EXPORT std::map<std::string, PayloadDocumentEntry::ptr> _collected_modifications; IPAACA_MEMBER_VAR_EXPORT std::vector<std::string> _collected_removals; @@ -199,13 +168,11 @@ IPAACA_HEADER_EXPORT class Payload: public Lock //{{{ /// inherited from ipaaca::Lock, finishing batch update collection mode IPAACA_HEADER_EXPORT void on_unlock() override; protected: - //IPAACA_HEADER_EXPORT ipaaca::Locker&& batch_update() { return std::move(ipaaca::Locker(*this); } IPAACA_HEADER_EXPORT void initialize(boost::shared_ptr<IUInterface> iu); IPAACA_HEADER_EXPORT inline void _set_owner_name(const std::string& name) { _owner_name = name; } IPAACA_HEADER_EXPORT void _remotely_enforced_wipe(); IPAACA_HEADER_EXPORT void _remotely_enforced_delitem(const std::string& k); IPAACA_HEADER_EXPORT void _remotely_enforced_setitem(const std::string& k, PayloadDocumentEntry::ptr entry); - //IPAACA_HEADER_EXPORT void _internal_replace_all(const std::map<std::string, PayloadDocumentEntry::ptr>& new_contents, const std::string& writer_name=""); IPAACA_HEADER_EXPORT void _internal_replace_all(const std::map<std::string, PayloadDocumentEntry::ptr>& new_contents, const std::string& writer_name=""); IPAACA_HEADER_EXPORT void _internal_merge(const std::map<std::string, PayloadDocumentEntry::ptr>& contents_to_merge, const std::string& writer_name=""); IPAACA_HEADER_EXPORT void _internal_set(const std::string& k, PayloadDocumentEntry::ptr v, const std::string& writer_name=""); @@ -221,11 +188,6 @@ IPAACA_HEADER_EXPORT class Payload: public Lock //{{{ IPAACA_HEADER_EXPORT operator std::map<std::string, std::string>(); /// remove a single payload entry IPAACA_HEADER_EXPORT inline void remove(const std::string& k) { _internal_remove(k); } - // FIXME: json: these two must support a bunch of standard types, not [only] json (users touch them) - // 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 /// Legacy / convenience function: set the whole payload map from a map string->string (all JSON types are also set as string, no interpretation) IPAACA_HEADER_EXPORT void set(const std::map<std::string, std::string>& all_elems); protected: @@ -235,7 +197,7 @@ IPAACA_HEADER_EXPORT class Payload: public Lock //{{{ public: [[deprecated("Use operator[] and operator std::string() instead")]] /// Read a single entry as string [DEPRECATED] (use string conversion in PayloadEntryProxy instead) - IPAACA_HEADER_EXPORT std::string get(const std::string& k); // DEPRECATED + IPAACA_HEADER_EXPORT std::string get(const std::string& k); protected: IPAACA_MEMBER_VAR_EXPORT unsigned long internal_revision; IPAACA_MEMBER_VAR_EXPORT inline void mark_revision_change() { internal_revision++; } @@ -267,7 +229,6 @@ IPAACA_HEADER_EXPORT class PayloadIterator//{{{ IPAACA_MEMBER_VAR_EXPORT Payload* _payload; IPAACA_MEMBER_VAR_EXPORT unsigned long reference_payload_revision; IPAACA_MEMBER_VAR_EXPORT PayloadDocumentStore::iterator raw_iterator; - //IPAACA_MEMBER_VAR_EXPORT bool is_end; protected: IPAACA_HEADER_EXPORT PayloadIterator(Payload* payload, PayloadDocumentStore::iterator&& pl_iter ); //, bool is_end); public: @@ -277,7 +238,6 @@ IPAACA_HEADER_EXPORT class PayloadIterator//{{{ IPAACA_HEADER_EXPORT std::shared_ptr<std::pair<std::string, PayloadEntryProxy> > operator->(); IPAACA_HEADER_EXPORT bool operator==(const PayloadIterator& ref); IPAACA_HEADER_EXPORT bool operator!=(const PayloadIterator& ref); - // constructor to create a new top-most parent proxy (from a payload key) }; //}}} @@ -382,13 +342,9 @@ IPAACA_HEADER_EXPORT class PayloadEntryProxy//{{{ /// Select list-style iteration for this proxy (to select iterator content type). Will throw if not actually list-type. See example in the class description. IPAACA_HEADER_EXPORT PayloadEntryProxyListDecorator as_list(); protected: - //IPAACA_MEMBER_VAR_EXPORT rapidjson::Document* _json_parent_node; - //IPAACA_MEMBER_VAR_EXPORT rapidjson::Document* _json_node; IPAACA_MEMBER_VAR_EXPORT Payload* _payload; IPAACA_MEMBER_VAR_EXPORT std::string _key; - // // new json stuff / hierarchical navigation - // IPAACA_MEMBER_VAR_EXPORT PayloadEntryProxy* parent; ///< Parent proxy (up to document root -> then null) IPAACA_MEMBER_VAR_EXPORT PayloadDocumentEntry::ptr document_entry; // contains lock and json Doc IPAACA_MEMBER_VAR_EXPORT bool existent; ///< Whether Value exists already (or else 'blindly' navigated) @@ -397,9 +353,6 @@ IPAACA_HEADER_EXPORT class PayloadEntryProxy//{{{ IPAACA_MEMBER_VAR_EXPORT std::string addressed_key; ///< Key that was used in map-style access /// currently navigated value in json tree (or a new Null value) IPAACA_MEMBER_VAR_EXPORT rapidjson::Value* json_value; ///< json value that corresponds to the current navigation (or nullptr) -/* protected: - IPAACA_HEADER_EXPORT void connect_to_existing_parents(); -*/ protected: // constructor to create a new top-most parent proxy (from a payload key) IPAACA_HEADER_EXPORT PayloadEntryProxy(Payload* payload, const std::string& key); @@ -440,7 +393,6 @@ IPAACA_HEADER_EXPORT class PayloadEntryProxy//{{{ PayloadDocumentEntry::ptr new_entry = document_entry->clone(); // copy-on-write, no lock required rapidjson::Value& newval = new_entry->get_or_create_nested_value_from_proxy_path(this); pack_into_json_value(newval, new_entry->document.GetAllocator(), t); - //new_entry->update_json_source(); _payload->set(_key, new_entry); return *this; } @@ -473,11 +425,6 @@ IPAACA_HEADER_EXPORT class PayloadEntryProxy//{{{ /// Copy value from below other json node, preserving types IPAACA_HEADER_EXPORT PayloadEntryProxy& operator=(const PayloadEntryProxy& otherproxy); - //IPAACA_HEADER_EXPORT PayloadEntryProxy& operator=(const std::string& value); - //IPAACA_HEADER_EXPORT PayloadEntryProxy& operator=(const char* value); - //IPAACA_HEADER_EXPORT PayloadEntryProxy& operator=(double value); - //IPAACA_HEADER_EXPORT PayloadEntryProxy& operator=(bool value); - /// Conversion to std::string (explicit or implicit) IPAACA_HEADER_EXPORT operator std::string(); /// Conversion to long (explicit or implicit) @@ -513,7 +460,7 @@ IPAACA_HEADER_EXPORT class PayloadEntryProxy//{{{ } return result; } - // FIXME why are these needed again? + // TODO maybe remove these deprecated converters later /// [DECPRECATED] use normal type conversion syntax instead [[deprecated("Use operator std::string() instead (i.e. explicit or implicit cast)")]] IPAACA_HEADER_EXPORT std::string to_str(); @@ -527,15 +474,6 @@ IPAACA_HEADER_EXPORT class PayloadEntryProxy//{{{ /// [DECPRECATED] use normal type conversion syntax instead [[deprecated("Use operator bool() instead (i.e. explicit or implicit cast)")]] IPAACA_HEADER_EXPORT bool to_bool(); - // getters (not needed since conversions are enough?) - //IPAACA_HEADER_EXPORT template<typename T> T get() { return json_value_cast<T>(json_value); } - // setters - //IPAACA_HEADER_EXPORT template<typename T> PayloadEntryProxy& set(T t); - /*{ - pack_into_json_value<T>(t); - connect_to_existing_parents(); - _payload->set(key, document_entry->document); - }*/ /// Append a supported type to a list-type payload value IPAACA_HEADER_EXPORT template<typename T> void push_back(T t) { @@ -603,18 +541,6 @@ IPAACA_HEADER_EXPORT class PayloadEntryProxy//{{{ _payload->set(_key, new_entry); } }; -// Available interpretations of payload entries (or children thereof) below. -// Usage of standard complex data structures (vector etc.) currently entails -// casting all entries to a uniform type (a-priori choice: std::string). -/* -IPAACA_HEADER_EXPORT template<> long PayloadEntryProxy::get(); -IPAACA_HEADER_EXPORT template<> double PayloadEntryProxy::get(); -IPAACA_HEADER_EXPORT template<> bool PayloadEntryProxy::get(); -IPAACA_HEADER_EXPORT template<> std::string PayloadEntryProxy::get(); -IPAACA_HEADER_EXPORT template<> std::vector<std::string> PayloadEntryProxy::get(); -IPAACA_HEADER_EXPORT template<> std::list<std::string> PayloadEntryProxy::get(); -IPAACA_HEADER_EXPORT template<> std::map<std::string, std::string> PayloadEntryProxy::get(); -*/ //}}} diff --git a/ipaacalib/cpp/include/ipaaca/ipaaca.h b/ipaacalib/cpp/include/ipaaca/ipaaca.h index 04f62ee0d2b2c45b079747a732007be22451c30e..df04ce4fc01696c208bcd742f93e1e9b0d1b3b66 100644 --- a/ipaacalib/cpp/include/ipaaca/ipaaca.h +++ b/ipaacalib/cpp/include/ipaaca/ipaaca.h @@ -67,9 +67,9 @@ IU payload contents: Payload, PayloadEntryProxy #define IPAACA_PROTOCOL_VERSION_MINOR 0 /// running release number of ipaaca-c++ -#define IPAACA_CPP_RELEASE_NUMBER 12 +#define IPAACA_CPP_RELEASE_NUMBER 13 /// date of last release number increment -#define IPAACA_CPP_RELEASE_DATE "2015-01-15" +#define IPAACA_CPP_RELEASE_DATE "2015-12-04" #ifndef __FUNCTION_NAME__ #ifdef WIN32 // Windows diff --git a/ipaacalib/cpp/include/ipaaca/util/notifier.h b/ipaacalib/cpp/include/ipaaca/util/notifier.h index c16a4dfc35be4729f4d447d405ac3ea658118be8..52ad449050fc97d279149c13b21e106291d3c603 100644 --- a/ipaacalib/cpp/include/ipaaca/util/notifier.h +++ b/ipaacalib/cpp/include/ipaaca/util/notifier.h @@ -3,8 +3,9 @@ * "Incremental Processing Architecture * for Artificial Conversational Agents". * - * Copyright (c) 2009-2013 Sociable Agents Group - * CITEC, Bielefeld University + * Copyright (c) 2009-2015 Social Cognitive Systems Group + * (formerly the Sociable Agents Group) + * CITEC, Bielefeld University * * http://opensource.cit-ec.de/projects/ipaaca/ * http://purl.org/net/ipaaca diff --git a/ipaacalib/cpp/src/ipaaca-buffers.cc b/ipaacalib/cpp/src/ipaaca-buffers.cc index cec49b8b3fd5970bdbcdfc6e8053b6b71cfe9c57..63f52f234fbd264fa8b5e49f3f60ecfe45a2d07b 100644 --- a/ipaacalib/cpp/src/ipaaca-buffers.cc +++ b/ipaacalib/cpp/src/ipaaca-buffers.cc @@ -118,8 +118,6 @@ IPAACA_EXPORT IUEventHandler::IUEventHandler(IUEventHandlerFunction function, IU IPAACA_EXPORT void IUEventHandler::call(Buffer* buffer, boost::shared_ptr<IUInterface> iu, bool local, IUEventType event_type, const std::string& category) { if (_condition_met(event_type, category)) { - //IUInterface::ptr iu = buffer->get(uid); - //if (iu) { #if VERBOSE_HANDLERS == 1 std::cout << "[" << pthread_self() << " handler ENTER]" << std::endl; #endif @@ -127,7 +125,6 @@ IPAACA_EXPORT void IUEventHandler::call(Buffer* buffer, boost::shared_ptr<IUInte #if VERBOSE_HANDLERS == 1 std::cout << "[" << pthread_self() << " handler EXIT]" << std::endl; #endif - //} } } //}}} @@ -141,20 +138,19 @@ IPAACA_EXPORT void Buffer::_allocate_unique_name(const std::string& basename, co } IPAACA_EXPORT void Buffer::register_handler(IUEventHandlerFunction function, IUEventType event_mask, const std::set<std::string>& categories) { - //std::cout << "register_handler " << function << " " << event_mask << " " << categories << std::endl; + IPAACA_DEBUG("register_handler " << function << " " << event_mask << " " << categories) IUEventHandler::ptr handler = IUEventHandler::ptr(new IUEventHandler(function, event_mask, categories)); _event_handlers.push_back(handler); } IPAACA_EXPORT void Buffer::register_handler(IUEventHandlerFunction function, IUEventType event_mask, const std::string& category) { - //std::cout << "register_handler " << function << " " << event_mask << " " << category << std::endl; + IPAACA_DEBUG("register_handler " << function << " " << event_mask << " " << category) IUEventHandler::ptr handler = IUEventHandler::ptr(new IUEventHandler(function, event_mask, category)); _event_handlers.push_back(handler); } IPAACA_EXPORT void Buffer::call_iu_event_handlers(boost::shared_ptr<IUInterface> iu, bool local, IUEventType event_type, const std::string& category) { - //IPAACA_INFO("handling an event " << ipaaca::iu_event_type_to_str(event_type) << " for IU " << iu->uid()) - //std::cout << "handling an event " << ipaaca::iu_event_type_to_str(event_type) << " for IU " << iu->uid() << std::endl; + //IPAACA_DEBUG("handling an event " << ipaaca::iu_event_type_to_str(event_type) << " for IU " << iu->uid()) for (std::vector<IUEventHandler::ptr>::iterator it = _event_handlers.begin(); it != _event_handlers.end(); ++it) { (*it)->call(this, iu, local, event_type, category); } @@ -165,13 +161,10 @@ IPAACA_EXPORT void Buffer::call_iu_event_handlers(boost::shared_ptr<IUInterface> IPAACA_EXPORT CallbackIUPayloadUpdate::CallbackIUPayloadUpdate(Buffer* buffer): _buffer(buffer) { } IPAACA_EXPORT CallbackIULinkUpdate::CallbackIULinkUpdate(Buffer* buffer): _buffer(buffer) { } IPAACA_EXPORT CallbackIUCommission::CallbackIUCommission(Buffer* buffer): _buffer(buffer) { } -// dlw IPAACA_EXPORT CallbackIUResendRequest::CallbackIUResendRequest(Buffer* buffer): _buffer(buffer) { } IPAACA_EXPORT boost::shared_ptr<int> CallbackIUPayloadUpdate::call(const std::string& methodName, boost::shared_ptr<IUPayloadUpdate> update) { - IPAACA_INFO("") - //std::cout << "-- Received a modify_payload with " << update->new_items.size() << " keys to merge." << std::endl; IUInterface::ptr iui = _buffer->get(update->uid); if (! iui) { IPAACA_WARNING("Remote InBuffer tried to spuriously write non-existent IU " << update->uid) @@ -180,8 +173,8 @@ IPAACA_EXPORT boost::shared_ptr<int> CallbackIUPayloadUpdate::call(const std::st IU::ptr iu = boost::static_pointer_cast<IU>(iui); iu->_revision_lock.lock(); if ((update->revision != 0) && (update->revision != iu->_revision)) { - IPAACA_INFO("Remote write operation failed because request was out of date; IU " << update->uid) - IPAACA_INFO(" Referred-to revision was " << update->revision << " while local one is " << iu->_revision) + IPAACA_WARNING("Remote write operation failed because request was out of date; IU " << update->uid) + IPAACA_WARNING(" Referred-to revision was " << update->revision << " while local one is " << iu->_revision) iu->_revision_lock.unlock(); return boost::shared_ptr<int>(new int(0)); } else if (iu->committed()) { @@ -192,7 +185,7 @@ IPAACA_EXPORT boost::shared_ptr<int> CallbackIUPayloadUpdate::call(const std::st return boost::shared_ptr<int>(new int(0)); } if (update->is_delta) { - // FIXME FIXME this is an unsolved problem atm: deletes in a delta update are + // FIXME TODO this is an unsolved problem atm: deletions in a delta update are // sent individually. We should have something like _internal_merge_and_remove for (std::vector<std::string>::const_iterator it=update->keys_to_remove.begin(); it!=update->keys_to_remove.end(); ++it) { iu->payload()._internal_remove(*it, update->writer_name); //_buffer->unique_name()); @@ -202,7 +195,6 @@ IPAACA_EXPORT boost::shared_ptr<int> CallbackIUPayloadUpdate::call(const std::st } else { iu->payload()._internal_replace_all(update->new_items, update->writer_name); //_buffer->unique_name()); } - //std::cout << "-- Calling update handler due to remote write." << std::endl; _buffer->call_iu_event_handlers(iu, true, IU_UPDATED, iu->category()); revision_t revision = iu->revision(); iu->_revision_lock.unlock(); @@ -219,7 +211,7 @@ IPAACA_EXPORT boost::shared_ptr<int> CallbackIULinkUpdate::call(const std::strin IU::ptr iu = boost::static_pointer_cast<IU>(iui); iu->_revision_lock.lock(); if ((update->revision != 0) && (update->revision != iu->_revision)) { - IPAACA_INFO("Remote write operation failed because request was out of date; IU " << update->uid) + IPAACA_WARNING("Remote write operation failed because request was out of date; IU " << update->uid) iu->_revision_lock.unlock(); return boost::shared_ptr<int>(new int(0)); } else if (iu->committed()) { @@ -249,7 +241,7 @@ IPAACA_EXPORT boost::shared_ptr<int> CallbackIUCommission::call(const std::strin IU::ptr iu = boost::static_pointer_cast<IU>(iui); iu->_revision_lock.lock(); if ((update->revision() != 0) && (update->revision() != iu->_revision)) { - IPAACA_INFO("Remote write operation failed because request was out of date; IU " << update->uid()) + IPAACA_WARNING("Remote write operation failed because request was out of date; IU " << update->uid()) iu->_revision_lock.unlock(); return boost::shared_ptr<int>(new int(0)); } else if (iu->committed()) { @@ -266,7 +258,6 @@ IPAACA_EXPORT boost::shared_ptr<int> CallbackIUCommission::call(const std::strin iu->_revision_lock.unlock(); return boost::shared_ptr<int>(new int(revision)); } -/** dlw */ IPAACA_EXPORT boost::shared_ptr<int> CallbackIUResendRequest::call(const std::string& methodName, boost::shared_ptr<protobuf::IUResendRequest> update) { IUInterface::ptr iui = _buffer->get(update->uid()); @@ -276,12 +267,8 @@ IPAACA_EXPORT boost::shared_ptr<int> CallbackIUResendRequest::call(const std::st } IU::ptr iu = boost::static_pointer_cast<IU>(iui); if ((update->has_hidden_scope_name() == true)&&(update->hidden_scope_name().compare("") != 0)){ - //_buffer->call_iu_event_handlers(iu, true, IU_UPDATED, update->hidden_scope_name()); revision_t revision = iu->revision(); - _buffer->_publish_iu_resend(iu, update->hidden_scope_name()); - //iu->_publish_resend(iu, update->hidden_scope_name()); - return boost::shared_ptr<int>(new int(revision)); } else { revision_t revision = 0; @@ -295,25 +282,17 @@ IPAACA_EXPORT boost::shared_ptr<int> CallbackIUResendRequest::call(const std::st IPAACA_EXPORT OutputBuffer::OutputBuffer(const std::string& basename, const std::string& channel) :Buffer(basename, "OB") { - //IPAACA_INFO("Entering ...") _id_prefix = _basename + "-" + _uuid + "-IU-"; _channel = (channel=="") ? __ipaaca_static_option_default_channel: channel; _initialize_server(); - //IPAACA_INFO("... exiting.") } IPAACA_EXPORT void OutputBuffer::_initialize_server() { - //IPAACA_INFO("Entering ...") _server = getFactory().createLocalServer( Scope( _unique_name ) ); - //_server = getFactory().createServer( Scope( _unique_name ) ); - //IPAACA_INFO("Registering methods") _server->registerMethod("updatePayload", Server::CallbackPtr(new CallbackIUPayloadUpdate(this))); _server->registerMethod("updateLinks", Server::CallbackPtr(new CallbackIULinkUpdate(this))); _server->registerMethod("commit", Server::CallbackPtr(new CallbackIUCommission(this))); - // dlw _server->registerMethod("resendRequest", Server::CallbackPtr(new CallbackIUResendRequest(this))); - - //IPAACA_INFO("... exiting.") } IPAACA_EXPORT OutputBuffer::ptr OutputBuffer::create(const std::string& basename) { @@ -377,11 +356,6 @@ IPAACA_EXPORT void OutputBuffer::_send_iu_commission(IUInterface* iu, revision_t informer->publish(data); } - - - - - IPAACA_EXPORT void OutputBuffer::add(IU::ptr iu) { if (_iu_store.count(iu->uid()) > 0) { @@ -396,7 +370,7 @@ IPAACA_EXPORT void OutputBuffer::add(IU::ptr iu) // (for Message-type IUs: do not actually store them) _iu_store[iu->uid()] = iu; } - iu->_associate_with_buffer(this); //shared_from_this()); + iu->_associate_with_buffer(this); _publish_iu(iu); } @@ -414,17 +388,14 @@ IPAACA_EXPORT void OutputBuffer::_publish_iu_resend(IU::ptr iu, const std::strin informer->publish(iu_data); } - - - IPAACA_EXPORT Informer<AnyType>::Ptr OutputBuffer::_get_informer(const std::string& category) { if (_informer_store.count(category) > 0) { return _informer_store[category]; } else { - //IPAACA_INFO("Making new informer for category " << category) + //IPAACA_INFO("Creating new informer for category " << category << " on channel " << _channel) std::string scope_string = "/ipaaca/channel/" + _channel + "/category/" + category; - IPAACA_INFO("Adding informer on " << scope_string) + IPAACA_INFO("Creating new informer for " << scope_string) Informer<AnyType>::Ptr informer = getFactory().createInformer<AnyType> ( Scope(scope_string)); _informer_store[category] = informer; @@ -473,7 +444,6 @@ IPAACA_EXPORT OutputBuffer::~OutputBuffer() _retract_all_internal(); } - //}}} // InputBuffer//{{{ @@ -481,7 +451,6 @@ IPAACA_EXPORT InputBuffer::InputBuffer(const BufferConfiguration& bufferconfigur :Buffer(bufferconfiguration.get_basename(), "IB") { _channel = bufferconfiguration.get_channel(); - for (std::vector<std::string>::const_iterator it=bufferconfiguration.get_category_interests().begin(); it!=bufferconfiguration.get_category_interests().end(); ++it) { _create_category_listener_if_needed(*it); } @@ -492,7 +461,6 @@ IPAACA_EXPORT InputBuffer::InputBuffer(const std::string& basename, const std::s :Buffer(basename, "IB") { _channel = __ipaaca_static_option_default_channel; - for (std::set<std::string>::const_iterator it=category_interests.begin(); it!=category_interests.end(); ++it) { _create_category_listener_if_needed(*it); } @@ -503,29 +471,16 @@ IPAACA_EXPORT InputBuffer::InputBuffer(const std::string& basename, const std::v :Buffer(basename, "IB") { _channel = __ipaaca_static_option_default_channel; - for (std::vector<std::string>::const_iterator it=category_interests.begin(); it!=category_interests.end(); ++it) { _create_category_listener_if_needed(*it); } _create_category_listener_if_needed(_uuid); triggerResend = false; } -/*IPAACA_EXPORT InputBuffer::InputBuffer(const std::string& basename, const std::initializer_list<std::string>& category_interests) -:Buffer(basename, "IB") -{ - _channel = __ipaaca_static_option_default_channel; - - for (std::initializer_list<std::string>::const_iterator it=category_interests.begin(); it!=category_interests.end(); ++it) { - _create_category_listener_if_needed(*it); - } - _create_category_listener_if_needed(_uuid); - triggerResend = false; -}*/ IPAACA_EXPORT InputBuffer::InputBuffer(const std::string& basename, const std::string& category_interest1) :Buffer(basename, "IB") { _channel = __ipaaca_static_option_default_channel; - _create_category_listener_if_needed(category_interest1); _create_category_listener_if_needed(_uuid); triggerResend = false; @@ -534,7 +489,6 @@ IPAACA_EXPORT InputBuffer::InputBuffer(const std::string& basename, const std::s :Buffer(basename, "IB") { _channel = __ipaaca_static_option_default_channel; - _create_category_listener_if_needed(category_interest1); _create_category_listener_if_needed(category_interest2); _create_category_listener_if_needed(_uuid); @@ -544,7 +498,6 @@ IPAACA_EXPORT InputBuffer::InputBuffer(const std::string& basename, const std::s :Buffer(basename, "IB") { _channel = __ipaaca_static_option_default_channel; - _create_category_listener_if_needed(category_interest1); _create_category_listener_if_needed(category_interest2); _create_category_listener_if_needed(category_interest3); @@ -555,7 +508,6 @@ IPAACA_EXPORT InputBuffer::InputBuffer(const std::string& basename, const std::s :Buffer(basename, "IB") { _channel = __ipaaca_static_option_default_channel; - _create_category_listener_if_needed(category_interest1); _create_category_listener_if_needed(category_interest2); _create_category_listener_if_needed(category_interest3); @@ -600,7 +552,6 @@ IPAACA_EXPORT InputBuffer::ptr InputBuffer::create(const std::string& basename, return InputBuffer::ptr(new InputBuffer(basename, category_interest1, category_interest2, category_interest3, category_interest4)); } - IPAACA_EXPORT void InputBuffer::set_resend(bool resendActive) { triggerResend = resendActive; @@ -611,21 +562,19 @@ IPAACA_EXPORT bool InputBuffer::get_resend() return triggerResend; } - IPAACA_EXPORT IUInterface::ptr InputBuffer::get(const std::string& iu_uid) { - RemotePushIUStore::iterator it = _iu_store.find(iu_uid); // TODO genericize + RemotePushIUStore::iterator it = _iu_store.find(iu_uid); if (it==_iu_store.end()) return IUInterface::ptr(); return it->second; } IPAACA_EXPORT std::set<IUInterface::ptr> InputBuffer::get_ius() { std::set<IUInterface::ptr> set; - for (RemotePushIUStore::iterator it=_iu_store.begin(); it!=_iu_store.end(); ++it) set.insert(it->second); // TODO genericize + for (RemotePushIUStore::iterator it=_iu_store.begin(); it!=_iu_store.end(); ++it) set.insert(it->second); return set; } - IPAACA_EXPORT RemoteServerPtr InputBuffer::_get_remote_server(const std::string& unique_server_name) { std::map<std::string, RemoteServerPtr>::iterator it = _remote_server_store.find(unique_server_name); @@ -641,11 +590,10 @@ IPAACA_EXPORT ListenerPtr InputBuffer::_create_category_listener_if_needed(const if (it!=_listener_store.end()) { return it->second; } - //IPAACA_INFO("Creating a new listener for category " << category) std::string scope_string = "/ipaaca/channel/" + _channel + "/category/" + category; + IPAACA_INFO("Creating new listener for " << scope_string) ListenerPtr listener = getFactory().createListener( Scope(scope_string) ); - IPAACA_INFO("Adding listener on " << scope_string) HandlerPtr event_handler = HandlerPtr( new EventFunctionHandler( boost::bind(&InputBuffer::_handle_iu_events, this, _1) @@ -685,8 +633,6 @@ IPAACA_EXPORT void InputBuffer::_trigger_resend_request(EventPtr event) { boost::shared_ptr<int> result = server->call<int>("resendRequest", update, IPAACA_REMOTE_SERVER_TIMEOUT); if (*result == 0) { throw IUResendRequestFailedError(); - } else { - //std::cout << "revision " << *result << std::endl; } } } @@ -703,20 +649,13 @@ IPAACA_EXPORT void InputBuffer::_handle_iu_events(EventPtr event) iu->_set_buffer(this); call_iu_event_handlers(iu, false, IU_ADDED, iu->category() ); } - //IPAACA_INFO( "New RemotePushIU state: " << (*iu) ) } else if (type == "ipaaca::RemoteMessage") { boost::shared_ptr<RemoteMessage> iu = boost::static_pointer_cast<RemoteMessage>(event->getData()); - //_iu_store[iu->uid()] = iu; - //iu->_set_buffer(this); - //std::cout << "REFCNT after cast, before calling handlers: " << iu.use_count() << std::endl; call_iu_event_handlers(iu, false, IU_MESSAGE, iu->category() ); - //_iu_store.erase(iu->uid()); } else { RemotePushIUStore::iterator it; if (type == "ipaaca::IUPayloadUpdate") { boost::shared_ptr<IUPayloadUpdate> update = boost::static_pointer_cast<IUPayloadUpdate>(event->getData()); - //IPAACA_INFO("** writer name: " << update->writer_name) - //std::cout << "writer name " << update->writer_name << std::endl; if (update->writer_name == _unique_name) { return; } @@ -726,10 +665,8 @@ IPAACA_EXPORT void InputBuffer::_handle_iu_events(EventPtr event) IPAACA_INFO("Using UPDATED message for an IU that we did not fully receive before") return; } - it->second->_apply_update(update); call_iu_event_handlers(it->second, false, IU_UPDATED, it->second->category() ); - } else if (type == "ipaaca::IULinkUpdate") { boost::shared_ptr<IULinkUpdate> update = boost::static_pointer_cast<IULinkUpdate>(event->getData()); if (update->writer_name == _unique_name) { @@ -741,10 +678,8 @@ IPAACA_EXPORT void InputBuffer::_handle_iu_events(EventPtr event) IPAACA_INFO("Ignoring LINKSUPDATED message for an IU that we did not fully receive before") return; } - it->second->_apply_link_update(update); call_iu_event_handlers(it->second, false, IU_LINKSUPDATED, it->second->category() ); - } else if (type == "ipaaca::protobuf::IUCommission") { boost::shared_ptr<protobuf::IUCommission> update = boost::static_pointer_cast<protobuf::IUCommission>(event->getData()); if (update->writer_name() == _unique_name) { @@ -756,12 +691,9 @@ IPAACA_EXPORT void InputBuffer::_handle_iu_events(EventPtr event) IPAACA_INFO("Ignoring COMMITTED message for an IU that we did not fully receive before") return; } - // it->second->_apply_commission(); it->second->_revision = update->revision(); call_iu_event_handlers(it->second, false, IU_COMMITTED, it->second->category() ); - // - // } else if (type == "ipaaca::protobuf::IURetraction") { boost::shared_ptr<protobuf::IURetraction> update = boost::static_pointer_cast<protobuf::IURetraction>(event->getData()); it = _iu_store.find(update->uid()); @@ -770,7 +702,6 @@ IPAACA_EXPORT void InputBuffer::_handle_iu_events(EventPtr event) IPAACA_INFO("Ignoring RETRACTED message for an IU that we did not fully receive before") return; } - // it->second->_revision = update->revision(); it->second->_apply_retraction(); auto final_iu_ref = it->second; @@ -783,7 +714,6 @@ IPAACA_EXPORT void InputBuffer::_handle_iu_events(EventPtr event) IPAACA_WARNING("(Unhandled Event type " << type << " !)"); return; } - //IPAACA_INFO( "New RemotePushIU state: " << *(it->second) ) } } //}}} diff --git a/ipaacalib/cpp/src/ipaaca-cmdline-parser.cc b/ipaacalib/cpp/src/ipaaca-cmdline-parser.cc index 31b9f796b918d3e593cd206fc0843a65e18fc884..a5fe8d5cf8a4b4a897d776469da3e40ef5e5e0d0 100644 --- a/ipaacalib/cpp/src/ipaaca-cmdline-parser.cc +++ b/ipaacalib/cpp/src/ipaaca-cmdline-parser.cc @@ -3,8 +3,9 @@ * "Incremental Processing Architecture * for Artificial Conversational Agents". * - * Copyright (c) 2009-2013 Sociable Agents Group - * CITEC, Bielefeld University + * Copyright (c) 2009-2015 Social Cognitive Systems Group + * (formerly the Sociable Agents Group) + * CITEC, Bielefeld University * * http://opensource.cit-ec.de/projects/ipaaca/ * http://purl.org/net/ipaaca @@ -70,9 +71,7 @@ void CommandLineOptions::dump() { } } -// // Command line parser implementation -// CommandLineParser::CommandLineParser() : library_options_handled(true) diff --git a/ipaacalib/cpp/src/ipaaca-fake.cc b/ipaacalib/cpp/src/ipaaca-fake.cc index c0d27977a0a6574ae9219a3f733a9f1800d7e9a9..a5277ec3e57913b6febf9b70e5b80dc0296e7e5f 100644 --- a/ipaacalib/cpp/src/ipaaca-fake.cc +++ b/ipaacalib/cpp/src/ipaaca-fake.cc @@ -31,6 +31,7 @@ * Excellence Initiative. */ +#ifdef IPAACA_BUILD_MOCK_OBJECTS #include <ipaaca/ipaaca.h> namespace ipaaca { @@ -62,4 +63,5 @@ IPAACA_EXPORT inline void FakeIU::_apply_retraction() { } } // of namespace ipaaca +#endif diff --git a/ipaacalib/cpp/src/ipaaca-internal.cc b/ipaacalib/cpp/src/ipaaca-internal.cc index 148164f11d0c64f2805b9fb0b880477ad215c5ad..6ae283c2ebd17f361cf809ce18c925b24395dad3 100644 --- a/ipaacalib/cpp/src/ipaaca-internal.cc +++ b/ipaacalib/cpp/src/ipaaca-internal.cc @@ -51,14 +51,9 @@ IPAACA_EXPORT void Initializer::initialize_backend()//{{{ { if (_initialized) return; - //IPAACA_INFO("Calling auto_configure_rsb()") auto_configure_rsb(); - // RYT FIXME This configuration stuff has been simply removed in rsb! - //ParticipantConfig config = ParticipantConfig::fromConfiguration(); - //getFactory().setDefaultParticipantConfig(config); - - //IPAACA_INFO("Creating and registering Converters") + IPAACA_DEBUG("Creating and registering Converters") boost::shared_ptr<IUConverter> iu_converter(new IUConverter()); converterRepository<std::string>()->registerConverter(iu_converter); @@ -84,9 +79,8 @@ IPAACA_EXPORT void Initializer::initialize_backend()//{{{ boost::shared_ptr<IntConverter> int_converter(new IntConverter()); converterRepository<std::string>()->registerConverter(int_converter); - //IPAACA_INFO("Initialization complete.") + IPAACA_DEBUG("Backend / converter initialization complete.") _initialized = true; - //IPAACA_TODO("initialize all converters") }//}}} IPAACA_EXPORT void Initializer::dump_current_default_config()//{{{ { @@ -103,10 +97,6 @@ IPAACA_EXPORT void Initializer::dump_current_default_config()//{{{ }//}}} IPAACA_EXPORT void Initializer::auto_configure_rsb()//{{{ { - // quick hack to iterate through the pwd parents - // and find the closest rsb plugin dir - // - // but only if not yet defined const char* plugin_path = getenv("RSB_PLUGINS_CPP_PATH"); if (!plugin_path) { #ifdef WIN32 @@ -145,10 +135,7 @@ IPAACA_EXPORT IUConverter::IUConverter() IPAACA_EXPORT std::string IUConverter::serialize(const AnnotatedData& data, std::string& wire) { - //std::cout << "serialize" << std::endl; - // Ensure that DATA actually holds a datum of the data-type we expect. assert(data.first == getDataType()); // "ipaaca::IU" - // NOTE: a dynamic_pointer_cast cannot be used from void* boost::shared_ptr<const IU> obj = boost::static_pointer_cast<const IU> (data.second); boost::shared_ptr<protobuf::IU> pbo(new protobuf::IU()); // transfer obj data to pbo @@ -175,8 +162,6 @@ IPAACA_EXPORT std::string IUConverter::serialize(const AnnotatedData& data, std: for (auto& kv: obj->_payload._document_store) { protobuf::PayloadItem* item = pbo->add_payload(); item->set_key(kv.first); - //item->set_value( kv.second->to_json_string_representation() ); - //item->set_type("JSON"); IPAACA_DEBUG("Payload type: " << obj->_payload_type) if (obj->_payload_type=="JSON") { item->set_value( kv.second->to_json_string_representation() ); @@ -197,20 +182,16 @@ IPAACA_EXPORT std::string IUConverter::serialize(const AnnotatedData& data, std: pbo->SerializeToString(&wire); switch(obj->access_mode()) { case IU_ACCESS_PUSH: - //std::cout << "Requesting to send as ipaaca-iu" << std::endl; return "ipaaca-iu"; case IU_ACCESS_MESSAGE: - //std::cout << "Requesting to send as ipaaca-messageiu" << std::endl; return "ipaaca-messageiu"; default: - //std::cout << "Requesting to send as default" << std::endl; return getWireSchema(); } } IPAACA_EXPORT AnnotatedData IUConverter::deserialize(const std::string& wireSchema, const std::string& wire) { - //std::cout << "deserialize" << std::endl; assert(wireSchema == getWireSchema()); // "ipaaca-iu" boost::shared_ptr<protobuf::IU> pbo(new protobuf::IU()); pbo->ParseFromString(wire); @@ -249,7 +230,6 @@ IPAACA_EXPORT AnnotatedData IUConverter::deserialize(const std::string& wireSche ls.insert(pls.targets(j)); } } - //return std::make_pair(getDataType(), obj); return std::make_pair("ipaaca::RemotePushIU", obj); break; } @@ -287,12 +267,11 @@ IPAACA_EXPORT AnnotatedData IUConverter::deserialize(const std::string& wireSche ls.insert(pls.targets(j)); } } - //return std::make_pair(getDataType(), obj); return std::make_pair("ipaaca::RemoteMessage", obj); break; } default: - // other cases not handled yet! ( TODO ) + // no other cases (yet) throw NotImplementedError(); } } @@ -307,9 +286,7 @@ IPAACA_EXPORT MessageConverter::MessageConverter() IPAACA_EXPORT std::string MessageConverter::serialize(const AnnotatedData& data, std::string& wire) { - // Ensure that DATA actually holds a datum of the data-type we expect. assert(data.first == getDataType()); // "ipaaca::Message" - // NOTE: a dynamic_pointer_cast cannot be used from void* boost::shared_ptr<const Message> obj = boost::static_pointer_cast<const Message> (data.second); boost::shared_ptr<protobuf::IU> pbo(new protobuf::IU()); // transfer obj data to pbo @@ -336,8 +313,6 @@ IPAACA_EXPORT std::string MessageConverter::serialize(const AnnotatedData& data, for (auto& kv: obj->_payload._document_store) { protobuf::PayloadItem* item = pbo->add_payload(); item->set_key(kv.first); - //item->set_value( kv.second->to_json_string_representation() ); - //item->set_type("JSON"); if (obj->_payload_type=="JSON") { item->set_value( kv.second->to_json_string_representation() ); item->set_type("JSON"); @@ -361,7 +336,6 @@ IPAACA_EXPORT std::string MessageConverter::serialize(const AnnotatedData& data, case IU_ACCESS_MESSAGE: return "ipaaca-messageiu"; default: - //std::cout << "Requesting to send as default" << std::endl; return getWireSchema(); } @@ -406,7 +380,6 @@ IPAACA_EXPORT AnnotatedData MessageConverter::deserialize(const std::string& wir ls.insert(pls.targets(j)); } } - //return std::make_pair(getDataType(), obj); return std::make_pair("ipaaca::RemotePushIU", obj); break; } @@ -443,12 +416,11 @@ IPAACA_EXPORT AnnotatedData MessageConverter::deserialize(const std::string& wir ls.insert(pls.targets(j)); } } - //return std::make_pair(getDataType(), obj); return std::make_pair("ipaaca::RemoteMessage", obj); break; } default: - // other cases not handled yet! ( TODO ) + // no other cases (yet) throw NotImplementedError(); } } @@ -536,7 +508,7 @@ IPAACA_EXPORT IULinkUpdateConverter::IULinkUpdateConverter() IPAACA_EXPORT std::string IULinkUpdateConverter::serialize(const AnnotatedData& data, std::string& wire) { - assert(data.first == getDataType()); // "ipaaca::IULinkUpdate" + assert(data.first == getDataType()); boost::shared_ptr<const IULinkUpdate> obj = boost::static_pointer_cast<const IULinkUpdate> (data.second); boost::shared_ptr<protobuf::IULinkUpdate> pbo(new protobuf::IULinkUpdate()); // transfer obj data to pbo @@ -598,8 +570,7 @@ IPAACA_EXPORT IntConverter::IntConverter() IPAACA_EXPORT std::string IntConverter::serialize(const AnnotatedData& data, std::string& wire) { - // Ensure that DATA actually holds a datum of the data-type we expect. - assert(data.first == getDataType()); // "int" + assert(data.first == getDataType()); // NOTE: a dynamic_pointer_cast cannot be used from void* boost::shared_ptr<const int> obj = boost::static_pointer_cast<const int> (data.second); boost::shared_ptr<protobuf::IntMessage> pbo(new protobuf::IntMessage()); diff --git a/ipaacalib/cpp/src/ipaaca-iuinterface.cc b/ipaacalib/cpp/src/ipaaca-iuinterface.cc index 2c36848cbc6c29df0fc794e31e2927f6689d289e..1ea5975c4c8b3370642ac81a157a89d5e34576d5 100644 --- a/ipaacalib/cpp/src/ipaaca-iuinterface.cc +++ b/ipaacalib/cpp/src/ipaaca-iuinterface.cc @@ -70,7 +70,7 @@ IPAACA_EXPORT void IUInterface::_set_uid(const std::string& uid) { _uid = uid; } -IPAACA_EXPORT void IUInterface::_set_buffer(Buffer* buffer) { //boost::shared_ptr<Buffer> buffer) { +IPAACA_EXPORT void IUInterface::_set_buffer(Buffer* buffer) { if (_buffer) { throw IUAlreadyInABufferError(); } @@ -86,7 +86,7 @@ IPAACA_EXPORT void IUInterface::_set_owner_name(const std::string& owner_name) { } /// set the buffer pointer and the owner names of IU and Payload -IPAACA_EXPORT void IUInterface::_associate_with_buffer(Buffer* buffer) { //boost::shared_ptr<Buffer> buffer) { +IPAACA_EXPORT void IUInterface::_associate_with_buffer(Buffer* buffer) { _set_buffer(buffer); // will throw if already set _set_owner_name(buffer->unique_name()); payload()._set_owner_name(buffer->unique_name()); diff --git a/ipaacalib/cpp/src/ipaaca-ius.cc b/ipaacalib/cpp/src/ipaaca-ius.cc index 16e3216ff91bf8a90ed0ae41f12d2d2391f66b43..2626302121779f490b2d10d3af03f7e7c0da8e91 100644 --- a/ipaacalib/cpp/src/ipaaca-ius.cc +++ b/ipaacalib/cpp/src/ipaaca-ius.cc @@ -82,27 +82,6 @@ IPAACA_EXPORT void IU::_modify_links(bool is_delta, const LinkMap& new_links, co _revision_lock.unlock(); } - -/* - * IPAACA_EXPORT void IU::_publish_resend(IU::ptr iu, const std::string& hidden_scope_name) -{ - //_revision_lock.lock(); - //if (_committed) { - // _revision_lock.unlock(); - // throw IUCommittedError(); - //} - //_increase_revision_number(); - //if (is_published()) { - //IUInterface* iu, bool is_delta, revision_t revision, const LinkMap& new_links, const LinkMap& links_to_remove, const std::string& writer_name - _buffer->_publish_iu_resend(iu, hidden_scope_name); - //} - //_revision_lock.unlock(); -} -*/ - - - - IPAACA_EXPORT void IU::_modify_payload(bool is_delta, const std::map<std::string, PayloadDocumentEntry::ptr>& new_items, const std::vector<std::string>& keys_to_remove, const std::string& writer_name) { IPAACA_INFO("") @@ -196,13 +175,12 @@ void Message::_internal_commit(const std::string& writer_name) IPAACA_EXPORT RemotePushIU::ptr RemotePushIU::create() { - RemotePushIU::ptr iu = RemotePushIU::ptr(new RemotePushIU(/* params */)); + RemotePushIU::ptr iu = RemotePushIU::ptr(new RemotePushIU()); iu->_payload.initialize(iu); return iu; } IPAACA_EXPORT RemotePushIU::RemotePushIU() { - // nothing } IPAACA_EXPORT void RemotePushIU::_modify_links(bool is_delta, const LinkMap& new_links, const LinkMap& links_to_remove, const std::string& writer_name) { @@ -230,7 +208,7 @@ IPAACA_EXPORT void RemotePushIU::_modify_links(bool is_delta, const LinkMap& new } IPAACA_EXPORT void RemotePushIU::_modify_payload(bool is_delta, const std::map<std::string, PayloadDocumentEntry::ptr>& new_items, const std::vector<std::string>& keys_to_remove, const std::string& writer_name) { - //std::cout << "-- Sending a modify_payload with " << new_items.size() << " keys to merge." << std::endl; + IPAACA_DEBUG("Sending a modify_payload with " << new_items.size() << " keys to merge.") if (_committed) { throw IUCommittedError(); } else if (_retracted) { @@ -319,13 +297,12 @@ IPAACA_EXPORT void RemotePushIU::_apply_retraction() IPAACA_EXPORT RemoteMessage::ptr RemoteMessage::create() { - RemoteMessage::ptr iu = RemoteMessage::ptr(new RemoteMessage(/* params */)); + RemoteMessage::ptr iu = RemoteMessage::ptr(new RemoteMessage()); iu->_payload.initialize(iu); return iu; } IPAACA_EXPORT RemoteMessage::RemoteMessage() { - // nothing } IPAACA_EXPORT void RemoteMessage::_modify_links(bool is_delta, const LinkMap& new_links, const LinkMap& links_to_remove, const std::string& writer_name) { diff --git a/ipaacalib/cpp/src/ipaaca-json.cc b/ipaacalib/cpp/src/ipaaca-json.cc index dfdd83ee63adc0603c0f9340cd017d33bd14f9e7..2c2d1cd937e3ac0b7187dde5fb649ca276b20689 100644 --- a/ipaacalib/cpp/src/ipaaca-json.cc +++ b/ipaacalib/cpp/src/ipaaca-json.cc @@ -31,11 +31,34 @@ * Excellence Initiative. */ +/** + * \file ipaaca-json.cc + * + * \brief Testbed for ipaaca / JSON functionality + * + * This file is not used in the ipaaca library, but produces + * a separate program, if enabled in CMakeLists.txt + * + * \author Ramin Yaghoubzadeh (ryaghoubzadeh@uni-bielefeld.de) + * \date March, 2015 + */ + #include <ipaaca/ipaaca.h> -#include <ipaaca/ipaaca-json.h> +#include "rapidjson/document.h" +#include "rapidjson/prettywriter.h" +#include "rapidjson/filestream.h" + +#include <cstdio> #include <iomanip> +// Notes: +// - From http://stackoverflow.com/questions/10426924/json-root-element +// Actually there are two different JSON specifications. RFC 4627 requires a JSON text to be +// an object or an array. ECMA-262, 5th edition, section 15.12 does not impose this restriction. + + + using namespace rapidjson; using namespace std; @@ -107,6 +130,7 @@ int batch_update_main(int argc, char** argv)//{{{ } //}}} +#ifdef IPAACA_BUILD_MOCK_OBJECTS int iterators_main(int argc, char** argv)//{{{ { std::string json_source("[\n\ @@ -408,6 +432,7 @@ int fakeiu_main(int argc, char** argv)//{{{ return 0; } //}}} +#endif int legacy_iu_main(int argc, char** argv)//{{{ { diff --git a/ipaacalib/cpp/src/ipaaca-links.cc b/ipaacalib/cpp/src/ipaaca-links.cc index e0a6229068126ee2004768a040a4327efe8a32b4..33ff812efffa46ec3f7a42cf1bc316d4bef6763b 100644 --- a/ipaacalib/cpp/src/ipaaca-links.cc +++ b/ipaacalib/cpp/src/ipaaca-links.cc @@ -87,7 +87,6 @@ IPAACA_EXPORT void SmartLinkMap::_add_and_remove_links(const LinkMap& add, const } IPAACA_EXPORT void SmartLinkMap::_replace_links(const LinkMap& links) { - //_links.clear(); _links=links; } IPAACA_EXPORT const LinkSet& SmartLinkMap::get_links(const std::string& key) diff --git a/ipaacalib/cpp/src/ipaaca-payload.cc b/ipaacalib/cpp/src/ipaaca-payload.cc index 20cf7d3ad10282a3aeec579883e534a59be5b601..31a02c14b9df21ce6389e78d66532e39727095bf 100644 --- a/ipaacalib/cpp/src/ipaaca-payload.cc +++ b/ipaacalib/cpp/src/ipaaca-payload.cc @@ -53,10 +53,8 @@ std::string value_diagnosis(rapidjson::Value* val) if (val->IsArray()) return "array"; if (val->IsObject()) return "object"; return "other"; - } - IPAACA_EXPORT std::ostream& operator<<(std::ostream& os, const rapidjson::Value& val)//{{{ { os << json_value_cast<std::string>(val); @@ -126,12 +124,6 @@ IPAACA_EXPORT template<> long json_value_cast(const rapidjson::Value& v) if (v.IsNull()) return 0l; // default: return parse of string version (should always be 0 though?) throw PayloadTypeConversionError(); - /* - rapidjson::StringBuffer buffer; - rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); - v.Accept(writer); - return atol(std::string(buffer.GetString()).c_str()); - */ } IPAACA_EXPORT template<> int json_value_cast(const rapidjson::Value& v) { @@ -162,7 +154,6 @@ IPAACA_EXPORT template<> bool json_value_cast(const rapidjson::Value& v) if (v.IsString()) { std::string s = v.GetString(); return !((s=="")||(s=="false")||(s=="False")||(s=="0")); - //return ((s=="1")||(s=="true")||(s=="True")); } if (v.IsBool()) return v.GetBool(); if (v.IsNull()) return false; @@ -174,12 +165,6 @@ IPAACA_EXPORT template<> bool json_value_cast(const rapidjson::Value& v) // default: assume "pointer-like" semantics (i.e. objects are TRUE) return true; } -/* - * std::map<std::string, std::string> result; - std::for_each(_document_store.begin(), _document_store.end(), [&result](std::pair<std::string, PayloadDocumentEntry::ptr> pair) { - result[pair.first] = pair.second->document.GetString(); - }); - */ //}}} IPAACA_EXPORT void pack_into_json_value(rapidjson::Value& valueobject, rapidjson::Document::AllocatorType& allocator, int newvalue) @@ -206,25 +191,6 @@ IPAACA_EXPORT void pack_into_json_value(rapidjson::Value& valueobject, rapidjson { valueobject.SetString(newvalue, allocator); } -/* -IPAACA_EXPORT template<> void pack_into_json_value(rapidjson::Value& valueobject, rapidjson::Document::AllocatorType& allocator, const std::vector<std::string>& newvalue) -{ - valueobject.SetArray(); - for (auto& str: newvalue) { - rapidjson::Value sv; - sv.SetString(str, allocator); - valueobject.PushBack(sv, allocator); - } -} -IPAACA_EXPORT template<> void pack_into_json_value(rapidjson::Value& valueobject, rapidjson::Document::AllocatorType& allocator, const std::list<std::string>& newvalue) -{ - IPAACA_IMPLEMENT_ME -} -IPAACA_EXPORT template<> void pack_into_json_value(rapidjson::Value& valueobject, rapidjson::Document::AllocatorType& allocator, const std::map<std::string, std::string>& newvalue) -{ - IPAACA_IMPLEMENT_ME -} -*/ // PayloadDocumentEntry//{{{ IPAACA_EXPORT std::string PayloadDocumentEntry::to_json_string_representation() @@ -240,37 +206,25 @@ IPAACA_EXPORT PayloadDocumentEntry::ptr PayloadDocumentEntry::from_json_string_r if (entry->document.Parse(json_str.c_str()).HasParseError()) { throw JsonParsingError(); } - //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() -{ - json_source = to_json_string_representation(); -} -*/ - IPAACA_EXPORT PayloadDocumentEntry::ptr PayloadDocumentEntry::create_null() { PayloadDocumentEntry::ptr entry = std::make_shared<ipaaca::PayloadDocumentEntry>(); - //entry->json_source = "null"; // rapidjson::Document value is also null implicitly return entry; } IPAACA_EXPORT PayloadDocumentEntry::ptr PayloadDocumentEntry::clone() { - //auto entry = PayloadDocumentEntry::from_json_string_representation(this->json_source); auto entry = PayloadDocumentEntry::create_null(); entry->document.CopyFrom(this->document, entry->document.GetAllocator()); - IPAACA_DEBUG("Cloned for copy-on-write, contents: " << entry) + IPAACA_DEBUG("PayloadDocumentEntry cloned for copy-on-write, contents: " << entry) return entry; } IPAACA_EXPORT rapidjson::Value& PayloadDocumentEntry::get_or_create_nested_value_from_proxy_path(PayloadEntryProxy* pep) @@ -282,6 +236,7 @@ IPAACA_EXPORT rapidjson::Value& PayloadDocumentEntry::get_or_create_nested_value if (pep->addressed_as_array) { IPAACA_DEBUG("Addressed as array with index " << pep->addressed_index) if (! parent_value.IsArray()) { + IPAACA_INFO("parent value is not of type Array") throw PayloadAddressingError(); } else { long idx = pep->addressed_index; @@ -292,42 +247,13 @@ IPAACA_EXPORT rapidjson::Value& PayloadDocumentEntry::get_or_create_nested_value throw PayloadAddressingError(); } } - // for append / push_back? : - /*if (parent_value.IsNull()) { - wasnull = true; - parent_value.SetArray(); - } - if (wasnull || parent_value.IsArray()) { - long idx = pep->addressed_index; - long s = parent_value.Size(); - if (idx<s) { - // existing element modified - parent_value[idx] = *json_value; - } else { - // implicitly initialize missing elements to null values - if (idx>s) { - long missing_elements = pep->addressed_index - p; - for (int i=0; i<missing_elements; ++i) { - parent_value.PushBack(, allocator) - } - } - } - if (s == - } else { - throw PayloadAddressingError(); - }*/ } else { IPAACA_DEBUG("Addressed as dict with key " << pep->addressed_key) - // addressed as object (dict) - //rapidjson::Value& parent_value = *(pep->parent->json_value); if (! parent_value.IsObject()) { - IPAACA_DEBUG("parent is not of type Object") + IPAACA_INFO("parent value is not of type Object") throw PayloadAddressingError(); } else { rapidjson::Document::AllocatorType& allocator = document.GetAllocator(); - //Value key; - //key.SetString(pep->addressed_key, allocator); - //parent_value.AddMember(key, *json_value, allocator); rapidjson::Value key; key.SetString(pep->addressed_key, allocator); auto it = parent_value.FindMember(key); @@ -343,72 +269,10 @@ IPAACA_EXPORT rapidjson::Value& PayloadDocumentEntry::get_or_create_nested_value } } } - //}}} // PayloadEntryProxy//{{{ - // only if not top-level -#if 0 -IPAACA_EXPORT void PayloadEntryProxy::connect_to_existing_parents() -{ - rapidjson::Document::AllocatorType& allocator = document_entry->document.GetAllocator(); - PayloadEntryProxy* pep = this; - while (!(pep->existent) && pep->parent) { // only if not top-level - if (pep->addressed_as_array) { - rapidjson::Value& parent_value = *(pep->parent->json_value); - if (! parent_value.IsArray()) { - throw PayloadAddressingError(); - } else { - long idx = pep->addressed_index; - long s = parent_value.Size(); - if (idx<s) { - parent_value[idx] = *json_value; - } else { - throw PayloadAddressingError(); - } - } - /*if (parent_value.IsNull()) { - wasnull = true; - parent_value.SetArray(); - } - if (wasnull || parent_value.IsArray()) { - long idx = pep->addressed_index; - long s = parent_value.Size(); - if (idx<s) { - // existing element modified - parent_value[idx] = *json_value; - } else { - // implicitly initialize missing elements to null values - if (idx>s) { - long missing_elements = pep->addressed_index - p; - for (int i=0; i<missing_elements; ++i) { - parent_value.PushBack(, allocator) - } - } - } - if (s == - } else { - throw PayloadAddressingError(); - }*/ - } else { - // addressed as object (dict) - rapidjson::Value& parent_value = *(pep->parent->json_value); - if (! parent_value.IsObject()) { - throw PayloadAddressingError(); - } else { - Value key; - key.SetString(pep->addressed_key, allocator); - parent_value.AddMember(key, *json_value, allocator); - } - } - // repeat for next parent in the tree - pep = pep->parent; - } -} -#endif - - IPAACA_EXPORT PayloadEntryProxy::PayloadEntryProxy(Payload* payload, const std::string& key) : _payload(payload), _key(key), parent(nullptr) { @@ -447,11 +311,11 @@ IPAACA_EXPORT PayloadEntryProxy PayloadEntryProxy::operator[](const char* addr_k IPAACA_EXPORT PayloadEntryProxy PayloadEntryProxy::operator[](const std::string& addr_key_) { if (!json_value) { - IPAACA_DEBUG("Invalid json_value!") + IPAACA_INFO("Invalid json_value") throw PayloadAddressingError(); } if (! json_value->IsObject()) { - IPAACA_DEBUG("Expected Object for operator[](string)!") + IPAACA_INFO("Expected Object for operator[](string)") throw PayloadAddressingError(); } return PayloadEntryProxy(this, addr_key_); @@ -459,16 +323,16 @@ IPAACA_EXPORT PayloadEntryProxy PayloadEntryProxy::operator[](const std::string& IPAACA_EXPORT PayloadEntryProxy PayloadEntryProxy::operator[](size_t addr_idx_) { if (!json_value) { - IPAACA_DEBUG("Invalid json_value!") + IPAACA_INFO("Invalid json_value") throw PayloadAddressingError(); } if (! json_value->IsArray()) { - IPAACA_DEBUG("Expected Array for operator[](size_t)!") + IPAACA_INFO("Expected Array for operator[](size_t)") throw PayloadAddressingError(); } long s = json_value->Size(); if (addr_idx_>=s) { - IPAACA_DEBUG("Array out of bounds!") + IPAACA_INFO("Array out of bounds") throw PayloadAddressingError(); } return PayloadEntryProxy(this, addr_idx_); @@ -476,7 +340,7 @@ IPAACA_EXPORT PayloadEntryProxy PayloadEntryProxy::operator[](size_t addr_idx_) IPAACA_EXPORT PayloadEntryProxy PayloadEntryProxy::operator[](int addr_idx_) { if (addr_idx_ < 0) { - IPAACA_DEBUG("Negative index!") + IPAACA_INFO("Negative array index") throw PayloadAddressingError(); } return operator[]((size_t) addr_idx_); @@ -490,81 +354,41 @@ IPAACA_EXPORT PayloadEntryProxy& PayloadEntryProxy::operator=(const PayloadEntry if (valueptr) { // only set if value is valid, keep default null value otherwise newval.CopyFrom(*valueptr, new_entry->document.GetAllocator()); } - //new_entry->update_json_source(); _payload->set(_key, new_entry); return *this; } -/* -IPAACA_EXPORT PayloadEntryProxy& PayloadEntryProxy::operator=(const std::string& value) -{ - //std::cout << "operator=(string)" << std::endl; - IPAACA_IMPLEMENT_ME - //_payload->set(_key, value); - return *this; -} -IPAACA_EXPORT PayloadEntryProxy& PayloadEntryProxy::operator=(const char* value) -{ - //std::cout << "operator=(const char*)" << std::endl; - IPAACA_IMPLEMENT_ME - //_payload->set(_key, value); - return *this; -} -IPAACA_EXPORT PayloadEntryProxy& PayloadEntryProxy::operator=(double value) -{ - //std::cout << "operator=(double)" << std::endl; - IPAACA_IMPLEMENT_ME - //_payload->set(_key, boost::lexical_cast<std::string>(value)); - return *this; -} -IPAACA_EXPORT PayloadEntryProxy& PayloadEntryProxy::operator=(bool value) -{ - //std::cout << "operator=(bool)" << std::endl; - IPAACA_IMPLEMENT_ME - //_payload->set(_key, boost::lexical_cast<std::string>(value)); - return *this; -} -*/ - IPAACA_EXPORT PayloadEntryProxy::operator std::string() { return json_value_cast<std::string>(json_value); - //PayloadEntryProxy::get<std::string>(); } IPAACA_EXPORT PayloadEntryProxy::operator long() { return json_value_cast<long>(json_value); - //return PayloadEntryProxy::get<long>(); } IPAACA_EXPORT PayloadEntryProxy::operator double() { return json_value_cast<double>(json_value); - //return PayloadEntryProxy::get<double>(); } IPAACA_EXPORT PayloadEntryProxy::operator bool() { return json_value_cast<bool>(json_value); - //return PayloadEntryProxy::get<bool>(); } IPAACA_EXPORT std::string PayloadEntryProxy::to_str() { return json_value_cast<std::string>(json_value); - //return PayloadEntryProxy::get<std::string>(); } IPAACA_EXPORT long PayloadEntryProxy::to_long() { return json_value_cast<long>(json_value); - //return PayloadEntryProxy::get<long>(); } IPAACA_EXPORT double PayloadEntryProxy::to_float() { return json_value_cast<double>(json_value); - //return PayloadEntryProxy::get<double>(); } IPAACA_EXPORT bool PayloadEntryProxy::to_bool() { return json_value_cast<bool>(json_value); - //return PayloadEntryProxy::get<bool>(); } IPAACA_EXPORT PayloadEntryProxyMapDecorator PayloadEntryProxy::as_map() @@ -594,8 +418,8 @@ IPAACA_EXPORT bool PayloadEntryProxy::is_string() { return json_value && json_value->IsString(); } -/// is_number => whether it is *interpretable* as -/// a numerical value (i.e. including conversions) + +/// is_number => whether it is *interpretable* as a numerical value (i.e. including conversions) IPAACA_EXPORT bool PayloadEntryProxy::is_number() { if (!json_value) return false; @@ -615,58 +439,6 @@ IPAACA_EXPORT bool PayloadEntryProxy::is_map() return json_value && json_value->IsObject(); } -// -// new stuff for protocol v2 -// - -/* -IPAACA_EXPORT template<> std::string PayloadEntryProxy::get<std::string>() -{ - if (!json_value) return ""; - //IPAACA_INFO( value_diagnosis(json_value) ) - if (json_value->IsString()) return json_value->GetString(); - if (json_value->IsNull()) return ""; - rapidjson::StringBuffer buffer; - rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); - json_value->Accept(writer); - return buffer.GetString(); - - //return _payload->get(_key); -} -IPAACA_EXPORT template<> long PayloadEntryProxy::get<long>() -{ - return atof(operator std::string().c_str()); -} -IPAACA_EXPORT template<> double PayloadEntryProxy::get<double>() -{ - return atol(operator std::string().c_str()); -} -IPAACA_EXPORT template<> bool PayloadEntryProxy::get<bool>() -{ - std::string s = operator std::string(); - return ((s=="1")||(s=="true")||(s=="True")); -} -// complex types -IPAACA_EXPORT template<> std::list<std::string> PayloadEntryProxy::get<std::list<std::string> >() -{ - std::list<std::string> l; - l.push_back(PayloadEntryProxy::get<std::string>()); - return l; -} -IPAACA_EXPORT template<> std::vector<std::string> PayloadEntryProxy::get<std::vector<std::string> >() -{ - std::vector<std::string> v; - v.push_back(PayloadEntryProxy::get<std::string>()); - return v; -} -IPAACA_EXPORT template<> std::map<std::string, std::string> PayloadEntryProxy::get<std::map<std::string, std::string> >() -{ - std::map<std::string, std::string> m; - m["__automatic__"] = PayloadEntryProxy::get<std::string>(); - return m; -} -*/ - //}}} // Payload//{{{ @@ -674,19 +446,19 @@ IPAACA_EXPORT template<> std::map<std::string, std::string> PayloadEntryProxy::g IPAACA_EXPORT void Payload::on_lock() { Locker locker(_payload_operation_mode_lock); - IPAACA_DEBUG("Starting batch update mode ...") + IPAACA_DEBUG("Starting payload batch update mode ...") _update_on_every_change = false; } IPAACA_EXPORT void Payload::on_unlock() { Locker locker(_payload_operation_mode_lock); - IPAACA_DEBUG("... applying batch update with " << _collected_modifications.size() << " modifications and " << _collected_removals.size() << " removals ...") + IPAACA_DEBUG("... applying payload batch update with " << _collected_modifications.size() << " modifications and " << _collected_removals.size() << " removals ...") _internal_merge_and_remove(_collected_modifications, _collected_removals, _batch_update_writer_name); _update_on_every_change = true; _batch_update_writer_name = ""; _collected_modifications.clear(); _collected_removals.clear(); - IPAACA_DEBUG("... exiting batch update mode.") + IPAACA_DEBUG("... exiting payload batch update mode.") } IPAACA_EXPORT void Payload::initialize(boost::shared_ptr<IUInterface> iu) @@ -696,8 +468,6 @@ IPAACA_EXPORT void Payload::initialize(boost::shared_ptr<IUInterface> iu) IPAACA_EXPORT PayloadEntryProxy Payload::operator[](const std::string& key) { - // TODO atomicize - //boost::shared_ptr<PayloadEntryProxy> p(new PayloadEntryProxy(this, key)); return PayloadEntryProxy(this, key); } @@ -824,10 +594,6 @@ IPAACA_EXPORT void Payload::set(const std::map<std::string, std::string>& all_el { 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); @@ -909,7 +675,6 @@ IPAACA_EXPORT PayloadEntryProxyMapIterator::PayloadEntryProxyMapIterator(Payload IPAACA_EXPORT PayloadEntryProxyMapIterator& PayloadEntryProxyMapIterator::operator++() { - // prevent increase beyond end() ? raw_iterator++; return *this; } diff --git a/ipaacalib/cpp/src/ipaaca-string-utils.cc b/ipaacalib/cpp/src/ipaaca-string-utils.cc index d3192fc858aed0814dbde2494ddb822172e98095..2a3b1b5e4a9999ea1374705fa167dc61e2427515 100644 --- a/ipaacalib/cpp/src/ipaaca-string-utils.cc +++ b/ipaacalib/cpp/src/ipaaca-string-utils.cc @@ -3,8 +3,9 @@ * "Incremental Processing Architecture * for Artificial Conversational Agents". * - * Copyright (c) 2009-2013 Sociable Agents Group - * CITEC, Bielefeld University + * Copyright (c) 2009-2015 Social Cognitive Systems Group + * (formerly the Sociable Agents Group) + * CITEC, Bielefeld University * * http://opensource.cit-ec.de/projects/ipaaca/ * http://purl.org/net/ipaaca diff --git a/ipaacalib/cpp/src/ipaaca.cc b/ipaacalib/cpp/src/ipaaca.cc index 2e7f99510dcb8afda09c5019da4e40c9bce9583a..76ee5a58ba5b8863b26602798eefd0bece3f4f1a 100644 --- a/ipaacalib/cpp/src/ipaaca.cc +++ b/ipaacalib/cpp/src/ipaaca.cc @@ -76,18 +76,6 @@ IPAACA_EXPORT std::string __ipaaca_static_option_default_payload_type("JSON"); IPAACA_EXPORT std::string __ipaaca_static_option_default_channel("default"); IPAACA_EXPORT unsigned int __ipaaca_static_option_log_level(IPAACA_LOG_LEVEL_WARNING); -/* -void init_inprocess_too() { - //ParticipantConfig config = getFactory().getDefaultParticipantConfig(); - ParticipantConfig config = ParticipantConfig::fromFile("rsb.cfg"); - //ParticipantConfig::Transport inprocess = config.getTransport("inprocess"); - //inprocess.setEnabled(true); - //config.addTransport(inprocess); - getFactory().setDefaultParticipantConfig(config); -} -*/ - - } // of namespace ipaaca diff --git a/ipaacalib/cpp/src/util/notifier.cc b/ipaacalib/cpp/src/util/notifier.cc index df063512946b1482193e870c203473059445a921..aaca812a4a086cc5b8805072d6fed0005daa4cdf 100644 --- a/ipaacalib/cpp/src/util/notifier.cc +++ b/ipaacalib/cpp/src/util/notifier.cc @@ -3,8 +3,9 @@ * "Incremental Processing Architecture * for Artificial Conversational Agents". * - * Copyright (c) 2009-2013 Sociable Agents Group - * CITEC, Bielefeld University + * Copyright (c) 2009-2015 Social Cognitive Systems Group + * (formerly the Sociable Agents Group) + * CITEC, Bielefeld University * * http://opensource.cit-ec.de/projects/ipaaca/ * http://purl.org/net/ipaaca @@ -29,7 +30,16 @@ * Forschungsgemeinschaft (DFG) in the context of the German * Excellence Initiative. */ - + +/** + * \file util/notifier.cc + * + * \brief Component notification (i.e. module-level introspection). + * + * \author Ramin Yaghoubzadeh (ryaghoubzadeh@uni-bielefeld.de) + * \date March, 2015 + */ + #include <ipaaca/util/notifier.h> namespace ipaaca { @@ -71,20 +81,19 @@ ComponentNotifier::ptr ComponentNotifier::create(const std::string& componentNam void ComponentNotifier::handle_iu_event(IUInterface::ptr iu, IUEventType event_type, bool local) { - //std::cout << "handle_iu_event: got an event" << std::endl; if ((event_type == IU_ADDED) || (event_type == IU_UPDATED) || (event_type == IU_MESSAGE)) { Locker locker(lock); + IPAACA_DEBUG("Received a componentNotify") std::string cName = iu->payload()[_IPAACA_COMP_NOTIF_NAME]; std::string cState = iu->payload()[_IPAACA_COMP_NOTIF_STATE]; if (cName != name) { - //std::cout << " handle_iu_event: calling notification handlers" << std::endl; // call all registered notification handlers for (std::vector<IUEventHandlerFunction>::iterator it = _handlers.begin(); it != _handlers.end(); ++it) { (*it)(iu, event_type, local); } // send own info only if the remote component is a newly initialized one if (cState=="new") { - //std::cout << " handle_iu_event: Submitting own notification to new remote end" << std::endl; + //IPAACA_DEBUG("Submitting own componentNotify for new remote component") submit_notify(_IPAACA_COMP_NOTIF_STATE_OLD); } } @@ -106,7 +115,7 @@ void ComponentNotifier::submit_notify(const std::string& current_state) iu->payload()[_IPAACA_COMP_NOTIF_SEND_CATS] = send_categories; iu->payload()[_IPAACA_COMP_NOTIF_RECV_CATS] = recv_categories; out_buf->add(iu); - //LOG_IPAACA_CONSOLE( "Sending a ComponentNotify: " << name << " " << function << " " << current_state << " " << send_categories << " " << recv_categories ) + IPAACA_DEBUG( "Sending a componentNotify: " << name << ": " << current_state << " (" << function << ", " << send_categories << ", " << recv_categories << ")" ) } void ComponentNotifier::initialize() {