OSDN Git Service

プロセス間・クラス間通信のためのクラスを追加。
authorcaprice <caprice@users.sourceforge.jp>
Sun, 16 Mar 2014 16:00:16 +0000 (01:00 +0900)
committercaprice <caprice@users.sourceforge.jp>
Sun, 16 Mar 2014 16:00:16 +0000 (01:00 +0900)
include/communication.hpp [new file with mode: 0644]

diff --git a/include/communication.hpp b/include/communication.hpp
new file mode 100644 (file)
index 0000000..c5d9c04
--- /dev/null
@@ -0,0 +1,66 @@
+
+#ifndef GIKOMONA_CORE_INTERPROCESS_COMMUNICATION_HPP
+#define GIKOMONA_CORE_INTERPROCESS_COMMUNICATION_HPP
+
+#include <boost/optional.hpp>
+
+#include "string.hpp"
+
+namespace monazilla { namespace GikoMona { namespace core {
+
+typedef int communicate_id;
+
+enum class application_type : communicate_id {
+    COMMUNICATE_ID_APP = 0,
+    GM_U2 = 0, // GikoMona Update Utility
+    
+    GIKOMONA,
+    PNUTS,
+    
+    END_OF_COMMUNICATE_ID_APP = 100,
+    
+    /* 100-1000 は予約されている */
+    
+    COMMUNICATE_ID_USER = 1000
+};
+
+class communication {
+public:
+    explicit communication(const communicate_id from);
+    ~comunication();
+    
+    bool connect(const communicate_id connect_to);
+    bool disconnect(const communicate_id disconnect_from);
+    
+    template <class MessageType>
+    bool send(const communicate_id to, MessageType&& msg);
+    
+    template <class MessageType>
+    bool send_async(const communicate_id to, MessageType&& msg);
+    
+    boost::optional<mona_string> receive();
+    
+private:
+    bool send_string(const communicate_id to, mona_string&& src);
+    bool send_string_async(const communicate_id to, mona_string&& src);
+};
+
+template <class MessageType>
+bool communication::send(const communicate_id to, MessageType&& msg) {
+    static_assert(is_satisfied_message_concept<MessageType>(),
+                  "`MessageType' does not satisfy the `message_concept'");
+    
+    return send_string(to, msg.to_string());
+}
+
+template <class MessageType>
+bool communication::send_async(const communicate_id to, MessageType&& msg) {
+    static_assert(is_satisfied_message_concept<MessageType>(),
+                  "`MessageType' does not satisfy the `message_concept'");
+
+    return send_string(to, msg.to_string());
+}
+
+} } } 
+
+#endif // GIKOMONA_CORE_INTERPROCESS_COMMUNICATION_HPP