Author: lslezak
Date: Tue Feb 10 20:35:15 2009
New Revision: 55398
URL: http://svn.opensuse.org/viewcvs/yast?rev=55398&view=rev
Log:
- DBus service - added /ModuleManager object for explicit import
Modified:
branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc
branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h
branches/tmp/lslezak/core/dbus/namespace_service/modules_dbus_server.cc
branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.cc
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=55398&r1=55397&r2=55398&view=diff
==============================================================================
--- branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc (original)
+++ branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc Tue Feb 10 20:35:15 2009
@@ -50,123 +50,179 @@
}
}
-DBusModulesServer::DBusModulesServer(const NameSpaceList &name_spaces) : e(this), wfm(NULL)
+bool DBusModulesServer::importNamespace(const std::string &nspace)
{
- init_wfm();
+ NameSpaceMap::const_iterator nsiter = nsmap.find(nspace);
- for (NameSpaceList::const_iterator it = name_spaces.begin();
- it != name_spaces.end();
- ++it)
+ if (nsiter != nsmap.end())
{
- Import import(*it); // has an iternal static cache
+ y2internal("Namespace %s has already been imported", nspace.c_str());
+ return true;
+ }
- Y2Namespace *ns = import.nameSpace();
+ Import import(nspace); // has an iternal static cache
- if (ns == NULL)
- {
- y2error("Import name space %s failed", it->c_str());
- }
- else
- {
- ns->initialize();
- std::string objname(*it);
- MakeValidObjectName(objname);
+ Y2Namespace *ns = import.nameSpace();
+
+ if (ns == NULL)
+ {
+ y2error("Import name space %s failed", nspace.c_str());
+ return false;
+ }
+ else
+ {
+ ns->initialize();
+ std::string objname(nspace);
+ MakeValidObjectName(objname);
- y2milestone("Imported name space: %s, using object name: %s", it->c_str(), objname.c_str());
+ y2milestone("Imported name space: %s, using object name: %s", nspace.c_str(), objname.c_str());
- nsmap[objname] = ns;
- }
+ nsmap[objname] = ns;
+
+ return registerNamespace(ns);
}
}
-DBusModulesServer::~DBusModulesServer()
+bool DBusModulesServer::registerFunction(const std::string &nspace, const char *fname, constFunctionTypePtr fptr)
{
- if (wfm != NULL)
+ if (fptr)
{
- y2milestone("Deleting WFM component");
- delete wfm;
- wfm = NULL;
+ constTypePtr rettype = fptr->returnType();
+
+ DBusSignature sig_marshalled;
+ DBusSignature sig_raw;
+
+ // add return type
+ std::string rett(Y2Dtype(rettype));
+
+ if (!rett.empty())
+ {
+ sig_raw.retval = DBusArgument("ret", rett);
+ }
+
+ // TODO FIXME void() ?
+ sig_marshalled.retval = DBusArgument("ret", "(bsv)");
+
+ // add parameter types
+ int params = fptr->parameterCount();
+ int parindex = 0;
+ DBusSignature::Params p_marshalled;
+ DBusSignature::Params p_raw;
+
+ bool params_ok_raw = true;
+
+ while(parindex < params)
+ {
+ std::string partype_raw(Y2Dtype(fptr->parameterType(parindex)));
+
+ if (!partype_raw.empty())
+ {
+ DBusArgument param("param", partype_raw);
+ p_raw.push_back(param);
+ }
+ else
+ {
+ y2warning("Function %s is not exported due to an unsupported parameter type", fname);
+ params_ok_raw = false;
+ }
+
+ DBusArgument param("param", "(bsv)");
+ p_marshalled.push_back(param);
+
+ parindex++;
+ }
+
+ if (params_ok_raw)
+ {
+ sig_raw.params = p_raw;
+ // register the function: register_function(object, interface, method, signature, handler)
+ register_method(nspace, "org.opensuse.yast.modules.Values", fname, sig_raw, e);
+ }
+
+ sig_marshalled.params = p_marshalled;
+ register_method(nspace, "org.opensuse.yast.modules.YCPValues", fname, sig_marshalled, e);
+
+ return true;
}
+
+ return false;
}
-void DBusModulesServer::registerFunctions(const std::string &interface_prefix, bool do_marshalling)
+
+bool DBusModulesServer::registerNamespace(const Y2Namespace *ns)
{
- for (NameSpaceMap::const_iterator it = nsmap.begin();
- it != nsmap.end();
- ++it)
+ if (ns)
{
- Y2Namespace *ns = it->second;
+ unsigned symbols = ns->symbolCount();
+ unsigned index = 0;
- if (ns)
+ while(index < symbols)
{
- unsigned symbols = ns->symbolCount();
- unsigned index = 0;
+ SymbolEntryPtr symbol = ns->symbolEntry(index);
- while(index < symbols)
+ if (symbol)
{
- SymbolEntryPtr symbol = ns->symbolEntry(index);
+ // name of the method
+ const char *name = symbol->name();
+ // type
+ constTypePtr type = symbol->type();
- if (symbol)
+ if (type->isFunction())
{
- // name of the method
- const char *name = symbol->name();
- // type
- constTypePtr type = symbol->type();
-
- if (type->isFunction())
- {
- constFunctionTypePtr fptr = constFunctionTypePtr(type);
+ constFunctionTypePtr fptr = constFunctionTypePtr(type);
- constTypePtr rettype = fptr->returnType();
+ registerFunction(ns->name(), name, fptr);
+ }
+ else
+ {
+ y2debug("Symbol %s::%s is not a function", ns->name().c_str(), name);
+ }
+ }
- DBusSignature sig;
+ index++;
+ }
- // add return type
- std::string rett(do_marshalling ? "(bsv)" : Y2Dtype(rettype));
+ return true;
+ }
- if (!rett.empty())
- {
- sig.retval = DBusArgument("ret", rett);
- }
+ return false;
+}
- // add parameter types
- int params = fptr->parameterCount();
- int parindex = 0;
- DBusSignature::Params p;
- bool params_ok = true;
- while(parindex < params)
- {
- std::string partype(do_marshalling ? "(bsv)" : Y2Dtype(fptr->parameterType(parindex)));
+DBusModulesServer::DBusModulesServer(const NameSpaceList &name_spaces) : e(this), manager_callback(this), wfm(NULL)
+{
+ init_wfm();
- if (!partype.empty())
- {
- DBusArgument param("param", partype);
- p.push_back(param);
- }
- else
- {
- y2warning("Function %s is not exported due to an unsupported parameter type", name);
- params_ok = false;
- break;
- }
+ for (NameSpaceList::const_iterator it = name_spaces.begin();
+ it != name_spaces.end();
+ ++it)
+ {
+ importNamespace(*it);
+ }
+}
- parindex++;
- }
+DBusModulesServer::~DBusModulesServer()
+{
+ if (wfm != NULL)
+ {
+ y2milestone("Deleting WFM component");
+ delete wfm;
+ wfm = NULL;
+ }
+}
- if (params_ok)
- {
- sig.params = p;
- // register the function: register_function(object, interface, method, signature, handler)
- register_method(it->first, interface_prefix, name, sig, e);
- }
- }
- }
+void DBusModulesServer::registerManager()
+{
+ DBusSignature::Params p;
+ DBusArgument param("module_name", DBUS_TYPE_STRING_AS_STRING);
+ p.push_back(param);
+
+ DBusSignature sig;
+ sig.retval = DBusArgument("ret", DBUS_TYPE_BOOLEAN_AS_STRING);
+ sig.params = p;
- index++;
- }
- }
- }
+ // register the manager object: register_function(object, interface, method, signature, handler)
+ register_method("ModuleManager", "org.opensuse.yast.modules.ModuleManager", "Import", sig, manager_callback);
}
std::string DBusModulesServer::Y2Dtype(constTypePtr type) const
@@ -233,8 +289,7 @@
bool DBusModulesServer::connect()
{
- registerFunctions("org.opensuse.yast.modules.YCPValues", true);
- registerFunctions("org.opensuse.yast.modules.Values", false);
+ registerManager();
return DBusServerBase::connect(SYSTEM, "org.opensuse.yast.modules");
}
@@ -454,6 +509,77 @@
return reply;
}
+DBusMsg DBusModulesServer::managerHandler(const DBusMsg &request)
+{
+ DBusMsg reply;
+
+ std::string method(request.method());
+ std::string object(request.path());
+ std::string interface(request.interface());
+
+ y2internal("ModuleManager request: object: %s, method: %s, interface: %s",
+ object.c_str(), method.c_str(), interface.c_str());
+
+ YCPValue ret;
+
+ if (object == "/ModuleManager")
+ {
+ if (interface == "org.opensuse.yast.modules.ModuleManager")
+ {
+ if (method == "Import")
+ {
+ if (request.arguments() == 1)
+ {
+ YCPValue arg = request.getYCPValue(0);
+
+ if (arg.isNull())
+ {
+ y2error("NULL parameter");
+ }
+ else
+ {
+ if (arg->isString())
+ {
+ std::string required_namespace(arg->asString()->value());
+
+ NameSpaceMap::const_iterator nsiter = nsmap.find(required_namespace);
+ if (nsiter != nsmap.end())
+ {
+ ret = YCPBoolean(true);
+ }
+ else
+ {
+ bool retval = importNamespace(arg->asString()->value());
+
+ ret = YCPBoolean(retval);
+ }
+ }
+ else
+ {
+ y2error("Expecting 'string' parameter, got '%s'", Type::vt2type(arg->valuetype())->toString().c_str());
+ }
+ }
+
+ }
+ else
+ {
+ y2error("ModuleManager function %s got %d parameters instead of 1", method.c_str(), request.arguments());
+ }
+ }
+ }
+ }
+
+ reply.createReply(request);
+
+ if (!ret.isNull())
+ {
+ y2milestone("Result: %s", ret->toString().c_str());
+ reply.addValue(ret);
+ }
+
+ return reply;
+}
+
std::string DBusModulesServer::createActionId(const DBusMsg &msg)
{
// actionId: <prefix>.<namespace>.<method>
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=55398&r1=55397&r2=55398&view=diff
==============================================================================
--- branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h (original)
+++ branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h Tue Feb 10 20:35:15 2009
@@ -48,8 +48,12 @@
// try to cast from a DBus value to the expected YCPValue
YCPValue AutoCast(const YCPValue &value, constTypePtr requested_type);
- // register the functions from the namespace to DBus service
- void registerFunctions(const std::string &interface_prefix, bool do_marshalling);
+ // import a Yast namespace
+ bool importNamespace(const std::string &nspace);
+ bool registerFunction(const std::string &nspace, const char *fname, constFunctionTypePtr fptr);
+ bool registerNamespace(const Y2Namespace *ns);
+
+ void registerManager();
DBusMsg handler(const DBusMsg &request);
@@ -68,6 +72,24 @@
Callback e;
+ DBusMsg managerHandler(const DBusMsg &request);
+
+ class ManagerCallback : public std::function