Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application connectivity server #25

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions include/cmdlib/CommandFacility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
{ \
return std::unique_ptr<dunedaq::cmdlib::CommandFacility>(new klass()); \
} \
}
}

namespace dunedaq::cmdlib {

Expand All @@ -51,7 +51,7 @@ class CommandFacility
public:
explicit CommandFacility(std::string /*uri*/) {}
virtual ~CommandFacility();
CommandFacility(const CommandFacility&) =
CommandFacility(const CommandFacility&) =
delete; ///< CommandFacility is not copy-constructible
CommandFacility& operator=(const CommandFacility&) =
delete; ///< CommandFacility is not copy-assignable
Expand All @@ -71,7 +71,10 @@ class CommandFacility

protected:
//! Must be implemented to handling the results of the commands
virtual void completion_callback(const cmdobj_t& cmd, cmd::CommandReply& meta) = 0;
virtual void completion_callback(const cmdobj_t& cmd, cmd::CommandReply& meta) = 0;

//! name of the commanded object
std::string m_name;

private:

Expand All @@ -83,8 +86,6 @@ class CommandFacility
//! Commanded Object to run execute with received commands as parameters
mutable CommandedObject* m_commanded_object = nullptr;

//! name of the commanded object
std::string m_name;

//! Completion queue for reqistered tasks
typedef tbb::concurrent_queue<std::future<void>> CompletionQueue;
Expand All @@ -94,15 +95,18 @@ class CommandFacility
typedef std::function<void(const cmdobj_t&, cmd::CommandReply)> CommandCallback;
CommandCallback m_command_callback = nullptr;

//! Single thrad is responsible to trigger tasks
//! Single thrad is responsible to trigger tasks
std::atomic<bool> m_active;

std::thread m_executor;

};

std::shared_ptr<CommandFacility>
make_command_facility(std::string const& uri)
make_command_facility(
std::string const& uri,
int connectivity_service_interval_ms=2000,
bool use_connectivity_service=false)
{
auto sep = uri.find("://");
std::string scheme;
Expand All @@ -115,7 +119,16 @@ make_command_facility(std::string const& uri)
static cet::BasicPluginFactory bpf("duneCommandFacility", "make");
std::shared_ptr<CommandFacility> cf_ptr;
try {
cf_ptr = bpf.makePlugin<std::shared_ptr<CommandFacility>>(plugin_name, uri);
if (scheme == "rest")
cf_ptr = bpf.makePlugin<std::shared_ptr<CommandFacility>>(
plugin_name,
uri,
connectivity_service_interval_ms,
use_connectivity_service
);
else
cf_ptr = bpf.makePlugin<std::shared_ptr<CommandFacility>>(plugin_name, uri);

} catch (const cet::exception &cexpt) {
throw CommandFacilityCreationFailed(ERS_HERE, uri, cexpt);
} catch (const ers::Issue &iexpt) {
Expand Down
Loading