Author: lslezak Date: Mon Jul 14 12:48:39 2008 New Revision: 49030 URL: http://svn.opensuse.org/viewcvs/yast?rev=49030&view=rev Log: - use SCR DBus service if Y2DBUS=1 is set Modified: branches/tmp/lslezak/workshop/core/libscr/src/Makefile.am branches/tmp/lslezak/workshop/core/libscr/src/SCR.cc branches/tmp/lslezak/workshop/core/libscr/src/include/scr/SCR.h branches/tmp/lslezak/workshop/core/libscr/testsuite/Makefile.am Modified: branches/tmp/lslezak/workshop/core/libscr/src/Makefile.am URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/workshop/core/libs... ============================================================================== --- branches/tmp/lslezak/workshop/core/libscr/src/Makefile.am (original) +++ branches/tmp/lslezak/workshop/core/libscr/src/Makefile.am Mon Jul 14 12:48:39 2008 @@ -9,11 +9,15 @@ lib_LTLIBRARIES = libscr.la libscr_la_SOURCES = \ - SCRAgent.cc SCR.cc + SCRAgent.cc SCR.cc ../../scr/src/DBusConn.cc ../../scr/src/DBusMsg.cc + +libscr_la_CPPFLAGS = $(DBUS_CFLAGS) +libscr_la_LIBADD = $(DBUS_LIBS) INCLUDES = \ -I$(srcdir)/../../libycp/src/include \ -I$(srcdir)/../../liby2/src/include \ + -I$(srcdir)/../../scr/src \ -I$(srcdir)/include \ ${Y2UTIL_CFLAGS} Modified: branches/tmp/lslezak/workshop/core/libscr/src/SCR.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/workshop/core/libs... ============================================================================== --- branches/tmp/lslezak/workshop/core/libscr/src/SCR.cc (original) +++ branches/tmp/lslezak/workshop/core/libscr/src/SCR.cc Mon Jul 14 12:48:39 2008 @@ -29,12 +29,91 @@ #include "ycp/y2log.h" #include "scr/SCRAgent.h" +#include "DBusConn.h" +#include "DBusMsg.h" + extern StaticDeclaration static_declarations; bool SCR::registered = false; +// DBus related variables +DBusConn *connection; + +bool check_dbus_env() +{ + const char* y2dbus = ::getenv("Y2DBUS"); + + if (y2dbus != NULL) + { + if (::strcmp(y2dbus, "1") == 0) + return true; + } + + return false; +} + +static YCPValue CallDBus(const char *method, const YCPPath &path, const YCPValue &args = YCPNull (), + const YCPValue &opt = YCPNull ()) +{ + DBusMsg msg; + // TODO create constants for these strings + msg.createCall("org.opensuse.yast.SCR", "/SCR", "org.opensuse.yast.SCR.Methods", method); + + msg.addYCPValue(path); + + if (!args.isNull()) + { + msg.addYCPValue(args); + } + + if (!opt.isNull()) + { + msg.addYCPValue(opt); + } + + // send the message and get the response + DBusMsg reply(connection->call(msg)); + + y2internal("Reply type: %d", reply.type()); + + // return the first argument from the reply + YCPValue ret = reply.getYCPValue(0); + + if (!ret.isNull()) + { + y2internal("Received reply: %s", ret->toString().c_str()); + } + + // validate the reply (check for exceptions) + if (reply.type() != DBUS_MESSAGE_TYPE_METHOD_RETURN) + { + if (reply.type() == DBUS_MESSAGE_TYPE_ERROR) + { + if (!ret.isNull()) + { + y2internal("Received Error reply: %s", ret->toString().c_str()); + } + } + + return YCPVoid(); + } + + if (!ret.isNull()) + { + y2internal("Got reply: %s", ret->toString().c_str()); + } + + return ret; +} + static YCPValue SCRRead3 (const YCPPath &path, const YCPValue &args = YCPNull (), const YCPValue &opt = YCPNull ()) { + + if (connection != NULL) + { + return CallDBus("Read", path, args, opt); + } + if (! SCRAgent::instance()) { ycperror ( "No SCR instance found" ); @@ -68,6 +147,11 @@ static YCPValue SCRWrite3 (const YCPPath &path, const YCPValue& value, const YCPValue& arg) { + if (connection != NULL) + { + return CallDBus("Write", path, value, arg); + } + if (! SCRAgent::instance()) { ycperror ( "No SCR instance found" ); @@ -79,6 +163,11 @@ static YCPValue SCRDir (const YCPPath& path) { + if (connection != NULL) + { + return CallDBus("Dir", path); + } + if (! SCRAgent::instance()) { ycperror ( "No SCR instance found" ); @@ -90,6 +179,11 @@ static YCPValue SCRExecute (const YCPPath &path) { + if (connection != NULL) + { + return CallDBus("Execute", path); + } + if (! SCRAgent::instance()) { ycperror ( "No SCR instance found" ); @@ -114,6 +208,11 @@ static YCPValue SCRExecute2 (const YCPPath &path, const YCPValue &arg) { + if (connection != NULL) + { + return CallDBus("Execute", path, arg); + } + if (! SCRAgent::instance()) { ycperror ( "No SCR instance found" ); @@ -128,6 +227,11 @@ static YCPValue SCRExecute3 (const YCPPath &path, const YCPValue &arg, const YCPValue &opt) { + if (connection != NULL) + { + return CallDBus("Execute", path, arg, opt); + } + if (! SCRAgent::instance()) { ycperror ( "No SCR instance found" ); @@ -244,5 +348,32 @@ static_declarations.registerDeclarations ("SCR", declarations); registered = true; + + bool y2dbus = check_dbus_env(); + + // use std SCR or DBUS SCR? + if (y2dbus) + { + y2milestone("Y2DBUS is set, using DBUS for SCR access"); + connection = new DBusConn; + + // connect to the system bus + if (!connection->connect(DBUS_BUS_SYSTEM)) + { + y2error("Cannot connect to DBus, exiting..."); + exit(1); + } + } + else + { + y2milestone("Y2DBUS is not set, using embedded SCR"); + } } +SCR::~SCR() +{ + if (connection != NULL) + { + delete connection; + } +} Modified: branches/tmp/lslezak/workshop/core/libscr/src/include/scr/SCR.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/workshop/core/libs... ============================================================================== --- branches/tmp/lslezak/workshop/core/libscr/src/include/scr/SCR.h (original) +++ branches/tmp/lslezak/workshop/core/libscr/src/include/scr/SCR.h Mon Jul 14 12:48:39 2008 @@ -25,6 +25,7 @@ public: SCR (); + ~SCR(); static bool registered; }; Modified: branches/tmp/lslezak/workshop/core/libscr/testsuite/Makefile.am URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/workshop/core/libs... ============================================================================== --- branches/tmp/lslezak/workshop/core/libscr/testsuite/Makefile.am (original) +++ branches/tmp/lslezak/workshop/core/libscr/testsuite/Makefile.am Mon Jul 14 12:48:39 2008 @@ -8,11 +8,12 @@ -I$(top_srcdir)/libycp/src/include \ -I$(top_srcdir)/liby2/src/include \ -I$(srcdir)/../src/include \ + -I$(srcdir)/../src/include \ ${Y2UTIL_CFLAGS} noinst_PROGRAMS = runscr runscr_SOURCES = runscr.cc -runscr_LDADD = ../src/libscr.la ../../liby2/src/liby2.la ../../libycp/src/libycp.la ${Y2UTIL_LIBS} +runscr_LDADD = ../src/libscr.la ../../liby2/src/liby2.la ../../libycp/src/libycp.la ${Y2UTIL_LIBS} $(DBUS_LIBS) PACKAGE = libscr AUTOMAKE_OPTIONS = dejagnu -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org