OSDN Git Service

communication/*をpost-officeとmailboxの二つ (あるいはこれに加えてpostboxつけて三つ) に分けることにしたため、shared_me...
authorcaprice <caprice@users.sourceforge.jp>
Tue, 29 Apr 2014 02:32:48 +0000 (11:32 +0900)
committercaprice <caprice@users.sourceforge.jp>
Tue, 29 Apr 2014 02:32:48 +0000 (11:32 +0900)
include/communication/communication.hpp

index 63f9907..60fe00e 100644 (file)
 
 #include "GikoMona.hpp"
 #include "string.hpp"
-#include "message.hpp"
-#include "application-type.hpp"
 
-namespace monazilla { namespace GikoMona { namespace core {
-
-class communication {
-public:
-    explicit communication(const communicate_id self_id);
-    ~communication();
-    
-    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:
-    typedef boost::interprocess::managed_shared_memory shared_memory;
-    
-    template <typename T>
-    using shared_memory_allocator
-        = boost::interprocess::allocator<T, shared_memory::segment_manager>;
-    
-    template <typename T>
-    using shared_list
-        = boost::interprocess::list<T, shared_memory_allocator<T>>;
+namespace monazilla { namespace GikoMona { namespace core { namespace communication {
     
-    typedef shared_list<mona_string> mailbox;
-    
-private:
-    template <typename T>
-    T *find_object(const std::string& name) {
-        return gm_shmem.find<T>(name.c_str()).first;
-    }
-    
-    template <typename T>
-    T *construct_object(const std::string& name) {
-        return gm_shmem.construct<T>(name.c_str())(shm.get_segment_manager());
-    }
-    
-    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;
+namespace process = boost::interprocess;
+
+typedef process::managed_shared_memory shared_memory;
+typedef shared_memory::segment_manager segment_manager;
+
+template <typename T>
+using shared_memory_allocator = process::allocator<T, segment_manager>;
     
-    const char *shared_memory_name = "monazilla.GikoMona.shared-memory";
-    const char *ref_counter_name = "monazilla.GikoMona.reference-counter";
-};
+template <typename T>
+using shared_list = process::list<T, shared_memory_allocator<T>>;
 
 template <class MessageType>
 bool communication::send(const communicate_id to, MessageType&& msg) {
@@ -83,6 +41,6 @@ bool communication::send_async(const communicate_id to, MessageType&& msg) {
     return send_string(to, msg.to_string());
 }
 
-} } }
+} } } }
 
 #endif // GIKOMONA_CORE_INTERPROCESS_COMMUNICATION_HPP