20 #include "softwarecontaineragentadaptor.h" 24 SoftwareContainerAgentAdaptor::~SoftwareContainerAgentAdaptor()
28 SoftwareContainerAgentAdaptor::SoftwareContainerAgentAdaptor(
29 Glib::RefPtr<Glib::MainLoop> &mainLoop,
32 com::pelagicore::SoftwareContainerAgent(),
36 std::string agentBusName =
"com.pelagicore.SoftwareContainerAgent";
37 Gio::DBus::BusType busType = useSessionBus ? Gio::DBus::BUS_TYPE_SESSION
38 : Gio::DBus::BUS_TYPE_SYSTEM;
40 name_lost.connect(sigc::mem_fun(
this, &SoftwareContainerAgentAdaptor::onDBusError));
41 name_acquired.connect(sigc::mem_fun(
this, &SoftwareContainerAgentAdaptor::onDBusNameAcquired));
42 object_not_registered.connect(
43 sigc::mem_fun(
this, &SoftwareContainerAgentAdaptor::onDBusError)
45 connect(busType, agentBusName);
48 void SoftwareContainerAgentAdaptor::onDBusError(std::string message)
50 log_error() <<
"Fatal D-Bus error: " << message;
54 void SoftwareContainerAgentAdaptor::onDBusNameAcquired(std::string name)
56 log_info() <<
"Name " << name <<
" aquired on D-Bus";
61 std::vector<int> list = m_agent.listContainers();
62 msg.returnValue(list);
67 std::vector<std::string> stdStrVec = m_agent.listCapabilities();
68 std::vector<Glib::ustring> glibStrVec = SoftwareContainerAgentCommon::stdStringVecToGlibStringVec(stdStrVec);
69 msg.returnValue(glibStrVec);
72 void SoftwareContainerAgentAdaptor::Execute(
73 const gint32 containerID,
74 const std::string commandLine,
75 const std::string workingDirectory,
76 const std::string outputFile,
77 const std::map<std::string, std::string> env,
80 pid_t pid = m_agent.execute(
86 [
this, containerID](pid_t pid,
int exitCode) {
87 ProcessStateChanged_emitter(containerID, pid,
false, exitCode);
88 log_info() <<
"ProcessStateChanged " << pid <<
" code " << exitCode;
96 m_agent.suspendContainer(containerID);
102 m_agent.resumeContainer(containerID);
108 m_agent.shutdownContainer(containerID);
112 void SoftwareContainerAgentAdaptor::BindMount(
113 const gint32 containerID,
114 const std::string pathInHost,
115 const std::string PathInContainer,
119 m_agent.bindMount(containerID, pathInHost, PathInContainer, readOnly);
123 void SoftwareContainerAgentAdaptor::SetCapabilities(
124 const gint32 containerID,
125 const std::vector<std::string> capabilities,
128 m_agent.setCapabilities(containerID, capabilities);
132 void SoftwareContainerAgentAdaptor::Create(
const std::string config,
135 gint32 containerID = m_agent.createContainer(config);
136 msg.returnValue(containerID);
Developers guide to adding a config item: