Skip to content

Commit

Permalink
[occ] Export PID to protobuf
Browse files Browse the repository at this point in the history
  • Loading branch information
miltalex authored and teo committed Jul 23, 2020
1 parent d7e053c commit e970ce6
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions occ/occlib/OccServer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
#include <boost/algorithm/string.hpp>
#include <boost/property_tree/ptree.hpp>

#include <sys/types.h>
#include <unistd.h>

#include "RuntimeControlledObject.h"
#include "RuntimeControlledObjectPrivate.h"

Expand Down Expand Up @@ -139,7 +142,10 @@ grpc::Status OccServer::GetState(grpc::ServerContext* context,
(void) request;

auto state = getStringFromState(m_rco->getState());
pid_t pid = getpid();

response->set_state(state);
response->set_pid(pid);

return grpc::Status::OK;
}
Expand Down
6 changes: 6 additions & 0 deletions occ/plugin/OccLiteServer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/split.hpp>

#include <sys/types.h>
#include <unistd.h>

#include <condition_variable>
#include <iomanip>

Expand Down Expand Up @@ -77,7 +80,10 @@ ::grpc::Status OccLite::Service::GetState(::grpc_impl::ServerContext* context,
(void) request;

auto state = fair::mq::PluginServices::ToStr(m_pluginServices->GetCurrentDeviceState());
pid_t pid = getpid();

response->state = state;
response->pid = pid;
OLOG(INFO) << "GetState response: " << response->state;

return grpc::Status::OK;
Expand Down
7 changes: 6 additions & 1 deletion occ/plugin/OccPluginServer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
#include <condition_variable>
#include <iomanip>

#include <sys/types.h>
#include <unistd.h>

OccPluginServer::OccPluginServer(fair::mq::PluginServices* pluginServices)
: Service(), m_pluginServices(pluginServices)
{
Expand Down Expand Up @@ -149,7 +152,10 @@ grpc::Status OccPluginServer::GetState(grpc::ServerContext* context,
(void) request;

auto state = fair::mq::PluginServices::ToStr(m_pluginServices->GetCurrentDeviceState());
pid_t pid = getpid();

response->set_state(state);
response->set_pid(pid);

return grpc::Status::OK;
}
Expand Down Expand Up @@ -230,4 +236,3 @@ OccPluginServer::Transition(grpc::ServerContext* context,

return grpc::Status::OK;
}

4 changes: 4 additions & 0 deletions occ/plugin/litestructs/GetState.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ bool OccLite::nopb::GetStateResponse::Serialize(rapidjson::Writer<rapidjson::Str
writer->String("state");
writer->String(state);

writer->String("pid");
writer->Int(pid);

writer->EndObject();
return true;
}

bool OccLite::nopb::GetStateResponse::Deserialize(const rapidjson::Value& obj)
{
state = obj["state"].GetString();
pid = obj["pid"].GetInt();
return true;
}

Expand Down
1 change: 1 addition & 0 deletions occ/plugin/litestructs/GetState.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct GetStateRequest : public JsonMessage
struct GetStateResponse : public JsonMessage
{
std::string state;
int pid;

bool Serialize(rapidjson::Writer<rapidjson::StringBuffer>* writer) const override;
bool Deserialize(const rapidjson::Value& obj) override;
Expand Down
1 change: 1 addition & 0 deletions occ/protos/occ.proto
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ message EventStreamReply {
message GetStateRequest {}
message GetStateReply {
string state = 1;
int32 pid = 2;
}

message ConfigEntry {
Expand Down

0 comments on commit e970ce6

Please sign in to comment.