FREEDM DGI
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
CAdapterFactory.hpp
Go to the documentation of this file.
1 
24 #ifndef C_ADAPTER_FACTORY_HPP
25 #define C_ADAPTER_FACTORY_HPP
26 
27 #include "IAdapter.hpp"
28 #include "CTcpServer.hpp"
29 #include "CDeviceBuilder.hpp"
30 
31 #include <map>
32 #include <set>
33 #include <string>
34 #include <iostream>
35 #include <stdexcept>
36 
37 #include <boost/thread.hpp>
38 #include <boost/noncopyable.hpp>
39 #include <boost/asio/ip/tcp.hpp>
40 #include <boost/asio/io_service.hpp>
41 #include <boost/asio/deadline_timer.hpp>
42 #include <boost/property_tree/ptree_fwd.hpp>
43 
44 namespace freedm {
45 namespace broker {
46 namespace device {
47 
55  : private boost::noncopyable
56 {
57 public:
59  static CAdapterFactory & Instance();
60 
62  void StartSessionProtocol(unsigned short port);
63 
65  void CreateAdapter(const boost::property_tree::ptree & p);
66 
68  void RemoveAdapter(const std::string identifier);
69 
71  void Stop();
72 private:
75 
77  void RunService();
78 
80  void CreateDevice(const std::string name, const std::string type,
81  IAdapter::Pointer adapter);
82 
85  const boost::property_tree::ptree & p);
86 
88  void SessionProtocol();
89 
91  void StartSession();
92 
94  void HandleRead(const boost::system::error_code & e);
95 
97  void Timeout(const boost::system::error_code & e);
98 
100  std::map<std::string, IAdapter::Pointer> m_adapters;
101 
103  boost::asio::io_service m_ios;
104 
107 
109  boost::thread m_thread;
110 
112  boost::asio::streambuf m_buffer;
113 
115  boost::asio::deadline_timer m_timeout;
116 
119 };
120 
121 } // namespace device
122 } // namespace freedm
123 } // namespace broker
124 
125 #endif // C_ADAPTER_FACTORY_HPP
CAdapterFactory()
Constructs the factory.
Definition: CAdapterFactory.cpp:84
Handles construction of all device objects used by the DGI.
Definition: CDeviceBuilder.hpp:47
boost::thread m_thread
Thread for the adapter i/o service.
Definition: CAdapterFactory.hpp:109
void InitializeAdapter(IAdapter::Pointer adapter, const boost::property_tree::ptree &p)
Initializes the devices stored on an adapter.
Definition: CAdapterFactory.cpp:364
CDeviceBuilder m_builder
Constructs the structure of devices.
Definition: CAdapterFactory.hpp:118
void StartSession()
Handles one plug and play device session.
Definition: CAdapterFactory.cpp:622
void SessionProtocol()
Session layer protocol for plug-and-play devices.
Definition: CAdapterFactory.cpp:721
void Timeout(const boost::system::error_code &e)
Disconnects plug and play devices that timeout.
Definition: CAdapterFactory.cpp:676
CTcpServer::Pointer m_server
TCP server to accept plug-and-play devices.
Definition: CAdapterFactory.hpp:106
static CAdapterFactory & Instance()
Gets the static instance of the factory.
Definition: CAdapterFactory.cpp:160
void Stop()
Stop everything!
Definition: CAdapterFactory.cpp:208
void CreateAdapter(const boost::property_tree::ptree &p)
Creates a new adapter and its associated devices.
Definition: CAdapterFactory.cpp:256
void CreateDevice(const std::string name, const std::string type, IAdapter::Pointer adapter)
Clones a device prototype and registers it with the system.
Definition: CAdapterFactory.cpp:562
void RunService()
Runs the adapter i/o service.
Definition: CAdapterFactory.cpp:175
Handles the creation of adapters and their associated devices.
Definition: CAdapterFactory.hpp:54
boost::shared_ptr< CTcpServer > Pointer
Convenience type for a shared pointer to self.
Definition: CTcpServer.hpp:46
void StartSessionProtocol(unsigned short port)
Starts the session TCP server.
Definition: CAdapterFactory.cpp:595
boost::asio::io_service m_ios
I/O service shared by the adapters.
Definition: CAdapterFactory.hpp:103
boost::shared_ptr< IAdapter > Pointer
Pointer to a physical adapter.
Definition: IAdapter.hpp:72
void HandleRead(const boost::system::error_code &e)
Handles plug and play devices that send a session packet.
Definition: CAdapterFactory.cpp:646
boost::asio::streambuf m_buffer
Packet received from plug and play device.
Definition: CAdapterFactory.hpp:112
void RemoveAdapter(const std::string identifier)
Removes an adapter and its associated devices.
Definition: CAdapterFactory.cpp:328
boost::asio::deadline_timer m_timeout
Timer for bad plug and play sessions.
Definition: CAdapterFactory.hpp:115
std::map< std::string, IAdapter::Pointer > m_adapters
Set of device adapters managed by the factory.
Definition: CAdapterFactory.hpp:100