Author: lslezak
Date: Thu Aug 28 11:37:46 2008
New Revision: 50429
URL: http://svn.opensuse.org/viewcvs/yast?rev=50429&view=rev
Log:
- use DBusCaller class in the servers
Added:
branches/tmp/lslezak/core/liby2dbus/src/DBusCaller.cc
branches/tmp/lslezak/core/liby2dbus/src/DBusCaller.h
Modified:
branches/tmp/lslezak/core/dbus/SCR_service/DBusServer.cc
branches/tmp/lslezak/core/dbus/SCR_service/DBusServer.h
branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc
branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h
branches/tmp/lslezak/core/liby2dbus/src/Makefile.am
Modified: branches/tmp/lslezak/core/dbus/SCR_service/DBusServer.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/dbus/SCR_service/DBusServer.cc?rev=50429&r1=50428&r2=50429&view=diff
==============================================================================
--- branches/tmp/lslezak/core/dbus/SCR_service/DBusServer.cc (original)
+++ branches/tmp/lslezak/core/dbus/SCR_service/DBusServer.cc Thu Aug 28 11:37:46 2008
@@ -88,16 +88,16 @@
for(Clients::iterator it = clients.begin();
it != clients.end();)
{
- pid_t pid = it->second;
+ DBusCaller caller = it->second;
- if (!isProcessRunning(pid))
+ if (!caller.isRunning())
{
Clients::iterator remove_it(it);
// move the current iterator
it++;
- y2milestone("Removing client %s (pid %d) from list", (remove_it->first).c_str(), pid);
+ y2milestone("Removing client %s (pid %d) from list", (remove_it->first).c_str(), caller.getPid());
clients.erase(remove_it);
}
@@ -106,7 +106,7 @@
// the process is still running
// no need to check the other clients
// we have to still run for at least this client
- y2debug("Client %s PID %d is still running", (it->first).c_str(), pid);
+ y2debug("Client %s PID %d is still running", (it->first).c_str(), caller.getPid());
break;
}
}
@@ -244,9 +244,10 @@
// remember the client
if (clients.find(caller) == clients.end())
{
+ DBusCaller c(caller, connection);
// insert the dbus name and PID
- Clients::value_type new_client(caller, callerPid(caller));
- y2milestone("Added new client %s (pid %d)", caller.c_str(), new_client.second);
+ Clients::value_type new_client(caller, c);
+ y2milestone("Added new client %s (pid %d)", caller.c_str(), c.getPid());
clients.insert(new_client);
}
@@ -444,50 +445,3 @@
}
#endif
-
-bool DBusServer::isProcessRunning(pid_t pid)
-{
- ostringstream sstr;
- sstr << "/proc/" << pid;
-
- struct stat stat_result;
- bool ret = ::stat(sstr.str().c_str(), &stat_result) == 0;
-
- y2milestone("Process /proc/%d is running: %s", pid, ret ? "true" : "false");
- return ret;
-}
-
-pid_t DBusServer::callerPid(const std::string &bus_name)
-{
- pid_t pid;
- DBusMsg query;
-
- // ask the DBus server for the PID of the caller
- query.createCall("org.freedesktop.DBus", "/org/freedesktop/DBus/Bus",
- "org.freedesktop.DBus", "GetConnectionUnixProcessID");
-
- query.addString(bus_name);
-
- // send the request
- DBusMsg reply(connection.call(query));
-
- // read the answer
- DBusMessageIter iter;
- dbus_message_iter_init(reply.getMessage(), &iter);
-
- int type = dbus_message_iter_get_arg_type(&iter);
- y2debug("Message type: %d, %c", type, (char)type);
-
- if (type == DBUS_TYPE_UINT32)
- {
- dbus_message_iter_get_basic(&iter, &pid);
- }
- else
- {
- y2internal("Unexpected type in PID reply %d (%c)", type, (char)type);
- }
-
- y2milestone("Message from PID %d", pid);
-
- return pid;
-}
Modified: branches/tmp/lslezak/core/dbus/SCR_service/DBusServer.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/dbus/SCR_service/DBusServer.h?rev=50429&r1=50428&r2=50429&view=diff
==============================================================================
--- branches/tmp/lslezak/core/dbus/SCR_service/DBusServer.h (original)
+++ branches/tmp/lslezak/core/dbus/SCR_service/DBusServer.h Thu Aug 28 11:37:46 2008
@@ -11,6 +11,7 @@
#include
#include "DBusConn.h"
+#include "DBusCaller.h"
#include "ScriptingAgent.h"
#ifdef HAVE_POLKIT
@@ -56,11 +57,9 @@
void resetTimer();
void registerSignalHandler();
- bool isProcessRunning(pid_t pid);
bool canFinish();
- pid_t callerPid(const std::string &bus_name);
- typedef std::map Clients;
+ typedef std::map Clients;
Clients clients;
};
Modified: branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc?rev=50429&r1=50428&r2=50429&view=diff
==============================================================================
--- branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc (original)
+++ branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc Thu Aug 28 11:37:46 2008
@@ -137,16 +137,16 @@
for(Clients::iterator it = clients.begin();
it != clients.end();)
{
- pid_t pid = it->second;
+ DBusCaller caller = it->second;
- if (!isProcessRunning(pid))
+ if (!caller.isRunning())
{
Clients::iterator remove_it(it);
// move the current iterator
it++;
- y2milestone("Removing client %s (pid %d) from list", (remove_it->first).c_str(), pid);
+ y2milestone("Removing client %s (pid %d) from list", (remove_it->first).c_str(), caller.getPid());
clients.erase(remove_it);
}
@@ -155,7 +155,7 @@
// the process is still running
// no need to check the other clients
// we have to still run for at least this client
- y2debug("Client %s PID %d is still running", (it->first).c_str(), pid);
+ y2debug("Client %s PID %d is still running", (it->first).c_str(), caller.getPid());
break;
}
}
@@ -262,9 +262,10 @@
// remember the client
if (clients.find(caller) == clients.end())
{
+ DBusCaller c(caller, connection);
// insert the dbus name and PID
- Clients::value_type new_client(caller, callerPid(caller));
- y2milestone("Added new client %s (pid %d)", caller.c_str(), new_client.second);
+ Clients::value_type new_client(caller, c);
+ y2milestone("Added new client %s (pid %d)", caller.c_str(), c.getPid());
clients.insert(new_client);
}
@@ -578,49 +579,3 @@
}
-bool DBusModulesServer::isProcessRunning(pid_t pid)
-{
- ostringstream sstr;
- sstr << "/proc/" << pid;
-
- struct stat stat_result;
- bool ret = ::stat(sstr.str().c_str(), &stat_result) == 0;
-
- y2milestone("Process /proc/%d is running: %s", pid, ret ? "true" : "false");
- return ret;
-}
-
-pid_t DBusModulesServer::callerPid(const std::string &bus_name)
-{
- pid_t pid;
- DBusMsg query;
-
- // ask the DBus server for the PID of the caller
- query.createCall("org.freedesktop.DBus", "/org/freedesktop/DBus/Bus",
- "org.freedesktop.DBus", "GetConnectionUnixProcessID");
-
- query.addString(bus_name);
-
- // send the request
- DBusMsg reply(connection.call(query));
-
- // read the answer
- DBusMessageIter iter;
- dbus_message_iter_init(reply.getMessage(), &iter);
-
- int type = dbus_message_iter_get_arg_type(&iter);
- y2debug("Message type: %d, %c", type, (char)type);
-
- if (type == DBUS_TYPE_UINT32)
- {
- dbus_message_iter_get_basic(&iter, &pid);
- }
- else
- {
- y2internal("Unexpected type in PID reply %d (%c)", type, (char)type);
- }
-
- y2milestone("Message from PID %d", pid);
-
- return pid;
-}
Modified: branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h?rev=50429&r1=50428&r2=50429&view=diff
==============================================================================
--- branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h (original)
+++ branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h Thu Aug 28 11:37:46 2008
@@ -11,6 +11,7 @@
#include
#include "DBusConn.h"
+#include "DBusCaller.h"
#ifdef HAVE_POLKIT
#include "PolKit.h"
@@ -66,11 +67,9 @@
void resetTimer();
void registerSignalHandler();
- bool isProcessRunning(pid_t pid);
bool canFinish();
- pid_t callerPid(const std::string &bus_name);
- typedef std::map Clients;
+ typedef std::map Clients;
Clients clients;
};
Added: branches/tmp/lslezak/core/liby2dbus/src/DBusCaller.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/liby2dbus/src/DBusCaller.cc?rev=50429&view=auto
==============================================================================
--- branches/tmp/lslezak/core/liby2dbus/src/DBusCaller.cc (added)
+++ branches/tmp/lslezak/core/liby2dbus/src/DBusCaller.cc Thu Aug 28 11:37:46 2008
@@ -0,0 +1,78 @@
+
+/*
+ DBusCaller.cc
+*/
+
+#include "DBusCaller.h"
+#include "DBusConn.h"
+#include "DBusMsg.h"
+
+#include
+
+#include
+
+extern "C"
+{
+// stat()
+#include
+}
+
+// ostringstream
+#include <sstream>
+
+DBusCaller::DBusCaller(const std::string &busid, DBusConn &connection) : pid(0)
+{
+ DBusMsg query;
+
+ // ask the DBus server for the PID of the caller
+ query.createCall("org.freedesktop.DBus", "/org/freedesktop/DBus/Bus",
+ "org.freedesktop.DBus", "GetConnectionUnixProcessID");
+
+ query.addString(busid);
+
+ // send the request
+ DBusMsg reply(connection.call(query));
+
+ // read the answer
+ DBusMessageIter iter;
+ dbus_message_iter_init(reply.getMessage(), &iter);
+
+ int type = dbus_message_iter_get_arg_type(&iter);
+ y2debug("Message type: %d, %c", type, (char)type);
+
+ if (type == DBUS_TYPE_UINT32)
+ {
+ dbus_message_iter_get_basic(&iter, &pid);
+ }
+ else
+ {
+ y2internal("Unexpected type in PID reply %d (%c)", type, (char)type);
+ }
+
+ y2milestone("Created DBusCaller with PID %d", pid);
+}
+
+DBusCaller::~DBusCaller()
+{
+}
+
+bool DBusCaller::isRunning()
+{
+ if (!pid)
+ return false;
+
+ ostringstream sstr;
+ sstr << "/proc/" << pid;
+
+ struct stat stat_result;
+ bool ret = ::stat(sstr.str().c_str(), &stat_result) == 0;
+
+ y2milestone("Process /proc/%d is running: %s", pid, ret ? "true" : "false");
+ return ret;
+}
+
+pid_t DBusCaller::getPid()
+{
+ return pid;
+}
+
Added: branches/tmp/lslezak/core/liby2dbus/src/DBusCaller.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/liby2dbus/src/DBusCaller.h?rev=50429&view=auto
==============================================================================
--- branches/tmp/lslezak/core/liby2dbus/src/DBusCaller.h (added)
+++ branches/tmp/lslezak/core/liby2dbus/src/DBusCaller.h Thu Aug 28 11:37:46 2008
@@ -0,0 +1,36 @@
+
+/*
+ DBusCaller
+*/
+
+#ifndef DBUSCALLER_H
+#define DBUSCALLER_H
+
+#include <string>
+
+extern "C"
+{
+#include
+}
+
+class DBusConn;
+
+// represents a DBus client process
+class DBusCaller
+{
+
+ public:
+
+ DBusCaller(const std::string &busid, DBusConn &connection);
+ ~DBusCaller();
+
+ bool isRunning();
+ pid_t getPid();
+
+ private:
+
+ pid_t pid;
+};
+
+#endif
+
Modified: branches/tmp/lslezak/core/liby2dbus/src/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/liby2dbus/src/Makefile.am?rev=50429&r1=50428&r2=50429&view=diff
==============================================================================
--- branches/tmp/lslezak/core/liby2dbus/src/Makefile.am (original)
+++ branches/tmp/lslezak/core/liby2dbus/src/Makefile.am Thu Aug 28 11:37:46 2008
@@ -7,7 +7,7 @@
plugin_LTLIBRARIES = liby2dbus.la
-liby2dbus_la_SOURCES = DBusMsg.cc DBusMsg.h DBusConn.cc DBusConn.h
+liby2dbus_la_SOURCES = DBusMsg.cc DBusMsg.h DBusConn.cc DBusConn.h DBusCaller.cc DBusCaller.h
if HAVE_POLKIT
liby2dbus_la_SOURCES += PolKit.cc PolKit.h
endif
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org