Skip to content

Commit bf9a560

Browse files
committed
[occ] Push configuration via boost::ptree
1 parent 112ecc4 commit bf9a560

5 files changed

Lines changed: 33 additions & 11 deletions

File tree

occ/occlib/OccServer.cxx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <boost/uuid/uuid_generators.hpp>
3131
#include <boost/uuid/uuid_io.hpp>
3232
#include <boost/algorithm/string.hpp>
33+
#include <boost/property_tree/ptree.hpp>
3334

3435
#include "RuntimeControlledObject.h"
3536

@@ -188,9 +189,9 @@ grpc::Status OccServer::Transition(grpc::ServerContext* context,
188189
<< " currentState: " << currentStateStr
189190
<< " event: " << event << std::endl;
190191

191-
PropertyMap properties;
192+
boost::property_tree::ptree properties;
192193
for (auto item : arguments) {
193-
properties[item.key()] = item.value();
194+
properties.put(item.key(), item.value());
194195
}
195196

196197
t_State newState = processStateTransition(event, properties);
@@ -211,7 +212,7 @@ grpc::Status OccServer::Transition(grpc::ServerContext* context,
211212
return grpc::Status::OK;
212213
}
213214

214-
t_State OccServer::processStateTransition(const std::string& event, const PropertyMap& properties)
215+
t_State OccServer::processStateTransition(const std::string& event, const boost::property_tree::ptree& properties)
215216
{
216217
int err = 0;
217218
int invalidEvent = 0;

occ/occlib/OccServer.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@
3838

3939
namespace pb = occ_pb;
4040

41+
42+
namespace boost {
43+
namespace property_tree
44+
{
45+
template < class Key, class Data, class KeyCompare >
46+
class basic_ptree;
47+
48+
typedef basic_ptree< std::string, std::string, std::less<std::string> > ptree;
49+
}
50+
}
51+
4152
class RuntimeControlledObject;
4253

4354
const std::unordered_map<std::string, std::string> EXPECTED_FINAL_STATE = {
@@ -89,7 +100,7 @@ class OccServer final : public pb::Occ::Service
89100
bool checkMachineDone();
90101

91102
private:
92-
t_State processStateTransition(const std::string& evt, const PropertyMap& properties);
103+
t_State processStateTransition(const std::string& evt, const boost::property_tree::ptree& properties);
93104
void updateState(t_State s);
94105

95106
void publishState(t_State s);

occ/occlib/OccState.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ typedef enum {
4848
done /// Final state of the process, it is not possible to go back from here, only quit.
4949
} t_State;
5050

51-
typedef std::unordered_map<std::string, std::string> PropertyMap;
52-
53-
5451
t_State OCC_EXPORT getStateFromString(const std::string& s);
5552
const std::string OCC_EXPORT getStringFromState(t_State s);
5653

occ/occlib/RuntimeControlledObject.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#include "RuntimeControlledObject.h"
2727

28+
#include <boost/property_tree/ptree.hpp>
29+
2830
#include <thread>
2931

3032
using namespace std::chrono_literals;
@@ -81,7 +83,7 @@ const std::string RuntimeControlledObject::getName()
8183
return dPtr->mName;
8284
}
8385

84-
int RuntimeControlledObject::executeConfigure(const PropertyMap& properties)
86+
int RuntimeControlledObject::executeConfigure(const boost::property_tree::ptree& properties)
8587
{
8688
return 0;
8789
}

occ/occlib/RuntimeControlledObject.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@
2929
#include "OccState.h"
3030
#include "occ_export.h"
3131

32+
namespace boost {
33+
namespace property_tree
34+
{
35+
template < class Key, class Data, class KeyCompare >
36+
class basic_ptree;
37+
38+
typedef basic_ptree< std::string, std::string, std::less<std::string> > ptree;
39+
}
40+
}
41+
3242
class RuntimeControlledObjectPrivate;
3343

3444
class OCC_EXPORT RuntimeControlledObject {
@@ -79,7 +89,7 @@ class OCC_EXPORT RuntimeControlledObject {
7989
* transition all checks (iterateRunning/iterateCheck) are blocked until the transition
8090
* finishes and returns success or error.
8191
*/
82-
virtual int executeConfigure(const PropertyMap& properties);
92+
virtual int executeConfigure(const boost::property_tree::ptree& properties);
8393

8494
/**
8595
* Transition from configured to standby.
@@ -180,8 +190,9 @@ class OCC_EXPORT RuntimeControlledObject {
180190
* @return 0 if the check completed successfully and the machine can stay in the current state,
181191
* or any other value to immediately trigger a transition to the error state.
182192
*
183-
* This function is called continuously by OccServer::runChecker in any state. Its purpose is for
184-
* the implementer to report an unusual condition in order to trigger a transition to error.
193+
* This function is called continuously by OccServer::runChecker in any state, including
194+
* t_State::running. Its purpose is for the implementer to report an unusual condition in
195+
* order to trigger a transition to t_State::error.
185196
*/
186197
virtual int iterateCheck();
187198

0 commit comments

Comments
 (0)