From: Andreas V. <li...@br...> - 2010-08-03 22:20:15
|
Am Sun, 25 Jul 2010 10:52:50 +0300 schrieb Or Goshen: > Hi > > How do I assign a value to a new variant type ? > > For example: > > ::DBus::Variant Server::get(const std::string& key) { > ::DBus::Variant var; > > // var = std::string("test"); // not this way > > // var.writer() << std::string("test"); // not this way either > > return var; > } > > Next question - suppose a Variant contains an array of strings, how > do I detect that + how do I parse that ? > > For example: > > void Server::set(const std::string& key, const ::DBus::Variant& > value) { if (value.signature().c_str()[0] == 'a') { > // array > //Am I suppose to parse the signature here ? > } else { > // basic type > std::string str = value; > std::cout << str << std::endl; > } > } Hello Or, see here some code how I use dbus-c++ with Obex. There's a usage of Variant: ObexClient obexClient (conn); ::DBus::Variant v; ::DBus::MessageIter m = v.writer(); m.append_string("00:21:AB:D6:25:3F"); ::DBus::Variant v2; ::DBus::MessageIter m2 = v2.writer(); m2.append_string("PBAP"); map <std::string, ::DBus::Variant> sessionParam; sessionParam["Destination"] = v; sessionParam["Target"] = v2; ::DBus::Path session_path = obexClient.CreateSession (sessionParam); cout << "Session Path: " << session_path << endl; PhonebookAccess pbap (conn, session_path); ObexSession obexSession (conn, session_path); pbap.Select ("SIM", "och"); pbap.SetFormat ("vcard30"); string ret = pbap.PullAll (); cout << ret << endl; If you've still some questions then please assign to the list. I allowed your mail even if you're not assigned this one time. regards Andreas |