• R/O
  • HTTP
  • SSH
  • HTTPS

libcore: コミット

GikoMonaのソフトウェアの基幹部分を集めて1つのライブラリに集約したものです。gikomona/pnutsのコンパイルにはこのライブラリが必須です。


コミットメタ情報

リビジョンb3eb4cb2a20076e6d2c0d9b280bc74e3dfd4ad17 (tree)
日時2014-08-10 13:53:40
作者caprice <caprice@user...>
コミッターcaprice

ログメッセージ

予告通り、communicationを切り離した。

変更サマリ

  • delete: include/communication/mail.hpp
  • delete: include/communication/message.hpp
  • delete: include/communication/message/failure.hpp
  • delete: include/communication/message/request.hpp
  • delete: include/communication/message/succeed.hpp
  • delete: include/communication/post-office.hpp
  • delete: include/communication/shmem.hpp

差分

--- a/include/communication/mail.hpp
+++ /dev/null
@@ -1,136 +0,0 @@
1-
2-#ifndef GIKOMONA_CORE_COMMUNICATION_MAIL_HPP
3-#define GIKOMONA_CORE_COMMUNICATION_MAIL_HPP
4-
5-#include <queue>
6-#include <memory>
7-#include <mutex>
8-#include <algorithm>
9-
10-#include "message.hpp"
11-
12-namespace monazilla { namespace GikoMona { namespace core { namespace communication {
13-
14-typedef mona_string post_code;
15-
16-struct mail {
17- post_code from;
18- post_code to_app_name;
19- post_code to_class_id;
20-
21- message msg;
22-};
23-
24-typedef std::vector<mail> mail_container_;
25-
26-typedef std::shared_ptr<std::vector<mail>> mailbox;
27-
28-class mail_container {
29-public:
30- mail_container();
31- ~mail_container();
32-
33- typedef mail_container self_type;
34- typedef mail value_type;
35- typedef std::queue<mail> mail_queue;
36-
37- self_type& operator=(const self_type& other) {}
38- self_type& operator=(self_type&& other) {}
39-
40- struct posted_mail_list_viewer {
41- friend class mail_container;
42- posted_mail_list_viewer(const mail_queue& m) {}
43- public:
44- ~posted_mail_list_viewer();
45- iterator begin() { return mail_list.begin(); }
46- const_iterator cbegin() { return mail_list.cbegin(); }
47-
48- iterator end() { return mail_list.end() }
49- const_iterator cend() { return mail_list.cend(); }
50- };
51-
52- struct received_mail_list_viewer {
53- friend class mail_container {}
54- received_mail_list_viewer(const mail_queue& m);
55- public:
56- ~received_mail_list_viewer();
57- };
58-
59- posted_mail_list_viewer posted_mail_list() {
60- std::lock_guard<std::mutex> do_lock(pmq_mutex);
61- return posted_mail_list_viewer(posted_mail_queue);
62- }
63-
64- received_mail_list_viewer received_mail_list() {
65- std::lock_guard<std::mutex> do_lock(rmq_mutex);
66- return received_mail_list_viewer(received_mail_queue);
67- }
68-
69- void post(const mail& m) {
70- std::lock_guard<std::mutex> do_lock(pmq_mutex);
71- posted_mail_queue.push(m);
72- }
73-
74- mail recieve() {
75- std::lock_guard<std::mutex> do_lock(rmq_mutex);
76-
77- if(!received_mail_queue.empty()) {
78- mail m = received_mail_queue.front();
79- receieved_mail_queue.pop();
80- }
81-
82- return std::move(m);
83- }
84-
85- template <template <class...> class Container>
86- Container<mail> collect() {
87- std::lock_guard<std::mutex> do_lock(pmq_mutex);
88-
89- Container<mail> cont(posted_mail_queue.size());
90- while(!posted_mail_queue.empty()) {
91- cont.push_back(posted_mail_queue.front());
92- posted_mail_queue.pop();
93- }
94-
95- return std::move(cont);
96- }
97-
98- void deliver();
99-private:
100- std::mutex pmq_mutex;
101- std::mutex rmq_mutex;
102- mail_queue posted_mail_queue;
103- mail_queue received_mail_queue;
104-};
105-
106-bool operator==(const mail_container& lhs, const mail_container& rhs) {
107- if(lhs.size() == rhs.size()) {}
108-
109- return false;
110-}
111-
112-bool operator!=(const mail_container& lhs, const mail_container& rhs) {
113- return !(lhs == rhs);
114-}
115-bool operator<(const mail_container& lhs, const mail_container& rhs) {
116- return (lhs.size() < rhs.size());
117-}
118-
119-bool operator>(const mail_container& lhs, const mail_container& rhs) {
120- return (lhs.size() < rhs.size());
121-}
122-
123-bool operator<=(const mail_container& lhs, const mail_container& rhs) {
124- return (lhs == rhs ? true : lhs < rhs);
125-}
126-bool operator>=(const mail_container& lhs, const mail_container& rhs) {
127- return (lhs == rhs ? true : lhs < rhs);
128-}
129-
130-mailbox create_mailbox();
131-void destroy_mailbox(mailbox&& mb);
132-
133-
134-} } } }
135-
136-#endif // GIKOMONA_CORE_COMMUNICATION_MAIL_HPP
--- a/include/communication/message.hpp
+++ /dev/null
@@ -1,59 +0,0 @@
1-
2-#ifndef GIKOMONA_CORE_COMMUNICATION_MESSAGE_HPP
3-#define GIKOMONA_CORE_COMMUNICATION_MESSAGE_HPP
4-
5-#include <sstream>
6-
7-#include <boost/type_erasure/any.hpp>
8-#include <boost/type_erasure/constructible.hpp>
9-#include <boost/type_erasure/member.hpp>
10-#include <boost/mpl/vector.hpp>
11-
12-#include "string.hpp"
13-
14-namespace monazilla { namespace GikoMona { namespace core { namespace communication {
15-
16-BOOST_TYPE_ERASURE_MEMBER(has_to_raw, to_raw, 0)
17-BOOST_TYPE_ERASURE_MEMBER(has_msg_type, get_type, 0)
18-
19-typedef mona_string raw_message;
20-
21-enum class message_type {
22- FAILURE,
23- REQUEST,
24- SUCCEED
25-};
26-
27-typedef
28- boost::mpl::vector<
29- has_to_raw<raw_message()>,
30- has_msg_type<message_type()>
31- > message_requirements
32- ;
33-
34-typedef boost::type_erasure::any<message_requirements> message;
35-
36-#define DEFINE_MESSAGE(type_, name, message) \
37- class name { \
38- public: \
39- explicit \
40- name (const mona_string& str) : detail(str) {} \
41- ~name() = default; \
42- raw_message to_raw() const { \
43- std::ostringstream str_builder; \
44- str_builder << #type_ << ":" \
45- << message << "(" \
46- << detail << ")."; \
47- return static_cast<raw_message>( \
48- convert_from(str_builder.str()) \
49- ); \
50- } \
51- message_type get_type() { return type; } \
52- private: \
53- const mona_string detail; \
54- const message_type type = message_type::type_; \
55-};
56-
57-} } } }
58-
59-#endif // GIKOMONA_CORE_COMMUNICATION_MESSAGE_HPP
--- a/include/communication/message/failure.hpp
+++ /dev/null
@@ -1,17 +0,0 @@
1-
2-
3-#ifndef GIKOMONA_CORE_MESSAGE_FAILURE_HPP
4-#define GIKOMONA_CORE_MESSAGE_FAILURE_HPP
5-
6-#include "message.hpp"
7-
8-namespace monazilla { namespace GikoMona { namespace core { namespace failure {
9-
10-#define DEFINE_FAILURE(name, message) DEFINE_MESSAGE(FAILURE, name, message)
11-
12- DEFINE_FAILURE(download, "DOWNLOAD");
13- DEFINE_FAILURE(open, "OPEN");
14-
15-} } } }
16-
17-#endif // GIKOMONA_CORE_MESSAGE_FAILURE_HPP
--- a/include/communication/message/request.hpp
+++ /dev/null
@@ -1,18 +0,0 @@
1-
2-#ifndef GIKOMONA_CORE_MESSAGE_REQUEST_HPP
3-#define GIKOMONA_CORE_MESSAGE_REQUEST_HPP
4-
5-#include "message.hpp"
6-
7-namespace monazilla { namespace GikoMona { namespace core { namespace request {
8-
9-#define DEFINE_REQUEST(name, message) DEFINE_MESSAGE(REQUEST, name, message)
10-
11- DEFINE_REQUEST(kill_and_exec, "KILL&EXEC");
12- DEFINE_REQUEST(kill, "KILL");
13- DEFINE_REQUEST(exec, "EXEC");
14-
15-
16-} } } }
17-
18-#endif // GIKOMONA_CORE_MESSAGE_REQUEST_HPP
--- a/include/communication/message/succeed.hpp
+++ /dev/null
@@ -1,17 +0,0 @@
1-#ifndef GIKOMONA_CORE_MESSAGE_SUCCEED_HPP
2-#define GIKOMONA_CORE_MESSAGE_SUCCEED_HPP
3-
4-#include "message.hpp"
5-
6-namespace monazilla { namespace GikoMona { namespace core { namespace succeed {
7-
8-#define DEFINE_SUCCEED(name, message) DEFINE_MESSAGE(SUCCEED, name, message)
9-
10- DEFINE_SUCCEED(download, "DOWNLOAD");
11- DEFINE_SUCCEED(open, "OPEN");
12- DEFINE_SUCCEED(find_your_mailbox, "FIND");
13- DEFINE_SUCCEED(allow_you_to_send_mail, "ALLOW");
14-
15-} } } }
16-
17-#endif // GIKOMONA_CORE_MESSAGE_SUCCEED_HPP
--- a/include/communication/post-office.hpp
+++ /dev/null
@@ -1,83 +0,0 @@
1-
2-#ifndef GIKOMONA_CORE_COMMUNICATION_POST_OFFICE_HPP
3-#define GIKOMONA_CORE_COMMUNICATION_POST_OFFICE_HPP
4-
5-#include <unordered_map>
6-#include <algorithm>
7-
8-#include <boost/optional.hpp>
9-#include <boost/interprocess/managed_shared_memory.hpp>
10-#include <boost/interprocess/containers/vector.hpp>
11-#include <boost/interprocess/allocators/allocator.hpp>
12-
13-#include "shmem.hpp"
14-#include "message.hpp"
15-#include "mail.hpp"
16-#include "application-type.hpp"
17-
18-namespace monazilla { namespace GikoMona { namespace core { namespace communication {
19-
20-/** @brief
21- * @note このクラスは (1プロセス中の) シングルトンクラスである。
22- * @warning 1つのプロセス中で複数回constructされた場合アプリケーション自体がabortする。
23- */
24-class post_office {
25- typedef std::unordered_map<post_code, mailbox&> address_map;
26-
27-public:
28- explicit post_office(const post_code& self_);
29- ~post_office() noexcept;
30-
31- bool connect(const post_code& connect_to);
32- bool disconnect(const post_code& disconnect_from);
33- bool disconnect_all();
34-
35- template <class MessageType>
36- bool send(const post_code& to, MessageType&& msg);
37-
38- bool register_mailbox(mailbox& obj);
39- bool unregister_mailbox(const mailbox& obj);
40- bool is_registered(const mailbox& obj);
41-
42- void collect_mail_from_mailbox();
43- void forward_mail_to_another_postoffice();
44- void deliver_mail_to_mailbox();
45-
46- mona_string receive(const post_code& originator_id);
47-
48- void do_operation() {
49- collect_mail_from_mailbox();
50- forward_mail_to_another_postoffice();
51- deliver_mail_to_mailbox();
52-
53- std::for_each(mail_address.begin(),
54- mail_address.end(),
55- [] (const address_map::value_type& val) {
56- if(val.second) {
57-
58- }
59- });
60- }
61-
62- static post_office* get_instance() {
63- if(!instance) { /* error? */ }
64- return instance;
65- }
66-
67-private:
68- bool send_string(const post_code& to, mona_string&& src);
69-
70- shared_memory gm_shmem; // アプリケーション群全体で共有されているメモリ
71- const post_code self_code;
72- address_map mail_address;
73- mailbox tempolary_mailbox;
74-
75- const char *shared_memory_name = "org.monazilla.GikoMona.shared-memory";
76- const char *ref_counter_name = "org.monazilla.GikoMona.reference-counter";
77-
78- static post_office* instance = nullptr;
79-};
80-
81-} } } }
82-
83-#endif // GIKOMONA_CORE_COMMUNICATION_POST_OFFICE_HPP
--- a/include/communication/shmem.hpp
+++ /dev/null
@@ -1,45 +0,0 @@
1-
2-#ifndef GIKOMONA_CORE_COMMUNICATION_SHMEM_HPP
3-#define GIKOMONA_CORE_COMMUNICATION_SHMEM_HPP
4-
5-#include <unordered_map>
6-
7-#include <boost/optional.hpp>
8-#include <boost/interprocess/managed_shared_memory.hpp>
9-#include <boost/interprocess/containers/vector.hpp>
10-#include <boost/interprocess/allocators/allocator.hpp>
11-
12-#include "GikoMona.hpp"
13-#include "string.hpp"
14-
15-namespace monazilla { namespace GikoMona { namespace core { namespace communication {
16-
17-namespace ipc = boost::interprocess;
18-
19-typedef ipc::managed_shared_memory shared_memory;
20-typedef ipc::shared_memory_object shared_object;
21-typedef shared_memory::segment_manager segment_manager;
22-
23-template <typename T>
24-using shared_memory_allocator = ipc::allocator<T, segment_manager>;
25-
26-template <typename T>
27-using shared_list = ipc::list<T, shared_memory_allocator<T>>;
28-
29-template <typename T>
30-T *find(shared_memory& shmem, const std::string& name) {
31- return shmem.find<T>(name.c_str()).first;
32-}
33-
34-template <typename T>
35-T *construct(shared_memory& shmem, const std::string& name) {
36- return shmem.construct<T>(name.c_str())(shm.get_segment_manager());
37-}
38-
39-void destruct(shared_memory& shmem, const std::string& name) {
40- shared_object::remove(name.c_str());
41-}
42-
43-} } } }
44-
45-#endif // GIKOMONA_CORE_COMMUNICATION_SHMEM_HPP
旧リポジトリブラウザで表示