#ifndef GIKOMONA_CORE_COMMUNICATION_POST_OFFICE_HPP
#define GIKOMONA_CORE_COMMUNICATION_POST_OFFICE_HPP
+#include <unordered_map>
+#include <algorithm>
+
#include <boost/optional.hpp>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/containers/vector.hpp>
* @warning 1つのプロセス中で複数回constructされた場合アプリケーション自体がabortする。
*/
class post_office {
+ typedef std::unordered_map<post_code, mailbox&> address_map;
+
public:
explicit post_office(const post_code& self_);
~post_office() noexcept;
template <class MessageType>
bool send(const post_code& to, MessageType&& msg);
+ bool register_mailbox(mailbox& obj);
+ bool unregister_mailbox(const mailbox& obj);
+ bool is_registered(const mailbox& obj);
+
+ void collect_mail_from_mailbox();
+ void forward_mail_to_another_postoffice();
+ void deliver_mail_to_mailbox();
+
mona_string receive(const post_code& originator_id);
+ void do_operation() {
+ collect_mail_from_mailbox();
+ forward_mail_to_another_postoffice();
+ deliver_mail_to_mailbox();
+
+ std::for_each(mail_address.begin(),
+ mail_address.end(),
+ [] (const address_map::value_type& val) {
+ if(val.second) {
+
+ }
+ });
+ }
+
static post_office* get_instance() {
if(!instance) { /* error? */ }
return instance;
private:
bool send_string(const post_code& to, mona_string&& src);
+
shared_memory gm_shmem; // アプリケーション群全体で共有されているメモリ
const post_code self_code;
+ address_map mail_address;
+ mailbox tempolary_mailbox;
- const char *shared_memory_name = "monazilla.GikoMona.shared-memory";
- const char *ref_counter_name = "monazilla.GikoMona.reference-counter";
+ const char *shared_memory_name = "org.monazilla.GikoMona.shared-memory";
+ const char *ref_counter_name = "org.monazilla.GikoMona.reference-counter";
static post_office* instance = nullptr;
};