IQRF Gateway Daemon
MqMessaging.h
Go to the documentation of this file.
1 /*
2  * Copyright 2016-2017 MICRORISC s.r.o.
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  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include "TaskQueue.h"
20 #include "IMessaging.h"
21 #include <string>
22 
23 class IDaemon;
24 class MqChannel;
25 
26 typedef std::basic_string<unsigned char> ustring;
27 
40 class MqMessaging : public IMessaging
41 {
42 public:
43  MqMessaging() = delete;
44  MqMessaging(const std::string& name);
45 
46  virtual ~MqMessaging();
47 
49  void start() override;
50  void stop() override;
51  void update(const rapidjson::Value& cfg) override;
52  const std::string& getName() const override { return m_name; }
53  void registerMessageHandler(MessageHandlerFunc hndl) override;
54  void unregisterMessageHandler() override;
55  void sendMessage(const ustring& msg) override;
56 
57 private:
58  int handleMessageFromMq(const ustring& mqMessage);
59 
60  MqChannel* m_mqChannel;
61  TaskQueue<ustring>* m_toMqMessageQueue;
62 
63  std::string m_name;
64  std::string m_localMqName;
65  std::string m_remoteMqName;
66 
67  IMessaging::MessageHandlerFunc m_messageHandlerFunc;
68 };
std::function< void(const ustring &)> MessageHandlerFunc
Incoming message handler functional type.
Definition: IMessaging.h:56
void update(const rapidjson::Value &cfg) override
Update configuration.
Definition: MqMessaging.cpp:67
IDaemon interface.
Definition: IDaemon.h:31
void unregisterMessageHandler() override
Unregister message handler.
Definition: MqMessaging.cpp:80
void start() override
IMessaging overriden methods.
Definition: MqMessaging.cpp:40
void registerMessageHandler(MessageHandlerFunc hndl) override
Register message handler.
Definition: MqMessaging.cpp:75
Interprocess messaging.
Definition: MqMessaging.h:40
IMessaging interface.
Definition: IMessaging.h:29
MqMessaging()=delete
const std::string & getName() const override
Get name of the instance.
Definition: MqMessaging.h:52
virtual ~MqMessaging()
Definition: MqMessaging.cpp:36
std::basic_string< unsigned char > ustring
Definition: ProtocolBridgeClientService.h:33
void sendMessage(const ustring &msg) override
send message
Definition: MqMessaging.cpp:85
std::basic_string< unsigned char > ustring
Definition: MqMessaging.h:24
void stop() override
Stop Messaging instance.
Definition: MqMessaging.cpp:58