libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
SerialDeviceManager.h
Go to the documentation of this file.
1 /* Copyright 2013-2019 Homegear GmbH
2  *
3  * libhomegear-base is free software: you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public License as
5  * published by the Free Software Foundation, either version 3 of the
6  * License, or (at your option) any later version.
7  *
8  * libhomegear-base is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with libhomegear-base. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  * In addition, as a special exception, the copyright holders give
18  * permission to link the code of portions of this program with the
19  * OpenSSL library under certain conditions as described in each
20  * individual source file, and distribute linked combinations
21  * including the two.
22  * You must obey the GNU Lesser General Public License in all respects
23  * for all of the code used other than OpenSSL. If you modify
24  * file(s) with this exception, you may extend this exception to your
25  * version of the file(s), but you are not obligated to do so. If you
26  * do not wish to do so, delete this exception statement from your
27  * version. If you delete this exception statement from all source
28  * files in the program, then also delete it here.
29 */
30 
31 #ifndef DEVICEMANAGER_H_
32 #define DEVICEMANAGER_H_
33 
34 #include "../Sockets/SerialReaderWriter.h"
35 
36 #include <memory>
37 #include <string>
38 #include <map>
39 #include <mutex>
40 
41 namespace BaseLib
42 {
43 
44 class SharedObjects;
45 
46 /*
47  * This class is used, when a device needs to be accessible from different modules.
48  */
50 {
51 public:
53  virtual ~SerialDeviceManager() {}
54  void init(BaseLib::SharedObjects* baseLib);
55 
56  virtual void add(const std::string& device, std::shared_ptr<SerialReaderWriter> readerWriter);
57  virtual std::shared_ptr<SerialReaderWriter> create(std::string device, int32_t baudrate, int32_t flags, bool createLockFile, int32_t readThreadPriority);
58  virtual std::shared_ptr<SerialReaderWriter> get(const std::string& device);
59  virtual void remove(const std::string& device);
60 private:
61  BaseLib::SharedObjects* _bl = nullptr;
62  std::mutex _devicesMutex;
63  std::map<std::string, std::shared_ptr<SerialReaderWriter>> _devices;
64 };
65 }
66 #endif
virtual void add(const std::string &device, std::shared_ptr< SerialReaderWriter > readerWriter)
Definition: SerialDeviceManager.cpp:46
This is the base library main class.
Definition: BaseLib.h:95
SerialDeviceManager()
Definition: SerialDeviceManager.cpp:37
Definition: BaseLib.cpp:34
void init(BaseLib::SharedObjects *baseLib)
Definition: SerialDeviceManager.cpp:41
virtual std::shared_ptr< SerialReaderWriter > create(std::string device, int32_t baudrate, int32_t flags, bool createLockFile, int32_t readThreadPriority)
Definition: SerialDeviceManager.cpp:66
virtual ~SerialDeviceManager()
Definition: SerialDeviceManager.h:53
Definition: SerialDeviceManager.h:49