Chromium Code Reviews| Index: tools/json_schema_compiler/h_generator.py |
| diff --git a/tools/json_schema_compiler/h_generator.py b/tools/json_schema_compiler/h_generator.py |
| index 5e7e7003a36629161c365e2d5ed0df237e8ace39..7cd5b45d7746ba5561fb93afe7b66b24e040a3ff 100644 |
| --- a/tools/json_schema_compiler/h_generator.py |
| +++ b/tools/json_schema_compiler/h_generator.py |
| @@ -92,6 +92,16 @@ class HGenerator(object): |
| (c.Concat(self._GenerateFunction(function)) |
| .Append() |
| ) |
| + if self._namespace.events: |
| + (c.Append('//') |
| + .Append('// Events') |
| + .Append('//') |
| + .Append() |
| + ) |
| + for event in self._namespace.events.values(): |
| + (c.Concat(self._GenerateEvent(event)) |
| + .Append() |
| + ) |
| (c.Concat(self._cpp_type_generator.GetNamespaceEnd()) |
| .Concat(self._cpp_type_generator.GetRootNamespaceEnd()) |
| .Append() |
| @@ -212,8 +222,17 @@ class HGenerator(object): |
| c.Substitute({'classname': classname}) |
| return c |
| + def _GenerateEvent(self, event): |
| + """Generates the namespaces for an event. |
| + """ |
| + c = Code() |
| + c.Sblock('namespace %s {' % cpp_util.Classname(event.name)) |
| + c.Concat(self._GenerateFromClientFunction(event)) |
| + c.Eblock('};') |
| + return c |
| + |
| def _GenerateFunction(self, function): |
| - """Generates the structs for a function. |
| + """Generates the namespaces and structs for a function. |
| """ |
| c = Code() |
| (c.Sblock('namespace %s {' % cpp_util.Classname(function.name)) |
| @@ -221,7 +240,7 @@ class HGenerator(object): |
| .Append() |
| ) |
| if function.callback: |
| - (c.Concat(self._GenerateFunctionResult(function)) |
| + (c.Concat(self._GenerateFunctionResult(function.callback)) |
| .Append() |
| ) |
| c.Eblock('};') |
| @@ -229,7 +248,7 @@ class HGenerator(object): |
| return c |
| def _GenerateFunctionParams(self, function): |
| - """Generates the struct for passing parameters into a function. |
| + """Generates the struct for passing parameters from JSON to a function. |
| """ |
| c = Code() |
| @@ -274,17 +293,22 @@ class HGenerator(object): |
| enum_name, |
| prop, |
| prop.enum_values)) |
| - c.Append('static scoped_ptr<Value> CreateEnumValue(%s %s);' % |
| - (enum_name, prop.unix_name)) |
| + # If the property is from the UI then we're in a struct so this function |
| + # should be static. If it's from the client, then we're just in a |
| + # namespace so we can't have the static keyword. |
| + if prop.from_json: |
|
Matt Tytel
2012/06/29 23:06:40
On alternative to this is to define this function
not at google - send to devlin
2012/07/03 14:21:39
Don't follow?
This approach is fine I think. I'd
Matt Tytel
2012/07/11 02:08:50
If we define CreateEnumValue here in the header fi
|
| + c.Append('static scoped_ptr<Value> CreateEnumValue(%s %s);' % |
| + (enum_name, prop.unix_name)) |
| + else: |
| + c.Append('scoped_ptr<Value> CreateEnumValue(%s %s);' % |
| + (enum_name, prop.unix_name)) |
|
not at google - send to devlin
2012/07/03 14:21:39
Clean this up a bit:
create_enum_value = 'scoped_
Matt Tytel
2012/07/11 02:08:50
Done.
|
| return c |
| - def _GenerateFunctionResult(self, function): |
| - """Generates functions for passing a function's result back. |
| + def _GenerateFromClientFunction(self, function): |
|
not at google - send to devlin
2012/07/03 14:21:39
Same comments in here as in cc_generator.
Also: c
Matt Tytel
2012/07/11 02:08:50
Done.
|
| + """Generates functions for passing paramaters to a callback. |
| """ |
| c = Code() |
| - |
| - c.Sblock('namespace Result {') |
| - params = function.callback.params |
| + params = function.params |
| if not params: |
| c.Append('Value* Create();') |
| else: |
| @@ -298,11 +322,20 @@ class HGenerator(object): |
| if param.description: |
| c.Comment(param.description) |
| if param.type_ == PropertyType.ANY: |
| - c.Comment("Value* Result::Create(Value*) not generated " |
| + c.Comment("Value* Create(Value*) not generated " |
| "because it's redundant.") |
| continue |
| c.Append('Value* Create(const %s);' % cpp_util.GetParameterDeclaration( |
| param, self._cpp_type_generator.GetType(param))) |
| + |
| + return c |
| + |
| + def _GenerateFunctionResult(self, callback): |
| + """Generates namespace for passing a function's result back. |
| + """ |
| + c = Code() |
| + c.Sblock('namespace Result {') |
| + c.Concat(self._GenerateFromClientFunction(callback)) |
| c.Eblock('};') |
| return c |