From f7f4d5b6067fd075564a88efd64ac5d7fa905187 Mon Sep 17 00:00:00 2001 From: caprice Date: Tue, 13 May 2014 20:05:35 +0900 Subject: [PATCH] =?utf8?q?communication.hpp=E3=81=AE=E5=90=8D=E5=89=8D?= =?utf8?q?=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/communication.cpp | 87 --------------------------------------------------- 1 file changed, 87 deletions(-) delete mode 100644 src/communication.cpp diff --git a/src/communication.cpp b/src/communication.cpp deleted file mode 100644 index a6b430f..0000000 --- a/src/communication.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include - -#include - -#include "reference-counter.hpp" - -#include "communication/communication.hpp" -#include "communication/message/request.hpp" -#include "communication/message/failure.hpp" -#include "communication/message/succeed.hpp" - -namespace ipc = boost::interprocess; - -namespace monazilla { namespace GikoMona { namespace core { - -communication::communication(const communicate_id self_id) : self(self_id) { - gm_shmem = shared_memory(ipc::open_or_create, shared_memory_name, 1024 * 4); - - my_mailbox = construct_object(create_mailbox_name(self)); - - if(auto obj = find_object(ref_counter_name)) { - auto locker = obj->scoped_lock(); - ++(*obj); - } else { - construct_object(ref_counter_name); - } -} - -communication::~communication() { - disconnect_all(); - - if(auto obj = find_object(ref_counter_name)) { - if(obj->count() == 1) { - ipc::shared_memory_object::remove(shared_memory_name); - } else { - auto locker = obj->scoped_lock(); - --(*obj); - } - } else { - /* error!!!!! */ - } -} - -bool communication::connect(const communicate_id connect_to) { - auto obj = find_object(gm_shmem, create_mailbox_name(connect_to)); - - if(obj) { - mailbox_map[connect_to] = *obj; - send(connect_to, succeed::find_your_mailbox("").to_string()); - - do { - mona_string mail = receive(connect_to); - } while(is_same_mail(mail, succeed::allow_you_to_send_mail(""))); - } - - return obj; -} - -bool communication::disconnect(const communicate_id disconnect_from) { - return mailbox_map.erase(disconnect_from); -} - -mona_string communication::receive(const communicate_id originator_id) { - boost::find_if -} - -bool communication::send_string(const communicate_id to, mona_string&& src) { - auto obj = find_object(gm_shmem, create_mailbox_name(to)); - - if(obj) { - std::ostringstream str_builder; - str_builder << to_string(self) << "-" << src; - - obj->push_back(str_builder.str()); - } - - return obj; -} - -std::string communication::create_mailbox_name(const communicate_id mb_user_id) { - std::ostringstream str_builder; - str_builder << "mailbox:" << to_string(mb_user_id); - - return str_builder.str(); -} - -} } } -- 2.11.0