1 #include "softwarecontaineragent_dbus_stub.h" 2 #include "softwarecontainererror.h" 4 Glib::ustring interfaceXml0 = R
"XML_DELIMITER( 5 <?xml version="1.0" encoding="UTF-8" ?> 6 <node name="/com/pelagicore/SoftwareContainer"> 7 <interface name="com.pelagicore.SoftwareContainerAgent"> 9 <arg direction="out" type="ai" name="containers" /> 12 <method name="Create"> 13 <arg direction="in" type="s" name="config" /> 14 <arg direction="out" type="i" name="containerID" /> 17 <method name="Execute"> 18 <arg direction="in" type="i" name="containerID" /> 19 <arg direction="in" type="s" name="commandLine" /> 20 <arg direction="in" type="s" name="workingDirectory" /> 21 <arg direction="in" type="s" name="outputFile" /> 22 <arg direction="in" type="a{ss}" name="env" /> 23 <arg direction="out" type="i" name="pid" /> 26 <method name="Suspend"> 27 <arg direction="in" type="i" name="containerID" /> 30 <method name="Resume"> 31 <arg direction="in" type="i" name="containerID" /> 34 <method name="Destroy"> 35 <arg direction="in" type="i" name="containerID" /> 38 <method name="BindMount"> 39 <arg direction="in" type="i" name="containerID" /> 40 <arg direction="in" type="s" name="pathInHost" /> 41 <arg direction="in" type="s" name="pathInContainer" /> 42 <arg direction="in" type="b" name="readOnly" /> 45 <method name="ListCapabilities"> 46 <arg direction="out" type="as" name="capabilities" /> 49 <method name="SetCapabilities"> 50 <arg direction="in" type="i" name="containerID" /> 51 <arg direction="in" type="as" name="capabilities" /> 54 <signal name="ProcessStateChanged"> 55 <arg direction="out" type="i" name="containerID"/> 56 <arg direction="out" type="u" name="processID"/> 57 <arg direction="out" type="b" name="isRunning"/> 58 <arg direction="out" type="u" name="exitCode"/> 65 com::pelagicore::SoftwareContainerAgent::SoftwareContainerAgent() : 68 m_objectPath("/com/pelagicore/SoftwareContainerAgent"),
69 m_interfaceName(
"com.pelagicore.SoftwareContainerAgent")
71 ProcessStateChanged_signal.connect(
72 sigc::mem_fun(
this, &SoftwareContainerAgent::ProcessStateChanged_emitter)
76 void com::pelagicore::SoftwareContainerAgent::connect(
77 Gio::DBus::BusType busType,
81 introspection_data = Gio::DBus::NodeInfo::create_for_xml(interfaceXml0);
82 }
catch(
const Glib::Error& ex) {
83 g_warning(
"Unable to create introspection data: %s \n", ex.what().c_str());
86 connectionId = Gio::DBus::own_name(
89 sigc::mem_fun(
this, &SoftwareContainerAgent::on_bus_acquired),
90 sigc::mem_fun(
this, &SoftwareContainerAgent::on_name_acquired),
91 sigc::mem_fun(
this, &SoftwareContainerAgent::on_name_lost)
95 void com::pelagicore::SoftwareContainerAgent::on_method_call(
const Glib::RefPtr<Gio::DBus::Connection>& ,
96 const Glib::ustring& ,
97 const Glib::ustring& ,
98 const Glib::ustring& ,
99 const Glib::ustring& method_name,
100 const Glib::VariantContainerBase& parameters,
101 const Glib::RefPtr<Gio::DBus::MethodInvocation>& invocation)
104 if (method_name.compare(
"List") == 0) {
109 if (method_name.compare(
"Create") == 0) {
110 Glib::Variant<Glib::ustring > base_config;
111 parameters.get_child(base_config, 0);
112 Glib::ustring p_config;
113 p_config = base_config.get();
116 Glib::ustring(p_config),
120 if (method_name.compare(
"Execute") == 0) {
121 Glib::Variant<gint32 > base_containerID;
122 parameters.get_child(base_containerID, 0);
123 gint32 p_containerID;
124 p_containerID = base_containerID.get();
126 Glib::Variant<Glib::ustring > base_commandLine;
127 parameters.get_child(base_commandLine, 1);
128 Glib::ustring p_commandLine;
129 p_commandLine = base_commandLine.get();
131 Glib::Variant<Glib::ustring > base_workingDirectory;
132 parameters.get_child(base_workingDirectory, 2);
133 Glib::ustring p_workingDirectory;
134 p_workingDirectory = base_workingDirectory.get();
136 Glib::Variant<Glib::ustring > base_outputFile;
137 parameters.get_child(base_outputFile, 3);
138 Glib::ustring p_outputFile;
139 p_outputFile = base_outputFile.get();
141 Glib::Variant<std::map<Glib::ustring, Glib::ustring> > base_env;
142 parameters.get_child(base_env, 4);
143 std::map<Glib::ustring, Glib::ustring> p_env;
144 p_env = base_env.get();
148 Glib::ustring(p_commandLine),
149 Glib::ustring(p_workingDirectory),
150 Glib::ustring(p_outputFile),
151 SoftwareContainerAgentCommon::glibStringMapToStdStringMap(p_env),
155 if (method_name.compare(
"Suspend") == 0) {
156 Glib::Variant<gint32 > base_containerID;
157 parameters.get_child(base_containerID, 0);
158 gint32 p_containerID;
159 p_containerID = base_containerID.get();
166 if (method_name.compare(
"Resume") == 0) {
167 Glib::Variant<gint32 > base_containerID;
168 parameters.get_child(base_containerID, 0);
169 gint32 p_containerID;
170 p_containerID = base_containerID.get();
177 if (method_name.compare(
"Destroy") == 0) {
178 Glib::Variant<gint32 > base_containerID;
179 parameters.get_child(base_containerID, 0);
180 gint32 p_containerID;
181 p_containerID = base_containerID.get();
188 if (method_name.compare(
"BindMount") == 0) {
189 Glib::Variant<gint32 > base_containerID;
190 parameters.get_child(base_containerID, 0);
191 gint32 p_containerID;
192 p_containerID = base_containerID.get();
194 Glib::Variant<Glib::ustring > base_pathInHost;
195 parameters.get_child(base_pathInHost, 1);
196 Glib::ustring p_pathInHost;
197 p_pathInHost = base_pathInHost.get();
199 Glib::Variant<Glib::ustring > base_pathInContainer;
200 parameters.get_child(base_pathInContainer, 2);
201 Glib::ustring p_pathInContainer;
202 p_pathInContainer = base_pathInContainer.get();
204 Glib::Variant<bool > base_readOnly;
205 parameters.get_child(base_readOnly, 3);
207 p_readOnly = base_readOnly.get();
211 Glib::ustring(p_pathInHost),
212 Glib::ustring(p_pathInContainer),
217 if (method_name.compare(
"ListCapabilities") == 0) {
222 if (method_name.compare(
"SetCapabilities") == 0) {
223 Glib::Variant<gint32 > base_containerID;
224 parameters.get_child(base_containerID, 0);
225 gint32 p_containerID;
226 p_containerID = base_containerID.get();
228 Glib::Variant<std::vector<Glib::ustring> > base_capabilities;
229 parameters.get_child(base_capabilities, 1);
230 std::vector<Glib::ustring> p_capabilities;
231 p_capabilities = base_capabilities.get();
235 SoftwareContainerAgentCommon::glibStringVecToStdStringVec(p_capabilities),
240 std::string errorMessage(err.what());
241 msg.returnError(errorMessage);
245 void com::pelagicore::SoftwareContainerAgent::on_interface_get_property(
247 const Glib::RefPtr<Gio::DBus::Connection>& ,
248 const Glib::ustring& ,
249 const Glib::ustring& ,
250 const Glib::ustring& ,
251 const Glib::ustring& )
255 bool com::pelagicore::SoftwareContainerAgent::on_interface_set_property(
256 const Glib::RefPtr<Gio::DBus::Connection>& ,
257 const Glib::ustring& ,
258 const Glib::ustring& ,
259 const Glib::ustring& ,
260 const Glib::ustring& ,
261 const Glib::VariantBase& )
266 void com::pelagicore::SoftwareContainerAgent::ProcessStateChanged_emitter(
272 std::vector<Glib::VariantBase> paramsList;
273 paramsList.push_back(Glib::Variant<gint32 >::create((containerID)));;
274 paramsList.push_back(Glib::Variant<guint32 >::create((processID)));;
275 paramsList.push_back(Glib::Variant<bool >::create((isRunning)));;
276 paramsList.push_back(Glib::Variant<guint32 >::create((exitCode)));;
278 m_connection->emit_signal(
279 "/com/pelagicore/SoftwareContainerAgent",
280 "com.pelagicore.SoftwareContainerAgent",
281 "ProcessStateChanged",
283 Glib::Variant<std::vector<Glib::VariantBase> >::create_tuple(paramsList));
286 void com::pelagicore::SoftwareContainerAgent::on_bus_acquired(
287 const Glib::RefPtr<Gio::DBus::Connection>& connection,
288 const Glib::ustring& )
290 Gio::DBus::InterfaceVTable *interface_vtable =
291 new Gio::DBus::InterfaceVTable(
292 sigc::mem_fun(
this, &SoftwareContainerAgent::on_method_call),
293 sigc::mem_fun(
this, &SoftwareContainerAgent::on_interface_get_property),
294 sigc::mem_fun(
this, &SoftwareContainerAgent::on_interface_set_property));
296 registeredId = connection->register_object(m_objectPath,
297 introspection_data->lookup_interface(
"com.pelagicore.SoftwareContainerAgent"),
299 m_connection = connection;
300 }
catch(
const Glib::Error& ex) {
301 object_not_registered.emit(
"Registration of object failed");
305 void com::pelagicore::SoftwareContainerAgent::on_name_acquired(
306 const Glib::RefPtr<Gio::DBus::Connection>& ,
307 const Glib::ustring &name)
309 name_acquired.emit(name);
312 void com::pelagicore::SoftwareContainerAgent::on_name_lost(
313 const Glib::RefPtr<Gio::DBus::Connection> &connection,
314 const Glib::ustring &name)
317 name_lost.emit(
"Unable to connect to the bus (is a bus running?)");
319 name_lost.emit(
"Unable to acquire the name " 320 + name +
" on the bus (is another agent running?)");
324 bool com::pelagicore::SoftwareContainerAgent::emitSignal(
const std::string& propName, Glib::VariantBase& value) {
325 std::map<Glib::ustring, Glib::VariantBase> changedProps;
326 std::vector<Glib::ustring> changedPropsNoValue;
328 changedProps[propName] = value;
330 Glib::Variant<std::map<Glib::ustring, Glib::VariantBase> > changedPropsVar = Glib::Variant<std::map <Glib::ustring, Glib::VariantBase> >::create (changedProps);
331 Glib::Variant<std::vector<Glib::ustring> > changedPropsNoValueVar = Glib::Variant<std::vector<Glib::ustring> >::create(changedPropsNoValue);
332 std::vector<Glib::VariantBase> ps;
333 ps.push_back(Glib::Variant<Glib::ustring>::create(m_interfaceName));
334 ps.push_back(changedPropsVar);
335 ps.push_back(changedPropsNoValueVar);
336 Glib::VariantContainerBase propertiesChangedVariant = Glib::Variant<std::vector<Glib::VariantBase> >::create_tuple(ps);
338 m_connection->emit_signal(
340 "org.freedesktop.DBus.Properties",
343 propertiesChangedVariant);