5 #include <Commons/Exception.h>
6 #include <CommonsJavaScript/Utils.h>
7 #include <CommonsJavaScript/JSCallbackManager.h>
8 #include <JSWebAPIErrorFactory.h>
9 #include <ArgumentValidator.h>
10 #include <CommonsJavaScript/Converter.h>
13 #include <abstractpropertytype.h>
19 using namespace DeviceAPI::Common;
20 using namespace WrtDeviceApis::Commons;
21 using namespace WrtDeviceApis::CommonsJavaScript;
23 JSClassDefinition JSVehicle::m_classInfo = {
25 kJSClassAttributeNone,
35 NULL, //DeleteProperty,
36 NULL, //GetPropertyNames,
37 NULL, //CallAsFunction,
38 NULL, //CallAsConstructor,
43 JSStaticFunction JSVehicle::m_function[] = {
44 { "get", JSVehicle::get, kJSPropertyAttributeNone },
48 const JSClassRef JSVehicle::getClassRef()
52 m_jsClassRef = JSClassCreate(&m_classInfo);
57 const JSClassDefinition* JSVehicle::getClassInfo()
62 JSClassRef JSVehicle::m_jsClassRef = JSClassCreate(JSVehicle::getClassInfo());
64 void JSVehicle::initialize(JSContextRef context, JSObjectRef object)
66 VehiclePrivObject* priv = static_cast<VehiclePrivObject*>(JSObjectGetPrivate(object));
69 VehiclePtr vehicle(new VehicleMaster());
70 priv = new VehiclePrivObject( context, vehicle);
71 if(!JSObjectSetPrivate(object, static_cast<void*>(priv)))
73 LoggerE("Object can't store private data.");
78 LoggerD("JSVehicle::initialize ");
81 void JSVehicle::finalize(JSObjectRef object)
83 VehiclePrivObject* priv = static_cast<VehiclePrivObject*>(JSObjectGetPrivate(object));
84 JSObjectSetPrivate(object, NULL);
85 LoggerD("Deleting timeutil");
89 bool JSVehicle::hasInstance(JSContextRef context,
90 JSObjectRef constructor,
91 JSValueRef possibleInstance,
92 JSValueRef* exception)
94 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
98 JSValueRef JSVehicle::get(JSContextRef context,
100 JSObjectRef thisObject,
101 size_t argumentCount,
102 const JSValueRef arguments[],
103 JSValueRef* exception)
107 VehiclePrivObject* privateObject = static_cast<VehiclePrivObject*>(JSObjectGetPrivate(thisObject));
108 if (NULL == privateObject)
110 LoggerE("private object is null");
111 //return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
114 ArgumentValidator validator(context, argumentCount, arguments);
115 std::string property = validator.toString(0);
117 VehiclePtr vehicle(privateObject->getObject());
119 std::list<AbstractPropertyType*> properties = vehicle->get(property);
121 std::stringstream json;
126 for(auto itr = properties.begin(); itr != properties.end(); itr++)
128 if(json.str() != "{") json<<",";
130 AbstractPropertyType* p = *itr;
132 json<<"\""<<p->name<<"\" : "<<p->toString();
138 Converter converter(context);
140 return converter.toJSValueRef(json.str());
143 /*} Catch (PlatformException) {
144 LoggerE("Exception: " << _rethrown_exception.GetMessage());
145 } Catch(NullPointerException) {
146 LoggerE("Exception: " << _rethrown_exception.GetMessage());
147 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
148 } Catch (WrtDeviceApis::Commons::Exception) {
149 LoggerE("Exception: " << _rethrown_exception.GetMessage());
152 //return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");