@@ -34,8 +34,10 @@ typedef enum {
34
34
35
35
struct client_resource {
36
36
char * device_id ;
37
- char * resource_type ;
38
37
char * resource_path ;
38
+ char * resource_type ;
39
+ jerry_value_t types_array ;
40
+ jerry_value_t iface_array ;
39
41
oc_server_handle_t server ;
40
42
resource_state state ;
41
43
jerry_value_t client ;
@@ -251,19 +253,22 @@ static struct client_resource *find_resource_by_path(const char *path)
251
253
/*
252
254
* Create a new resource object
253
255
*/
254
- static jerry_value_t create_resource (const char * device_id , const char * path )
256
+ static jerry_value_t create_resource (struct client_resource * client )
255
257
{
256
258
jerry_value_t resource = jerry_create_object ();
257
259
258
- if (device_id ) {
259
- zjs_obj_add_string (resource , device_id , "deviceId" );
260
+ if (client -> device_id ) {
261
+ zjs_obj_add_string (resource , client -> device_id , "deviceId" );
260
262
}
261
- if (path ) {
262
- zjs_obj_add_string (resource , path , "resourcePath" );
263
+ if (client -> resource_path ) {
264
+ zjs_obj_add_string (resource , client -> resource_path , "resourcePath" );
263
265
}
264
266
ZVAL props = jerry_create_object ();
265
267
zjs_set_property (resource , "properties" , props );
266
268
269
+ zjs_set_property (resource , "resourceTypes" , client -> types_array );
270
+ zjs_set_property (resource , "interfaces" , client -> iface_array );
271
+
267
272
DBG_PRINT ("id=%s, path=%s, obj number=%lu\n" , device_id , path , resource );
268
273
269
274
return resource ;
@@ -290,6 +295,8 @@ static void free_client(const uintptr_t native_p)
290
295
if (client -> resource_type ) {
291
296
zjs_free (client -> resource_type );
292
297
}
298
+ jerry_release_value (client -> types_array );
299
+ jerry_release_value (client -> iface_array );
293
300
zjs_free (client );
294
301
}
295
302
}
@@ -424,8 +431,58 @@ static oc_discovery_flags_t discovery(const char *di,
424
431
memcpy (cur -> resource_path , uri , uri_len );
425
432
cur -> resource_path [uri_len ] = '\0' ;
426
433
}
434
+ /*
435
+ * Add the array of resource types to newly discovered resource
436
+ */
437
+ uint32_t sz = oc_string_array_get_allocated_size (types );
438
+ cur -> types_array = jerry_create_array (sz );
439
+
440
+ for (i = 0 ; i < sz ; i ++ ) {
441
+ char * t = oc_string_array_get_item (types , i );
442
+ ZVAL val = jerry_create_string (t );
443
+ jerry_set_property_by_index (cur -> types_array , i , val );
444
+ }
445
+ /*
446
+ * Add array of interfaces
447
+ */
448
+ sz = 0 ;
449
+ // count up set ifaces
450
+ for (i = 1 ; i < 8 ; ++ i ) {
451
+ if ((1 << i ) & interfaces ) {
452
+ sz ++ ;
453
+ }
454
+ }
455
+ cur -> iface_array = jerry_create_array (sz );
456
+ if (interfaces & OC_IF_BASELINE ) {
457
+ ZVAL val = jerry_create_string ("oic.if.baseline" );
458
+ jerry_set_property_by_index (cur -> iface_array , -- sz , val );
459
+ }
460
+ if (interfaces & OC_IF_LL ) {
461
+ ZVAL val = jerry_create_string ("oic.if.ll" );
462
+ jerry_set_property_by_index (cur -> iface_array , -- sz , val );
463
+ }
464
+ if (interfaces & OC_IF_B ) {
465
+ ZVAL val = jerry_create_string ("oic.if.b" );
466
+ jerry_set_property_by_index (cur -> iface_array , -- sz , val );
467
+ }
468
+ if (interfaces & OC_IF_R ) {
469
+ ZVAL val = jerry_create_string ("oic.if.r" );
470
+ jerry_set_property_by_index (cur -> iface_array , -- sz , val );
471
+ }
472
+ if (interfaces & OC_IF_RW ) {
473
+ ZVAL val = jerry_create_string ("oic.if.rw" );
474
+ jerry_set_property_by_index (cur -> iface_array , -- sz , val );
475
+ }
476
+ if (interfaces & OC_IF_A ) {
477
+ ZVAL val = jerry_create_string ("oic.if.a" );
478
+ jerry_set_property_by_index (cur -> iface_array , -- sz , val );
479
+ }
480
+ if (interfaces & OC_IF_S ) {
481
+ ZVAL val = jerry_create_string ("oic.if.s" );
482
+ jerry_set_property_by_index (cur -> iface_array , -- sz , val );
483
+ }
427
484
428
- ZVAL res = create_resource (cur -> device_id , cur -> resource_path );
485
+ ZVAL res = create_resource (cur );
429
486
zjs_trigger_event (cur -> client , "resourcefound" , & res , 1 , NULL ,
430
487
NULL );
431
488
zjs_fulfill_promise (h -> promise_obj , & res , 1 );
@@ -528,8 +585,7 @@ static void ocf_get_handler(oc_client_response_t *data)
528
585
if (h && h -> res ) {
529
586
struct client_resource * resource = h -> res ;
530
587
if (data -> code == OC_STATUS_OK ) {
531
- ZVAL resource_val = create_resource (resource -> device_id ,
532
- resource -> resource_path );
588
+ ZVAL resource_val = create_resource (resource );
533
589
ZVAL properties_val = get_props_from_response (data );
534
590
535
591
zjs_set_property (resource_val , "properties" , properties_val );
@@ -664,8 +720,7 @@ static void put_finished(oc_client_response_t *data)
664
720
if (data -> code == OC_STATUS_CHANGED ) {
665
721
DBG_PRINT ("PUT response OK, device_id=%s\n" ,
666
722
resource -> device_id );
667
- ZVAL resource_val = create_resource (resource -> device_id ,
668
- resource -> resource_path );
723
+ ZVAL resource_val = create_resource (resource );
669
724
zjs_fulfill_promise (h -> promise_obj , & resource_val , 1 );
670
725
} else {
671
726
ERR_PRINT ("PUT response code %d\n" , data -> code );
@@ -852,6 +907,10 @@ static void ocf_get_platform_info_handler(oc_client_response_t *data)
852
907
zjs_obj_add_readonly_string (platform_info , oc_string (rep -> value .string ), "osVersion" );
853
908
} else if (strcmp (oc_string (rep -> name ), "mnfv" ) == 0 ) {
854
909
zjs_obj_add_readonly_string (platform_info , oc_string (rep -> value .string ), "firmwareVersion" );
910
+ } else if (strcmp (oc_string (rep -> name ), "mnml" ) == 0 ) {
911
+ zjs_obj_add_readonly_string (platform_info , oc_string (rep -> value .string ), "manufacturerURL" );
912
+ } else if (strcmp (oc_string (rep -> name ), "mnsl" ) == 0 ) {
913
+ zjs_obj_add_readonly_string (platform_info , oc_string (rep -> value .string ), "supportURL" );
855
914
}
856
915
DBG_PRINT ("%s\n" , oc_string (rep -> value .string ));
857
916
break ;
0 commit comments