OSDN Git Service

class post_officeを追加
authorcaprice <caprice@users.sourceforge.jp>
Tue, 29 Apr 2014 07:45:57 +0000 (16:45 +0900)
committercaprice <caprice@users.sourceforge.jp>
Tue, 29 Apr 2014 07:45:57 +0000 (16:45 +0900)
include/communication/post-office.hpp [new file with mode: 0644]

diff --git a/include/communication/post-office.hpp b/include/communication/post-office.hpp
new file mode 100644 (file)
index 0000000..a18b95d
--- /dev/null
@@ -0,0 +1,48 @@
+
+#ifndef GIKOMONA_CORE_POST_OFFICE_HPP
+#define GIKOMONA_CORE_POST_OFFICE_HPP
+
+#include <boost/optional.hpp>
+#include <boost/interprocess/managed_shared_memory.hpp>
+#include <boost/interprocess/containers/vector.hpp>
+#include <boost/interprocess/allocators/allocator.hpp>
+
+#include "GikoMona.hpp"
+#include "string.hpp"
+#include "communication.hpp"
+#include "message.hpp"
+#include "application-type.hpp"
+
+namespace monazilla { namespace GikoMona { namespace core { namespace communication {
+    
+class post_office {
+public:
+    explicit post_office(const communicate_id self_id);
+    ~post_office();
+    
+    bool connect(const communicate_id connect_to);
+    bool disconnect(const communicate_id disconnect_from);
+    bool disconnect_all();
+    
+    template <class MessageType>
+    bool send(const communicate_id to, MessageType&& msg);
+    
+    mona_string receive(const communicate_id originator_id);
+
+private:
+    bool send_string(const communicate_id to, mona_string&& src);
+    std::string create_mailbox_name(const communicate_id mb_user_id);
+    
+    const communicate_id self;
+    shared_memory gm_shmem; // GikoMona全体で共有されているメモリ
+    mailbox *my_mailbox;
+    std::unordered_map<communicate_id, mailbox> mailbox_map;
+    boost::interprocess::named_mutex my_mailbox_mutex;
+    
+    const char *shared_memory_name = "monazilla.GikoMona.shared-memory";
+    const char *ref_counter_name = "monazilla.GikoMona.reference-counter";
+};
+
+} } } }
+
+#endif // GIKOMONA_CORE_POST_OFFICE_HPP