controllerclientcpp  0.6.1
 全て クラス ネームスペース ファイル 関数 変数 型定義 列挙型 列挙型の値 マクロ定義 ページ
mujinzmq.h
説明を見る。
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2012-2015 MUJIN Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
17 #ifndef MUJIN_ZMQ_H
18 #define MUJIN_ZMQ_H
19 
20 #include <boost/shared_ptr.hpp>
21 
23 
24 namespace mujinzmq
25 {
26 
27 #include "mujincontrollerclient/config.h"
28 
31 class MUJINCLIENT_API ZmqSubscriber
32 {
33 public:
34  ZmqSubscriber(const std::string& host, const unsigned int port);
35  virtual ~ZmqSubscriber();
36 
37 protected:
38  void _InitializeSocket(boost::shared_ptr<zmq::context_t> context);
39  void _DestroySocket();
40 
41  boost::shared_ptr<zmq::context_t> _context;
42  boost::shared_ptr<zmq::socket_t> _socket;
43  std::string _host;
44  unsigned int _port;
46 };
47 
50 class MUJINCLIENT_API ZmqPublisher
51 {
52 public:
53  ZmqPublisher(const unsigned int port);
54  virtual ~ZmqPublisher();
55 
56  bool Publish(const std::string& messagestr);
57 
58 protected:
59  void _InitializeSocket(boost::shared_ptr<zmq::context_t> context);
60  void _DestroySocket();
61 
62  boost::shared_ptr<zmq::context_t> _context;
63  boost::shared_ptr<zmq::socket_t> _socket;
64  unsigned int _port;
66 };
67 
70 class MUJINCLIENT_API ZmqClient
71 {
72 public:
73  ZmqClient(const std::string& host, const unsigned int port);
74  virtual ~ZmqClient();
75 
76  std::string Call(const std::string& msg, const double timeout=5.0/*secs*/);
77 
78 protected:
79  void _InitializeSocket(boost::shared_ptr<zmq::context_t> context);
80  void _DestroySocket();
81 
82  unsigned int _port;
83  std::string _host;
84  boost::shared_ptr<zmq::context_t> _context;
85  boost::shared_ptr<zmq::socket_t> _socket;
87 };
88 
91 class MUJINCLIENT_API ZmqServer
92 {
93 public:
94  ZmqServer(const unsigned int port);
95  virtual ~ZmqServer();
96 
97  virtual unsigned int Recv(std::string& data, long timeout=0);
98  virtual void Send(const std::string& message);
99 
100 protected:
101  virtual void _InitializeSocket(boost::shared_ptr<zmq::context_t> context);
102  virtual void _DestroySocket();
103 
105  unsigned int _port;
106  boost::shared_ptr<zmq::context_t> _context;
107  boost::shared_ptr<zmq::socket_t> _socket;
110 
111 };
112 
113 } // namespace mujinzmq
114 #endif // MUJIN_ZMQ_H