void amb::BaseJsonMessageReader::canHasData()
{
std::string d = mIo->read();
+ incompleteMessage += d;
+
+ while(hasJson(incompleteMessage));
+}
+
+bool amb::BaseJsonMessageReader::hasJson(string & d)
+{
std::string::size_type start = d.find("{");
- if(start == std::string::npos)
+ if(start == std::string::npos && incompleteMessage.empty())
{
- incompleteMessage += d;
- return;
+ return false;
}
- if(incompleteMessage.empty() && start > 0)
+ if(start > 0)
{
DebugOut(7) << "We have an incomplete message at the beginning. Toss it away." << endl;
d = d.substr(start-1);
if(end == std::string::npos)
{
- incompleteMessage += d;
- return;
+ return false;
}
- std::string tryMessage = incompleteMessage + d.substr(0, end+1);
+ std::string tryMessage = d.substr(0, end+1);
DebugOut(6) << "Trying to parse message: " << tryMessage << endl;
{
DebugOut(7) << "Invalid or incomplete message" << endl;
DebugOut(7) << parseError << endl;
- incompleteMessage += d;
- return;
+ return false;
}
incompleteMessage = end == d.length()-1 ? "" : d.substr(end);
hasJsonMessage(doc);
+ return true;
}
for(auto i : obj)
{
if(i.second.is<picojson::object>())
+ {
ambObj[i.first] = std::shared_ptr<AbstractPropertyType>(amb::jsonToProperty(i.second));
+ }
}
return ambObj;
jsonObj["interfaceName"] = picojson::value(obj.interfaceName);
for(auto i : obj)
{
- jsonObj[i.second->alias()] = i.second->toJson();
+ jsonObj[i.first] = i.second->toJson();
}
return picojson::value(jsonObj);
private:
+ bool hasJson(string &d);
+
std::string incompleteMessage;
};
{
public:
typedef std::function<void (std::vector<Object>)> ListCallback;
- typedef std::function<void (Object)> ObjectCallback;
+ typedef std::function<void (Object&)> ObjectCallback;
typedef std::function<void (bool)> SetCallback;
AmbRemoteClient(AbstractIo* io);
amb::Object interface2("interface2");
interface1.emplace("vehicleSpeed", std::shared_ptr<AbstractPropertyType>(new VehicleProperty::VehicleSpeedType(100)));
+ interface1.emplace("engineSpeed", std::shared_ptr<AbstractPropertyType>(new VehicleProperty::EngineSpeedType(1999)));
+
+ interface2.emplace("engineSpeed", std::shared_ptr<AbstractPropertyType>(new VehicleProperty::EngineSpeedType(3099)));
call.objectNames.push_back(interface1);
call.objectNames.push_back(interface2);
void get(amb::GetMethodCall &get)
{
DebugOut(0) << "get called" << endl;
+
+ if(get.value.interfaceName == "interface1")
+ {
+ amb::Object interface1("interface1");
+
+ interface1.emplace("vehicleSpeed", std::shared_ptr<AbstractPropertyType>(new VehicleProperty::VehicleSpeedType(100)));
+ interface1.emplace("engineSpeed", std::shared_ptr<AbstractPropertyType>(new VehicleProperty::EngineSpeedType(1999)));
+ get.value = interface1;
+ }
+ else if(get.value.interfaceName == "interface2")
+ {
+ amb::Object interface2("interface2");
+ interface2.emplace("engineSpeed", std::shared_ptr<AbstractPropertyType>(new VehicleProperty::EngineSpeedType(3099)));
+ get.value = interface2;
+ }
+
+ send(get);
}
};
DebugOut(0) << "list call reply" << endl;
g_assert(supported.size() == 2);
});
+
+ DebugOut(0) << "calling client->get()" << endl;
+ c->get("interface1", [](amb::Object &obj)
+ {
+ DebugOut(0) << "get call reply" << endl;
+ g_assert(obj.size() == 3);
+ });
}
int main(int argc, char** argv)