Index: tools/json_schema_compiler/cc_generator.py |
diff --git a/tools/json_schema_compiler/cc_generator.py b/tools/json_schema_compiler/cc_generator.py |
index 8cea17b588af55ed93f5df205ca5076d9bf6080d..5ca02419eed0b3081a738c93cc0d53924d9ccb45 100644 |
--- a/tools/json_schema_compiler/cc_generator.py |
+++ b/tools/json_schema_compiler/cc_generator.py |
@@ -88,7 +88,7 @@ class CCGenerator(object): |
) |
for event in self._namespace.events.values(): |
(c.Concat(self._GenerateCreateCallbackArguments( |
- cpp_util.Classname(event.name), event)) |
+ cpp_util.Classname(event.name), event, True)) |
not at google - send to devlin
2012/07/25 23:28:41
Boolean arguments should be avoided because they m
mitchellwrosen
2012/07/26 02:01:17
Done.
|
.Append() |
) |
(c.Concat(self._cpp_type_generator.GetNamespaceEnd()) |
@@ -291,7 +291,7 @@ class CCGenerator(object): |
# Results::Create function |
if function.callback: |
c.Concat(self._GenerateCreateCallbackArguments( |
- "%s::Results" % cpp_namespace, function.callback)) |
+ "%s::Results" % cpp_namespace, function.callback, False)) |
not at google - send to devlin
2012/07/25 23:28:41
Named arguments also let you specify a default val
mitchellwrosen
2012/07/26 02:01:17
Done.
|
c.Substitute({'cpp_namespace': cpp_namespace}) |
@@ -679,7 +679,10 @@ class CCGenerator(object): |
) |
return c |
- def _GenerateCreateCallbackArguments(self, function_scope, callback): |
+ def _GenerateCreateCallbackArguments(self, |
+ function_scope, |
+ callback, |
+ is_event): |
not at google - send to devlin
2012/07/25 23:28:41
prefer generate_to_json over is_event.
Also, like
mitchellwrosen
2012/07/26 02:01:17
Done.
|
"""Generate all functions to create Value parameters for a callback. |
E.g for function "Bar", generate Bar::Results::Create |
@@ -688,6 +691,8 @@ class CCGenerator(object): |
function_scope: the function scope path, e.g. Foo::Bar for the function |
Foo::Bar::Baz(). |
callback: the Function object we are creating callback arguments for. |
+ is_event: if the Function object is an Event or not. A ToJson method is |
+ generated for events. |
not at google - send to devlin
2012/07/25 23:28:41
need to update comment.
mitchellwrosen
2012/07/26 02:01:17
Done.
|
""" |
c = Code() |
params = callback.params |
@@ -714,9 +719,22 @@ class CCGenerator(object): |
c.Append('return create_results.Pass();') |
c.Eblock('}') |
+ if is_event: |
+ c.Append() |
+ (c.Sblock('std::string %(function_scope)s::' |
+ 'ToJson(%(declaration_list)s) {') |
+ .Append('scoped_ptr<base::ListValue> create_results = ' |
+ 'Create(%(param_list)s);') |
+ .Append('std::string json;') |
+ .Append('base::JSONWriter::Write(create_results.get(), &json);') |
+ .Append('return json;') |
+ ) |
+ c.Eblock('}') |
+ |
c.Substitute({ |
'function_scope': function_scope, |
- 'declaration_list': ', '.join(declaration_list) |
+ 'declaration_list': ', '.join(declaration_list), |
+ 'param_list': ', '.join([param.unix_name for param in param_list]) |
}) |
return c |