Handles the creation of adapters and their associated devices.
More...
#include <CAdapterFactory.hpp>
Singleton factory that creates, stores, and runs new device adapters.
- Limitations:
- This class is not thread safe.
freedm::broker::device::CAdapterFactory::CAdapterFactory |
( |
| ) |
|
|
private |
Constructs an uninitialized factory.
- Precondition:
- None.
- Postcondition:
- Registers the known device classes.
- Postcondition:
- Initializes the session protocol TCP server.
- Limitations:
- None.
void freedm::broker::device::CAdapterFactory::CreateAdapter |
( |
const boost::property_tree::ptree & |
p | ) |
|
Creates a new adapter and all of its devices. The adapter is registered with each device, and each device is registered with the global device manager. The adapter is configured to recognize its own device signals, and started when the configuration is complete.
- Error Handling:
- Throws an EDgiConfigError if the property tree is bad, or EBadRequest if a PnP controller has assigned an unexpected signal to a device (which would be an EDgiConfigError otherwise)
- Precondition:
- The adapter must not begin work until IAdapter::Start.
- Precondition:
- The adapter's devices must not be specified in other adapters.
- Postcondition:
- Calls CAdapterFactory::InitializeAdapter to create devices.
- Postcondition:
- Starts the adapter through IAdapter::Start.
- Parameters
-
p | The property tree that specifies a single adapter. |
- Limitations:
- None.
void freedm::broker::device::CAdapterFactory::CreateDevice |
( |
const std::string |
name, |
|
|
const std::string |
type, |
|
|
IAdapter::Pointer |
adapter |
|
) |
| |
|
private |
Creates a new device and registers it with the device manager.
- Error Handling:
- Throws a std::runtime_error if the name is already in use, the type is not recognized, or the adapter is null.
- Precondition:
- Type must be registered with CAdapterFactory::RegisterDevicePrototype.
- Postcondition:
- Creates a new device using m_prototype[type].
- Postcondition:
- Adds the new device to the device manager.
- Parameters
-
name | The unique identifier for the device to be created. |
type | The string identifier for the type of device to create. |
adapter | The adapter that will handle the data of the new device. |
- Limitations:
- The device types must be registered prior to this call.
void freedm::broker::device::CAdapterFactory::HandleRead |
( |
const boost::system::error_code & |
e | ) |
|
|
private |
Starts the session protocol after a successful read from a device.
- Precondition:
- None.
- Postcondition:
- If a successful read, calls CAdapterFactory::SessionProtocol.
- Parameters
-
e | The error code associated with the last read operation. |
- Limitations:
- None.
void freedm::broker::device::CAdapterFactory::InitializeAdapter |
( |
IAdapter::Pointer |
adapter, |
|
|
const boost::property_tree::ptree & |
p |
|
) |
| |
|
private |
Initializes an adapter to contain a set of device signals.
- Error Handling:
- Throws EDgiConfigError if the property tree has a bad specification format. Could also throw EBadRequest if the adapter is a CPnpAdapter and the Hello message assigns an unexpected signal to a device.
- Precondition:
- The property tree must contain an adapter specification.
- Postcondition:
- Associates a set of device signals with the passed adapter.
- Parameters
-
adapter | The adapter to initialize. |
p | The property tree that contains the buffer data. |
- Limitations:
- None.
Retrieves the singleton factory instance.
- Precondition:
- None.
- Postcondition:
- Creates a new factory on the first call.
- Returns
- The global instance of CAdapterFactory.
- Limitations:
- None.
void freedm::broker::device::CAdapterFactory::RemoveAdapter |
( |
const std::string |
identifier | ) |
|
Removes an adapter and all of its associated devices.
- Error Handling:
- Throws a std::runtime_error if no such adapter exists.
- Precondition:
- An adapter must exist with the provided identifier.
- Postcondition:
- Removes the specified adapter from m_adapters.
- Postcondition:
- Removes the adapter's devices from the device manager.
- Parameters
-
identifier | The identifier of the adapter to remove. |
- Limitations:
- None.
void freedm::broker::device::CAdapterFactory::RunService |
( |
| ) |
|
|
private |
Runs the i/o service with an infinite workload.
- Precondition:
- None.
- Postcondition:
- Runs m_ios and blocks the calling thread.
- Limitations:
- None.
void freedm::broker::device::CAdapterFactory::SessionProtocol |
( |
| ) |
|
|
private |
Handles the hello message for the plug and play session protoocl.
- Precondition:
- m_buffer must contain the device hello packet.
- Postcondition:
- If the packet is well-formed, creates a new adapter and responds to the plug and play connection with a start packet.
- Postcondition:
- Otherwise, responds with a bad request that indicates the error.
- Limitations:
- None.
Reformat the packet as a property tree that can be used with CreateAdapter.
The config property tree now contains a valid adapter specification.
void freedm::broker::device::CAdapterFactory::StartSession |
( |
| ) |
|
|
private |
Prepares to read the hello message from a new plug and play device.
- Precondition:
- m_server must be connected to a remote endpoint.
- Postcondition:
- m_timeout is started to disconnect the device if it does not respond.
- Postcondition:
- Schedules a read into m_buffer from the current m_server connection.
- Limitations:
- This function must only be called by m_server.
void freedm::broker::device::CAdapterFactory::StartSessionProtocol |
( |
unsigned short |
port | ) |
|
Initializes the plug and play session protocol.
- Parameters
-
port | the port over which to run the session protocol |
- Error Handling:
- Throws a std::logic_error if the session protoocl has been initialized through a prior call to this function.
- Precondition:
- m_server must not be initialized by a prior call to this function.
- Postcondition:
- m_server is created to accept connections from plug and play devices.
- Limitations:
- This function must be called at most once.
void freedm::broker::device::CAdapterFactory::Stop |
( |
| ) |
|
Stops the i/o service and removes all devices from the device manager. This function must be called from outside the devices thread.
- Precondition:
- None
- Postcondition:
- All the devices of every adapter in the system are removed.
- Postcondition:
- The IOService has stopped.
- Postcondition:
- The devices thread is detatched and stopped (unless called from it).
- Error Handling:
- Guaranteed not to throw. Errors are only logged.
- Limitations:
- MUST be called from outside the devices thread.
void freedm::broker::device::CAdapterFactory::Timeout |
( |
const boost::system::error_code & |
e | ) |
|
|
private |
Closes a plug and play connection if it does not send a well-formed packet.
- Precondition:
- None.
- Postcondition:
- If timeout or error, closes the current m_server connection.
- Parameters
-
e | The error code associated with the timer. |
- Limitations:
- None.
std::map<std::string, IAdapter::Pointer> freedm::broker::device::CAdapterFactory::m_adapters |
|
private |
boost::asio::streambuf freedm::broker::device::CAdapterFactory::m_buffer |
|
private |
boost::asio::io_service freedm::broker::device::CAdapterFactory::m_ios |
|
private |
boost::thread freedm::broker::device::CAdapterFactory::m_thread |
|
private |
boost::asio::deadline_timer freedm::broker::device::CAdapterFactory::m_timeout |
|
private |
The documentation for this class was generated from the following files:
- /home/docs/checkouts/readthedocs.org/user_builds/freedm/checkouts/latest/Broker/src/device/CAdapterFactory.hpp
- /home/docs/checkouts/readthedocs.org/user_builds/freedm/checkouts/latest/Broker/src/device/CAdapterFactory.cpp