#include <statemachine_factory.h>
Definition at line 14 of file statemachine_factory.h.
◆ addProtocolResourceDir()
| void fipa::acl::StateMachineFactory::addProtocolResourceDir |
( |
const std::string & |
resourceDir | ) |
|
|
static |
Add the resource dir where to search for the protocol definitions
- Exceptions
-
| std::runtime_error | if resource directory does not exist |
Definition at line 24 of file statemachine_factory.cpp.
26 fs::path protocolDir = fs::path(resourceDir);
27 if(fs::is_directory(protocolDir))
29 std::vector<std::string>::iterator resourcesIt = std::find(msResourceDirs.begin(), msResourceDirs.end(), protocolDir.string());
30 if(resourcesIt == msResourceDirs.end())
32 msResourceDirs.push_back(protocolDir.string());
33 msPreparedResourceDir =
false;
34 LOG_INFO(
"Add protocol resource dir: '%s'", protocolDir.string().c_str());
36 LOG_WARN(
"Protocol resource dir '%s' already added", protocolDir.string().c_str());
39 std::string msg =
"Could not add resource dir: '" + resourceDir +
"', since it does not exist";
40 throw std::runtime_error(msg);
◆ getStateMachine()
| StateMachine fipa::acl::StateMachineFactory::getStateMachine |
( |
const std::string & |
protocol | ) |
|
|
static |
Create a statemachine for a given protocol
- Exceptions
-
| runtime_error | if statem machine |
Definition at line 93 of file statemachine_factory.cpp.
95 if(!msPreparedResourceDir)
97 StateMachineFactory::prepareProtocolsFromResourceDirs();
100 std::map<std::string, StateMachine>::iterator it = msStateMachines.find(protocol);
102 if(it != msStateMachines.end())
107 LOG_WARN(
"StateMachine for protocol '%s' not found", protocol.c_str());
108 throw std::runtime_error(
"State machine for requested protocol does not exist");
◆ prepareProtocolsFromResourceDir()
| void fipa::acl::StateMachineFactory::prepareProtocolsFromResourceDir |
( |
const std::string & |
directory | ) |
|
|
static |
Instanciates all available machines a resource directory
Definition at line 53 of file statemachine_factory.cpp.
55 fs::path protocolDir = fs::path(resourceDir);
56 LOG_INFO(
"Prepare protocols from: '%s'", protocolDir.string().c_str());
57 if(fs::is_directory(protocolDir))
59 std::vector<fs::path> files;
60 std::copy(fs::directory_iterator(protocolDir), fs::directory_iterator(), std::back_inserter(files));
62 std::vector<fs::path>::iterator it = files.begin();
63 for(;it != files.end(); ++it)
65 if(fs::is_regular_file(*it))
68 std::string protocolName = it->string();
69 size_t pos = protocolName.find_last_of(
"/");
70 protocolName.erase(0, pos+1);
75 LOG_INFO(
"Register protocol %s", protocolName.c_str());
76 std::map<std::string, StateMachine>::const_iterator statemachinesIt = msStateMachines.find(protocolName);
77 if( statemachinesIt != msStateMachines.end())
79 LOG_WARN(
"Protocol '%s' already registered - will use statemachine specification from '%s'", protocolName.c_str(), it->string().c_str());
81 msStateMachines[protocolName] = statemachine;
82 }
catch(
const std::runtime_error& e)
84 LOG_ERROR(
"Error loading specification for: '%s' - %s", protocolName.c_str(), e.what());
90 msPreparedResourceDir =
true;
StateMachine loadSpecification(const std::string &file)
◆ setProtocolResourceDir()
| void fipa::acl::StateMachineFactory::setProtocolResourceDir |
( |
const std::string & |
resourceDir | ) |
|
|
static |
Set the resource dir where to search for the protocol definitions (implies a clearing of all previous entries)
- Exceptions
-
| std::runtime_error | if resource directory does not exist |
Definition at line 18 of file statemachine_factory.cpp.
20 msResourceDirs.clear();
static void addProtocolResourceDir(const std::string &resourceDir)
The documentation for this class was generated from the following files: