From: Kevron Rees Date: Wed, 21 Aug 2013 23:19:07 +0000 (-0700) Subject: added getHistory call. it is synchronous for now X-Git-Tag: submit/tizen/20130821.232007^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4df09072364277b7669336f43a2833e1de541bb9;p=profile%2Fivi%2Fwrt-plugins-ivi.git added getHistory call. it is synchronous for now --- diff --git a/packaging/wrt-plugins-ivi.changes b/packaging/wrt-plugins-ivi.changes index 10aba0a..c1033ba 100644 --- a/packaging/wrt-plugins-ivi.changes +++ b/packaging/wrt-plugins-ivi.changes @@ -1,3 +1,7 @@ +* Tue Aug 20 2013 +- Added GetHistory call to vehicle +- integrated speech api + * Tue Aug 06 2013 - Added set() call - lowerCamelCase for object members diff --git a/packaging/wrt-plugins-ivi.spec b/packaging/wrt-plugins-ivi.spec index 80382ae..a4d0482 100644 --- a/packaging/wrt-plugins-ivi.spec +++ b/packaging/wrt-plugins-ivi.spec @@ -1,6 +1,6 @@ Name: wrt-plugins-ivi Summary: JavaScript plugins for WebRuntime for IVI -Version: 0.6.0 +Version: 0.7.0 Release: 1 Group: Development/Libraries License: Apache License, Version 2.0 diff --git a/src/Vehicle/JSVehicle.cpp b/src/Vehicle/JSVehicle.cpp index cfc4f62..b544102 100644 --- a/src/Vehicle/JSVehicle.cpp +++ b/src/Vehicle/JSVehicle.cpp @@ -50,6 +50,7 @@ JSStaticFunction JSVehicle::m_function[] = { { "subscribe", JSVehicle::subscribe, kJSPropertyAttributeNone }, { "supported", JSVehicle::supported, kJSPropertyAttributeNone }, { "set", JSVehicle::set, kJSPropertyAttributeNone }, + { "getHistory", JSVehicle::getHistory, kJSPropertyAttributeNone }, { 0, 0, 0 } }; @@ -361,7 +362,25 @@ JSValueRef JSVehicle::getHistory(JSContextRef context, std::string objectName = validator.toString(0); + LoggerD("objectName to getHistory on = "<getHistory(objectName, (double)begin, (double)end, successCallback, errorCallback, context); + + return JSValueMakeUndefined(context); } } diff --git a/src/Vehicle/Vehicle.cpp b/src/Vehicle/Vehicle.cpp index 4784035..f2ee5f3 100644 --- a/src/Vehicle/Vehicle.cpp +++ b/src/Vehicle/Vehicle.cpp @@ -8,6 +8,11 @@ #include #include +#include // uuid class +#include // generators +#include +#include + namespace DeviceAPI { namespace Vehicle @@ -16,6 +21,14 @@ namespace Vehicle using namespace WrtDeviceApis::Commons; using namespace WrtDeviceApis::CommonsJavaScript; +std::map VehicleMaster::historyMap; + +class DataClass +{ +public: + std::string uuid; +}; + GVariant* jsValueToGVariant(JSContextRef ctx, JSValueRef jsVal, std::string signature) { LoggerD("Entered"); @@ -59,6 +72,36 @@ GVariant* jsValueToGVariant(JSContextRef ctx, JSValueRef jsVal, std::string sign return nullptr; } +std::string mapToJSon(std::map propertyMap) +{ + std::stringstream json; + + json<<"{"; + + for(auto itr = propertyMap.begin(); itr != propertyMap.end(); itr++) + { + if(json.str() != "{") json<<","; + + std::string key = (*itr).first; + + /// make lowerCamelCase: + std::transform(key.begin(), key.begin()+1, key.begin(), ::tolower); + + GVariant* var = (*itr).second; + + gsize size; + + json<<"\""<message); ///TODO: call error callback return; } @@ -294,35 +337,9 @@ void VehicleMaster::onSignalReceived(std::string objectName, std::map cbs = objectToFunctionListMap[objectName]; @@ -482,5 +499,131 @@ VehicleMaster::ErrorType VehicleMaster::set(std::string objectName, std::map(user_data); + + VehicleSubscribeCB histCb; // = VehicleMaster::historyMap[uuid->uuid]; + + histCb.callback = successCallback; + histCb.errorCallback = errorCallback; + histCb.context = context; + + //delete uuid; + + if(error) + { + LoggerD("error getting history: "<message); + LoggerD("pre-error-callback"); + const JSValueRef arguments[1] = { JSValueMakeNumber(histCb.context, 10) }; + JSObjectCallAsFunction(histCb.context, histCb.errorCallback, NULL, 1, arguments, NULL); + LoggerD("post error callback"); + return; + } + + LoggerD("TRACE"); + + GVariantIter* iter; + char* key; + GVariant *value; + double time; + + LoggerD("variant sig type: "< superList; + std::map obj; + + while(g_variant_iter_next(iter,"(svd)", &key, &value, &time)) + { + if(obj.find(key) != obj.end()) + { + superList.push_back(mapToJSon(obj)); + obj.clear(); + } + + obj[key] = value; + obj["time"] = g_variant_new_double(time); + } + + JSValueRef values[superList.size()]; + + int i=0; + + LoggerD("populating array"); + + for(auto itr = superList.begin(); itr != superList.end(); itr++) + { + std::string jsonObj = *itr; + JSStringRef jsonString = JSStringCreateWithUTF8CString(jsonObj.c_str()); + + values[i] = JSValueMakeFromJSONString(histCb.context, jsonString); + i++; + + JSStringRelease(jsonString); + } + + LoggerD("making array"); + + JSObjectRef jsresult = JSObjectMakeArray(histCb.context, superList.size(), values, NULL); + + const JSValueRef arguments[1] = { jsresult }; + + LoggerD("calling callback"); + JSObjectCallAsFunction(histCb.context, histCb.callback, NULL, 1, arguments, NULL); + LoggerD("finished calling callback"); + + JSValueUnprotect(histCb.context, histCb.callback); + JSValueUnprotect(histCb.context, histCb.errorCallback); + }; + + /*VehicleSubscribeCB cbObj; + + cbObj.callback = successCallback; + cbObj.errorCallback = errorCallback; + cbObj.context = context; + + boost::uuids::uuid uuid = boost::uuids::random_generator()(); + + DataClass* data = new DataClass(); + data->uuid = boost::lexical_cast(uuid); + + VehicleMaster::historyMap[data->uuid] = cbObj; + + + //g_dbus_proxy_call(proxy, "GetHistory", g_variant_new("(dd)", begin, end), G_DBUS_CALL_FLAGS_NONE, -1, NULL, (GAsyncReadyCallback)cb, data);*/ +} + } } \ No newline at end of file diff --git a/src/Vehicle/Vehicle.h b/src/Vehicle/Vehicle.h index df6a5de..8b89542 100644 --- a/src/Vehicle/Vehicle.h +++ b/src/Vehicle/Vehicle.h @@ -18,6 +18,7 @@ class VehicleSubscribeCB { public: JSObjectRef callback; + JSObjectRef errorCallback; JSContextRef context; }; @@ -44,6 +45,8 @@ public: VehicleMaster::ErrorType set(std::string objectName, std::map values, JSContextRef context); + void getHistory(std::string objectName, double begin, double end, JSObjectRef successCallback, JSObjectRef errorCallback, JSContextRef context); + private: /// methods: GDBusProxy* automotiveManager(); @@ -56,6 +59,7 @@ public: std::map > objectToFunctionListMap; std::map objectPathToObjectNameMap; + static std::map historyMap; }; typedef DPL::SharedPtr VehiclePtr;