MediaServer object properties
authorLuc Yriarte <luc.yriarte@intel.com>
Mon, 22 Jul 2013 16:24:59 +0000 (18:24 +0200)
committerLuc Yriarte <luc.yriarte@intel.com>
Mon, 22 Jul 2013 16:24:59 +0000 (18:24 +0200)
src/MediaServer/JSMediaServer.cpp
src/MediaServer/JSMediaServer.h

index 2c1e463..ec46aa1 100644 (file)
@@ -42,6 +42,14 @@ JSClassDefinition JSMediaServer::m_classInfo = {
        NULL, //ConvertToType
 };
 
+JSStaticValue JSMediaServer::m_property[] =
+{
+       {"id",  getProperty, NULL, kJSPropertyAttributeReadOnly},
+       {"friendlyName",  getProperty, NULL, kJSPropertyAttributeReadOnly},
+       {"root",  getProperty, NULL, kJSPropertyAttributeReadOnly},
+       { 0, 0, 0, 0 }
+};
+
 JSStaticFunction JSMediaServer::m_function[] = {
        {"browse", JSMediaServer::browse, kJSPropertyAttributeNone},
        {"find", JSMediaServer::find, kJSPropertyAttributeNone},
@@ -98,6 +106,38 @@ bool JSMediaServer::hasInstance(JSContextRef context,
 }
 
 
+JSValueRef JSMediaServer::getProperty(JSContextRef context,
+               JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+       LoggerD("Entered ");
+       // TODO try/catch block
+               MediaServerPrivObject* privateObject = static_cast<MediaServerPrivObject*>(JSObjectGetPrivate(object));
+               if (NULL == privateObject)
+               {
+                       LoggerE("private object is null");
+                       // TODO post exception
+               }
+
+               if (JSStringIsEqualToUTF8CString(propertyName, "id")) {
+                       JSStringRef jsStr = JSStringCreateWithUTF8CString("/com/intel/..."); // FIXME use proxy value
+                       return JSValueMakeString(context, jsStr);
+               }
+               if (JSStringIsEqualToUTF8CString(propertyName, "friendlyName")) {
+                       JSStringRef jsStr = JSStringCreateWithUTF8CString("FIXME mediaserver"); // FIXME use proxy value
+                       return JSValueMakeString(context, jsStr);
+               }
+               if (JSStringIsEqualToUTF8CString(propertyName, "root")) {
+                       JSStringRef jsStr = JSStringCreateWithUTF8CString("FIXME mediaserver root "); // FIXME use proxy value
+                       return JSValueMakeFromJSONString(context, jsStr);
+               }
+
+    return JSValueMakeUndefined(context);
+}
+
+
+
 JSValueRef JSMediaServer::browse(JSContextRef context,
                JSObjectRef object,
                JSObjectRef thisObject,
index 7cba63e..02f6106 100644 (file)
@@ -19,6 +19,7 @@ public:
 
        static const JSClassRef getClassRef();
 
+    static JSObjectRef createJSObject(JSContextRef context);
 private:
        /**
                * The callback invoked when an object is first created.
@@ -39,6 +40,14 @@ private:
                                                        JSValueRef possibleInstance,
                                                        JSValueRef* exception);
 
+    /**
+     * Getters  for properties
+     */
+    static JSValueRef getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception);
+
 
        /**
                * Browses for media item under a given MediaContainer.
@@ -72,6 +81,13 @@ private:
                 */
        static JSStaticFunction m_function[];
 
+    /**
+     * This member variable contains the initialization values for the
+     * properties of this class. The values are given according to the
+     * data structure JSPropertySpec.
+     */
+    static JSStaticValue m_property[];
+
        static JSClassRef m_jsClassRef;
 };