Author: lslezak
Date: Fri Jul 11 09:38:51 2008
New Revision: 48980
URL: http://svn.opensuse.org/viewcvs/yast?rev=48980&view=rev
Log:
- added more types in DBus -> YCPValue conversion
- send error reply when an error occurrs
Modified:
branches/tmp/lslezak/workshop/core/scr/src/DBusConn.h
branches/tmp/lslezak/workshop/core/scr/src/DBusMsg.cc
branches/tmp/lslezak/workshop/core/scr/src/DBusMsg.h
branches/tmp/lslezak/workshop/core/scr/src/DBusServer.cc
branches/tmp/lslezak/workshop/core/scr/src/Makefile.am
Modified: branches/tmp/lslezak/workshop/core/scr/src/DBusConn.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/workshop/core/scr/src/DBusConn.h?rev=48980&r1=48979&r2=48980&view=diff
==============================================================================
--- branches/tmp/lslezak/workshop/core/scr/src/DBusConn.h (original)
+++ branches/tmp/lslezak/workshop/core/scr/src/DBusConn.h Fri Jul 11 09:38:51 2008
@@ -9,7 +9,7 @@
#include
#include <string>
-#include "DBusMsg.h";
+#include "DBusMsg.h"
class DBusConn
{
Modified: branches/tmp/lslezak/workshop/core/scr/src/DBusMsg.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/workshop/core/scr/src/DBusMsg.cc?rev=48980&r1=48979&r2=48980&view=diff
==============================================================================
--- branches/tmp/lslezak/workshop/core/scr/src/DBusMsg.cc (original)
+++ branches/tmp/lslezak/workshop/core/scr/src/DBusMsg.cc Fri Jul 11 09:38:51 2008
@@ -27,6 +27,12 @@
msg = dbus_message_new_method_return(m.getMessage());
}
+void DBusMsg::createError(const DBusMsg &m, const std::string &error_msg, const std::string &error_code)
+{
+ release();
+ msg = dbus_message_new_error(m.getMessage(), error_code.c_str(), error_msg.c_str());
+}
+
void DBusMsg::release()
{
if (msg != NULL)
@@ -355,6 +361,49 @@
// recurse into the variant iterator
return getYCPValue(&sub);
}
+ else if (type == DBUS_TYPE_DOUBLE)
+ {
+ double d;
+ dbus_message_iter_get_basic(it, &d);
+ ret = YCPFloat(d);
+ }
+ else if (type == DBUS_TYPE_INT64)
+ {
+ dbus_int64_t i;
+ dbus_message_iter_get_basic(it, &i);
+ ret = YCPInteger(i);
+ }
+ else if (type == DBUS_TYPE_UINT64)
+ {
+ // warning: YCPInteger is signed!
+ dbus_uint64_t i;
+ dbus_message_iter_get_basic(it, &i);
+ ret = YCPInteger(i);
+ }
+ else if (type == DBUS_TYPE_INT32)
+ {
+ dbus_int32_t i;
+ dbus_message_iter_get_basic(it, &i);
+ ret = YCPInteger(i);
+ }
+ else if (type == DBUS_TYPE_UINT32)
+ {
+ dbus_uint32_t i;
+ dbus_message_iter_get_basic(it, &i);
+ ret = YCPInteger(i);
+ }
+ else if (type == DBUS_TYPE_INT16)
+ {
+ dbus_int16_t i;
+ dbus_message_iter_get_basic(it, &i);
+ ret = YCPInteger(i);
+ }
+ else if (type == DBUS_TYPE_UINT16)
+ {
+ dbus_uint16_t i;
+ dbus_message_iter_get_basic(it, &i);
+ ret = YCPInteger(i);
+ }
else
{
y2error("Unsupported Dbus type: %d (%c)", type, (char)type);
Modified: branches/tmp/lslezak/workshop/core/scr/src/DBusMsg.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/workshop/core/scr/src/DBusMsg.h?rev=48980&r1=48979&r2=48980&view=diff
==============================================================================
--- branches/tmp/lslezak/workshop/core/scr/src/DBusMsg.h (original)
+++ branches/tmp/lslezak/workshop/core/scr/src/DBusMsg.h Fri Jul 11 09:38:51 2008
@@ -27,6 +27,11 @@
// create a reply
void createReply(const DBusMsg &m);
+ // create an error (exception)
+ void createError(const DBusMsg &m, const std::string &error_msg,
+ // use the generic code by default
+ const std::string &error_code = std::string(DBUS_ERROR_FAILED));
+
bool addString(const std::string &val);
bool addInt64(dbus_int64_t val);
bool addInt32(dbus_int32_t val);
Modified: branches/tmp/lslezak/workshop/core/scr/src/DBusServer.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/workshop/core/scr/src/DBusServer.cc?rev=48980&r1=48979&r2=48980&view=diff
==============================================================================
--- branches/tmp/lslezak/workshop/core/scr/src/DBusServer.cc (original)
+++ branches/tmp/lslezak/workshop/core/scr/src/DBusServer.cc Fri Jul 11 09:38:51 2008
@@ -54,6 +54,9 @@
continue;
}
+ // create a reply to the message
+ DBusMsg reply;
+
y2milestone("Received request from %s: interface: %s, method: %s", request.sender().c_str(),
request.interface().c_str(), request.method().c_str());
@@ -61,74 +64,68 @@
if (request.type() == DBUS_MESSAGE_TYPE_METHOD_CALL && request.interface() == "org.opensuse.yast.SCR" && request.path() == "/SCR")
{
int args = request.arguments();
+
if (args == 0)
{
- // TODO return an ERROR
- continue;
+ // return an ERROR
+ reply.createError(request, "Missing arguments", DBUS_ERROR_INVALID_ARGS);
}
-
- YCPValue arg0 = request.getYCPValue(0);
-
- if (!arg0.isNull() && arg0->isString())
+ else
{
- // DBus doesn't support YCPPath type, string is used as a workaround
- std::string path_str(arg0->asString()->value());
- YCPPath pth(path_str);
- y2milestone("Reading path %s", path_str.c_str());
-
- YCPValue arg = request.getYCPValue(1);
- YCPValue opt = request.getYCPValue(2);
-
- std::string method(request.method());
-
- // result from SCR::
- YCPValue ret;
-
- if (method == "Read")
- ret = sa->Read(pth, arg, opt);
- else if (method == "Write")
- ret = sa->Write(pth, arg, opt);
- else if (method == "Execute")
- ret = sa->Execute(pth, arg, opt);
- else if (method == "Dir")
- ret = sa->Dir(pth);
- else
- {
- y2warning("Unknown requested method %s", method.c_str());
- // TODO return ERROR
- continue;
- }
+ YCPValue arg0 = request.getYCPValue(0);
- DBusMsg reply;
- reply.createReply(request);
-
- if (!ret.isNull())
+ if (!arg0.isNull() && arg0->isString())
{
- reply.addYCPValue(ret);
- }
+ // DBus doesn't support YCPPath type, string is used as a workaround
+ std::string path_str(arg0->asString()->value());
+ YCPPath pth(path_str);
+ y2milestone("Reading path %s", path_str.c_str());
+
+ YCPValue arg = request.getYCPValue(1);
+ YCPValue opt = request.getYCPValue(2);
+
+ std::string method(request.method());
+
+ // result from SCR::
+ YCPValue ret;
+ bool known_method = true;
+
+ if (method == "Read")
+ ret = sa->Read(pth, arg, opt);
+ else if (method == "Write")
+ ret = sa->Write(pth, arg, opt);
+ else if (method == "Execute")
+ ret = sa->Execute(pth, arg, opt);
+ else if (method == "Dir")
+ ret = sa->Dir(pth);
+ else
+ {
+ y2warning("Unknown requested method %s", method.c_str());
+ reply.createError(request, ("Unknown method: " + method).c_str(), DBUS_ERROR_UNKNOWN_METHOD);
+ // don't create a standard reply
+ known_method = false;
+ }
- // send the result
- if (!connection.send(reply))
- {
- y2error("Cannot send the result");
+ if (known_method)
+ {
+ reply.createReply(request);
+
+ if (!ret.isNull())
+ {
+ reply.addYCPValue(ret);
+ }
+ }
}
else
{
- if (!ret.isNull())
- {
- y2milestone("Sending result %s", ret->toString().c_str());
- }
+ reply.createError(request, "First argument must be a string", DBUS_ERROR_INVALID_ARGS);
}
-
- y2milestone("Flushing connection...");
- connection.flush();
- y2milestone("...done");
}
}
- else if (request.isMethodCall("org.freedesktop.DBus.Introspectable", "Introspect"))
+ // handle Introspection request from "org.freedesktop.DBus.Introspectable" "Introspect"
+ else if (request.isMethodCall(DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
{
y2milestone("Requesting path: %s", request.path().c_str());
- // handle Introspection request from "org.freedesktop.DBus.Introspectable" "Introspect"
// define all exported methods here
const char *introspect = (request.path() != "/SCR") ?
// introcpection data for the root node
@@ -138,26 +135,32 @@
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\" \"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\"> <node> </method> </method></method> </method> </interface> </method> </interface> </node> ";
// create a reply to the request
- DBusMsg reply;
reply.createReply(request);
-
reply.addString(introspect);
+ }
+ else
+ {
+ y2warning("Ignoring unknown interface or method call: interface: %s, method: %s",
+ request.interface().c_str(), request.method().c_str());
+
+ // report error
+ reply.createError(request, "Unknown object, interface or method", DBUS_ERROR_UNKNOWN_METHOD);
+ }
+ // was a reply set?
+ if (!reply.empty())
+ {
+ // send the reply
if (!connection.send(reply))
{
- y2error("Cannot send the introspection reply");
+ y2error("Cannot send the result");
}
else
{
- y2milestone("Introspection data sent");
+ y2milestone("Flushing connection...");
+ connection.flush();
+ y2milestone("...done");
}
-
- connection.flush();
- }
- else
- {
- y2warning("Ignoring unknown interface or method call: interface: %s, method: %s",
- request.interface().c_str(), request.method().c_str());
}
y2milestone("Message processed");
Modified: branches/tmp/lslezak/workshop/core/scr/src/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/workshop/core/scr/src/Makefile.am?rev=48980&r1=48979&r2=48980&view=diff
==============================================================================
--- branches/tmp/lslezak/workshop/core/scr/src/Makefile.am (original)
+++ branches/tmp/lslezak/workshop/core/scr/src/Makefile.am Fri Jul 11 09:38:51 2008
@@ -42,7 +42,7 @@
INCLUDES = ${AGENT_INCLUDES}
-bin_PROGRAMS = SCR_dbus_server
+ybin_PROGRAMS = SCR_dbus_server
SCR_dbus_server_SOURCES = SCR_dbus_server.cc DBusServer.cc DBusServer.h \
DBusMsg.cc DBusMsg.h DBusConn.cc DBusConn.h
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org