Commits

Christian Krebs committed 1002662

populate the local event map of the default message receive handler with the dynamic created map

  • Participants
  • Parent commits 3212f1e

Comments (0)

Files changed (3)

File templates/js/js-build_application.mako

       function(map)
       {
         window.message_maps = map;
+        window.cls.ServiceBase.populate_map(map);
         build_and_enable_services(service_descriptions, map);
         window.test_framework.rebuild_last_state();
       }, 

File templates/js/js-http-interface.mako

       logger.log(
           '\nreceived:',
           '\n  service: ' + service,
-          '\n  command: '+ _event_map[service][command],
+          '\n  command: '+ (_event_map[service] && _event_map[service][command] || "<" + command + ">"),
           '\n  status: ' + _status_map[status],
           '\n  tag: ' + tag,
           '\n  payload: ' + xhr.responseText.replace(/([,.()])/g, '$1\u200b')
     logger.log(
         '\nsent:',
         '\n  service: ' + service,
-        '\n  command: '+ _event_map[service][command_id],
+        '\n  command: '+ (_event_map[service] && _event_map[service][command_id] || "<" + command_id + ">"),
         '\n  tag: ' + tag,
         '\n  payload: ' + JSON.stringify(message)
       );

File templates/js/js-service-base.mako

   * @constructor 
   */
 
-window.cls.ServiceBase = function()
+window.cls.ServiceBase = function ServiceBase()
 {
   // singleton
-  if(arguments.callee.instance)
+  if(ServiceBase.instance)
   {
-    return arguments.callee.instance;
+    return ServiceBase.instance;
   }
-  arguments.callee.instance = this;
+  ServiceBase.instance = this;
 
   window.cls.MessageMixin.apply(this); // mix in message handler behaviour.
 
 
   var _services = null;
   var _event_map = {};
+  
 % for service in services:
+  % if service.name == "Scope":
   _event_map['${dashed_name(service.name)}'] = [];
-  % for command in service.itercommands():
+    % for command in service.itercommands():
   _event_map['${dashed_name(service.name)}'][${command.id}] = 'handle${command.name}';
-  % endfor
-  % for event in service.iterevents():
+    % endfor
+    % for event in service.iterevents():
   _event_map['${dashed_name(service.name)}'][${event.id}] = '${event.name.replace('On', 'on')}';
-  % endfor
+    % endfor
+  % endif
 % endfor
 
+
   var _status_map = [];
   _status_map[0] = "OK";
   _status_map[1] = "Conflict";
     {
       service_obj[msg_name](status, message);
     }
-  }
+  };
 
   var _handle_scope_message_debug = function(service, message, command, status, tag)
   {
     window.debug.log_message(service, message, command, status, tag);
     _handle_scope_message(service, message, command, status, tag);
-  }
+  };
 
   // static methods
 
-  arguments.callee.get_event_map = function()
+  (function()
   {
-    return _event_map;
-  }
 
-  arguments.callee.get_status_map = function()
-  {
-    return _status_map;
-  }
+    this.get_event_map = function()
+    {
+      return _event_map;
+    };
 
-  arguments.callee.get_type_map = function()
-  {
-    return _type_map;
-  }
+    this.get_status_map = function()
+    {
+      return _status_map;
+    };
 
-  arguments.callee.get_generic_message_handler = function()
-  {
-    return window.ini && window.ini.debug && _handle_scope_message_debug || _handle_scope_message;
-  }
+    this.get_type_map = function()
+    {
+      return _type_map;
+    };
 
-  arguments.callee.register_services = function(namespace)
-  {
-    _services = namespace;
-  }
+    this.get_generic_message_handler = function()
+    {
+      return window.ini && window.ini.debug && _handle_scope_message_debug || _handle_scope_message;
+    };
 
-}
+    this.register_services = function(namespace)
+    {
+      _services = namespace;
+    };
+
+    this.populate_map = function(map)
+    {
+      for (var service in map)
+      {
+        if (service == "scope")
+          continue;
+        var cmd_map = _event_map[service] = {};
+        for (var cmd_id in map[service])
+        {
+          if (map[service][cmd_id].name.slice(0, 2) == "On")
+            cmd_map[cmd_id] = "on" + map[service][cmd_id].name.slice(2);
+          else
+            cmd_map[cmd_id] = "handle" + map[service][cmd_id].name;
+        }
+      }
+    };
+
+  }).apply(ServiceBase);
+
+};