1. scope
  2. hob

Commits

Christian Krebs  committed df61b73

Incorporated review feedback

  • Participants
  • Parent commits 6631e8a
  • Branches default

Comments (0)

Files changed (2)

File templates/js/get_message_maps.js

View file
 {
 
   /* interface */
-  this.get_maps = function(service_descriptions, onsuccess, onerror, get_messages_flag){};
+  this.get_maps = function(service_descriptions, onsuccess, onerror, should_get_messages){};
   
   /* constants */
   const 
   // ===========================
   // get the messages from scope
   // ===========================
-  this._get_maps = function()     
-  {
-    if (this._service_descriptions.scope)
-    {
-      var version = this._service_descriptions.scope.version.split('.').map(Number);
-      if (version[1] >= 1) 
-        this._request_enums();
-      else 
-        this._request_infos();
-    }
-    else 
-      this._onerror({message: "failed to get maps, no scope in  service descriptions"});
-
-  };
   
   this._request_enums = function()
   {
     if (!status)
     {
       this._service_infos[service]['raw_enums'] = msg;
-      if (this._check_map_complete('raw_enums'))
-        this._request_infos();
+      if (this._is_map_complete('raw_enums'))
+        this._request_info();
     }
     else
       this._onerror({message: "failed to get enums for " + service + " in _handle_enums"});
   };
 
-  this._request_infos = function()
+  this._request_info = function()
   {
     var service = '', tag = 0;
     for (service in this._service_infos)
     if (!status)
     {
       this._service_infos[service]['raw_infos'] = msg;
-      if (this._get_messages_flag)
+      if (this._should_get_messages)
       {
         var tag = tagManager.set_callback(this, this._handle_messages, [service]);
         services["scope"].requestMessageInfo(tag, [service, [], 1, 1]);
         this._service_infos[service]['raw_messages'] = null;
         this._onerror({message: "failed to build the message maps for " + service});
       }
-      if (this._check_map_complete('raw_messages'))
+      if (this._is_map_complete('raw_messages'))
         this._finalize();
     }
     else
       this._onerror({message: "failed to get infos for " + service + " in _handle_infos"});
   };
 
-  this._check_map_complete = function(prop)
+  this._is_map_complete = function(prop)
   {
     for (var service in this._service_infos)
       if (!this._service_infos[service][prop])
       command = command_list[i];
       command_obj = map[command[NUMBER]] = {};
       command_obj.name = command[MSG_NAME];
-      if (this._get_messages_flag)
+      if (this._should_get_messages)
       {
         msg = this._get_msg(msgs, command[MESSAGE_ID]);
         command_obj[MSG_TYPE_COMMAND] = this._parse_msg(msg, msgs, {}, enums, []);
         event = event_list[i];
         event_obj = map[event[NUMBER]] = {};
         event_obj.name = event[MSG_NAME];
-        if (this._get_messages_flag)
+        if (this._should_get_messages)
         {
           msg = this._get_msg(msgs, event[MESSAGE_ID]);
           event_obj[MSG_TYPE_EVENT] = this._parse_msg(msg, msgs, {}, enums, []);
   this._finalize = function()
   {
     this._onsuccess(this._map);
-    this._service_descriptions = null; 
     this._onsuccess = null;
     this._onerror = null;
     this._service_infos = null;
 
   /* implementation */
   
-  this.get_maps = function(service_descriptions, onsuccess, onerror, get_messages_flag)
+  this.get_maps = function(service_descriptions, onsuccess, onerror, should_get_messages)
   {
-    if (!onsuccess || !onerror)
-    {
-      throw new Error("get_maps must be called with an onsuccess and an onerror callback");
-    }
-    this._service_descriptions = service_descriptions;
+    /**
+      * service_descriptions must be a dictonary of services. 
+      * Each service must have a name and a version.  
+      * service_descriptions is typically created with the 
+      * respond message of the HostInfo command of the scope service.
+      */
+    if (!service_descriptions || !onsuccess || !onerror)
+      throw new Error("get_maps must be called with a service_descriptions dictionary and " +
+          "an onsuccess and an onerror callback");
     this._onsuccess = onsuccess;
     this._onerror = onerror;
     this._service_infos = {};
     this._map = {};
-    this._get_messages_flag = get_messages_flag === false ? false : true;
+    this._should_get_messages = should_get_messages === false ? false : true;
     for (var service in service_descriptions)
     {
       if (!/^stp-|^core-/.test(service))
         }
       }
     }
-    this._get_maps(service_descriptions);
+    if (service_descriptions.scope)
+    {
+      var version = service_descriptions.scope.version.split('.').map(Number);
+      if (version[1] >= 1) 
+        this._request_enums();
+      else 
+        this._request_info();
+    }
+    else 
+      this._onerror({message: "failed to get maps, no scope in  service descriptions"});
   }
 };
 
     2: "Response",
     3: "Event",
   };
-  print_list.push(this._get_indent(indent) + this._quote(name, ': ') + '{');
+  print_list.push(this._get_indent_string(indent) + this._quote(name, ': ') + '{');
   indent++;
   for (var key in obj)
   {
     if (typeof obj[key] == 'string' || typeof obj[key] == 'number')
     {
       if (key == 'type' && /^\d+$/.test(obj[key]))
-        print_list.push(this._get_indent(indent) + 
+        print_list.push(this._get_indent_string(indent) + 
             this._quote(key) + ': "' + TYPE[obj[key]] + '", // ' + obj[key]);
       else
-        print_list.push(this._get_indent(indent) + 
+        print_list.push(this._get_indent_string(indent) + 
             this._quote(key) + ': ' + this._quote(obj[key]) +',');
     }
   }
       {
         if (circular_check_list.indexOf(obj.message_name) != -1)
         {
-          print_list.push(this._get_indent(indent) + '"message": <circular reference>,');
+          print_list.push(this._get_indent_string(indent) + '"message": <circular reference>,');
           continue;
         }
         else
           circular_check_list.push(obj.message_name);
       }
       if (indent == 3)
-        print_list.push(this._get_indent(indent) + '// ' + MSG_TYPE[key]);
+        print_list.push(this._get_indent_string(indent) + '// ' + MSG_TYPE[key]);
       if (obj[key].length)
       {
-        print_list.push(this._get_indent(indent) + this._quote(key) + ': [');
+        print_list.push(this._get_indent_string(indent) + this._quote(key) + ': [');
         for (var i = 0; i < obj[key].length; i++)
           this._pretty_print_object('', obj[key][i], indent + 1, print_list, circular_check_list);
-        print_list.push(this._get_indent(indent) + '],');
+        print_list.push(this._get_indent_string(indent) + '],');
       }
       else
-        print_list.push(this._get_indent(indent) + this._quote(key) + ': [],');
+        print_list.push(this._get_indent_string(indent) + this._quote(key) + ': [],');
     }
   }
   indent--;
-  print_list.push(this._get_indent(indent) + '},');
+  print_list.push(this._get_indent_string(indent) + '},');
   return print_list;
 };
 
-window.cls.GetMessageMaps._get_indent = function(indent)
+window.cls.GetMessageMaps._get_indent_string = function(level, indent)
 {
-  const INDENT = '  ';
-  for (var ret = ''; indent-- && (ret += INDENT); );
-  return ret;
+  return new Array(level).join(indent || '  ');
 };
 
 window.cls.GetMessageMaps._quote = function(value, token)

File templates/js/messagemixin.js

View file
    */
   this.post_message = function( name, msg )
   {
-    if (! this._mm_listeners) { return; }
+    if (! this._mm_listeners) { return false; }
     if (msg === undefined || msg === null || isNaN(msg)) 
     {
       msg = {};
         cb(msg);
       }
     }
+    return Boolean(i);
   };
   this.post = this.post_message;
 }