Commits

Christian Krebs committed 3212f1e

Dynamic creation of the service interfaces with the message maps.

  • Participants
  • Parent commits c797bd5

Comments (0)

Files changed (5)

 from mako.lookup import TemplateLookup
 
 LIB_DIR = "lib"
+DOC_DIR = "doc"
 DOC_ROOT_URL = "http://dragonfly.opera.com/app/scope-interface/"
 
 class Javascript(object):
     version = '_'.join(service.options["version"].value.split('.')[:2])
     service_name = dashed_name(service.name, dash="_")
     fname = "%s_%s.js" % (service_name, version)
-    short_fpath = os.path.join(LIB_DIR, fname)
+    short_fpath = os.path.join(service_name == "scope" and LIB_DIR or DOC_DIR, fname)
     fpath = os.path.join(template_env.out_dir, short_fpath)
     template = template_env.lookup.get_template("js-service-implementation.mako")
     text = template.render_unicode(
         javascript.up2date_count += 1
 
 def generate_file(services, lookup, template_name, create_test_framework=False,
-            console_logger_tutorial=False, lib_dir="", language_context='js'):
+            console_logger_tutorial=False, lib_dir="", doc_dir="", language_context='js'):
     from hob import proto
     return lookup.get_template(template_name).render_unicode(
         services=services,
         generate_field_consts=generate_field_consts,
         const_id=const_id,
         lib_dir=lib_dir,
+        doc_dir=doc_dir,
         language_context=language_context,
         proto=proto,
         )
     tasks = [generate_service_implementation]
     if not os.path.exists(out_dir):
         os.makedirs(out_dir)
-    if not os.path.exists(os.path.join(out_dir, LIB_DIR)):
-        os.makedirs(os.path.join(out_dir, LIB_DIR))
+    for repo in [LIB_DIR, DOC_DIR]:
+        if not os.path.exists(os.path.join(out_dir, repo)):
+            os.makedirs(os.path.join(out_dir, repo))
     template_env = TemplateEnv(lookup, out_dir, js_test_framework, console_logger_tutorial)
 
     for path in iterProtoFiles(target.selectServiceFiles(args)):
                     create_test_framework=js_test_framework,
                     console_logger_tutorial=console_logger_tutorial,
                     lib_dir=LIB_DIR,
+                    doc_dir=DOC_DIR,
                     language_context='js',
                     )
         short_path = os.path.join(rep, file_name)

templates/js/js-build_application.mako

       function(map)
       {
         window.message_maps = map;
-        build_and_enable_services(service_descriptions);
+        build_and_enable_services(service_descriptions, map);
         window.test_framework.rebuild_last_state();
       }, 
       function(error)
    * This callback is invoked when host info is received from the debuggee.
    *
    */
-  var build_and_enable_services = function(service_descriptions)
+  var build_and_enable_services = function(service_descriptions, map)
   {
     var 
     service_name = '',
       class_name = window.app.helpers.dash_to_class_name(service_name);
       if (service_name != "scope")
       {
-        var
-        match_version = _find_compatible_version(version, window.app.builders[class_name]),
-        builder = window.app.builders[class_name] && window.app.builders[class_name][match_version];
-        if (builder) 
+        if (window.services[service_name] && 
+          window.services[service_name].create_and_expose_interface(version, map[service_name]))
         {
-          builder(service);
+          var
+          match_version = _find_compatible_version(version, window.app.builders[class_name]),
+          builder = window.app.builders[class_name] && window.app.builders[class_name][match_version];
+          if (builder) 
+          {
+            builder(service);
+          }
         }
       }
     }
 % for service in services:
   % if service.name == "Scope":
   var namespace = cls.${service.name} && cls.${service.name}["${service.options["version"].value}"];
-  window.app.helpers.implement_service(namespace);
+  namespace.Service.apply(window.services.scope.constructor.prototype);
+  window.services.scope.is_implemented = true;
   window.services.scope.set_host_info_callback(on_host_info_callback);
   window.services.scope.set_services_enabled_callback(on_services_enabled);
   % endif
 window.app.builders.${service.name}["${version}"] = function(service)
 {
   var namespace = cls.${service.name} && cls.${service.name}["${version}"];
-  window.app.helpers.implement_service(namespace);
     % if create_test_framework:
       % if service.name == "EcmascriptDebugger":
   window.runtimes = new namespace.Runtimes();
 
 window.app.helpers = {};
 
-window.app.helpers.implement_service = function(namespace)
-{
-  if(namespace && namespace.Service && window.services[namespace.name])
-  {
-    namespace.Service.apply(window.services[namespace.name].constructor.prototype);
-    window.services[namespace.name].is_implemented = true;
-  }
-}
-
 window.app.helpers.dash_to_class_name = function(name)
 {
   for ( var cur = '', i = 0, ret = '', do_upper = true; cur = name[i]; i++)

templates/js/js-client-html.mako

 % endif
 % for service in services:
 <% version = '_'.join(service.options["version"].value.split('.')[:2]) %>\
+  % if service.name == "Scope":
   <script src="${lib_dir}/${dashed_name(service.name, dash='_')}_${version}.js"></script>
+  % endif
 % endfor
 </head>
 <body>

templates/js/js-service-base.mako

   this.on_quit = function(){};
   this.is_implemented = false;
 
+  this.create_and_expose_interface = function(version, map)
+  {
+    if (map)
+    {
+      this.version = version;
+      for (var cmd_id in map)
+      {
+        this._expose_method(parseInt(cmd_id), map[cmd_id].name);
+      };
+      this.is_implemented = true;
+      return true;
+    }
+    return false;
+  };
+
+  this._expose_method = function(id, name)
+  {
+    if (name.slice(0, 2) == 'On')
+    {
+      this['on' + name.slice(2)] = function(status, message){};
+    }
+    else
+    {
+      this['handle' + name] = function(status, message){};
+      this['request' + name] = function(tag, message)
+      {
+        opera.scopeTransmit(this.name, message || [], id, tag || 0);
+      };
+    }
+  };
+
   var _services = null;
   var _event_map = {};
 % for service in services:

templates/js/js-windows.mako

     if(this._debug_context)
     {
       this._window_filter = [1, [this._debug_context]];
-      services['window-manager'].requestModifyFilter(0, this._window_filter)
+      var tag = window.tagManager.set_callback(this, this.handleModifyFilter);
+      services['window-manager'].requestModifyFilter(tag, this._window_filter)
+    }
+  }
+
+  this.handleModifyFilter = function(status, message)
+  {
+    if(status == 0)
+    {
+      for( var service in services )
+      {
+        if(services[service].is_implemented)
+        {
+          services[service].post('window-filter-change', {filter: this._window_filter});
+          services[service].on_window_filter_change(this._window_filter);
+        }
+      }
+    }
+    else
+    {
+      // TODO
     }
   }