OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 Google Inc. All rights reserved. | 2 # Copyright (c) 2011 Google Inc. All rights reserved. |
3 # Copyright (c) 2012 Intel Corporation. All rights reserved. | 3 # Copyright (c) 2012 Intel Corporation. All rights reserved. |
4 # | 4 # |
5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
7 # met: | 7 # met: |
8 # | 8 # |
9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
(...skipping 1884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1895 def process_command(json_command, domain_name, agent_field_name, agent_inter
face_name): | 1895 def process_command(json_command, domain_name, agent_field_name, agent_inter
face_name): |
1896 if (("handlers" in json_command) and (not ("renderer" in json_command["h
andlers"]))): | 1896 if (("handlers" in json_command) and (not ("renderer" in json_command["h
andlers"]))): |
1897 return | 1897 return |
1898 | 1898 |
1899 json_command_name = json_command["name"] | 1899 json_command_name = json_command["name"] |
1900 | 1900 |
1901 cmd_enum_name = "k%s_%sCmd" % (domain_name, json_command["name"]) | 1901 cmd_enum_name = "k%s_%sCmd" % (domain_name, json_command["name"]) |
1902 | 1902 |
1903 Generator.method_name_enum_list.append(" %s," % cmd_enum_name) | 1903 Generator.method_name_enum_list.append(" %s," % cmd_enum_name) |
1904 Generator.method_handler_list.append(" &InspectorBackendDispa
tcherImpl::%s_%s," % (domain_name, json_command_name)) | 1904 Generator.method_handler_list.append(" &InspectorBackendDispa
tcherImpl::%s_%s," % (domain_name, json_command_name)) |
1905 Generator.backend_method_declaration_list.append(" void %s_%s(long ca
llId, JSONObject* requestMessageObject);" % (domain_name, json_command_name)) | 1905 Generator.backend_method_declaration_list.append(" void %s_%s(long ca
llId, JSONObject* requestMessageObject, JSONArray* protocolErrors);" % (domain_n
ame, json_command_name)) |
1906 | 1906 |
1907 backend_agent_interface_list = [] if "redirect" in json_command else Gen
erator.backend_agent_interface_list | 1907 backend_agent_interface_list = [] if "redirect" in json_command else Gen
erator.backend_agent_interface_list |
1908 | 1908 |
1909 ad_hoc_type_output = [] | 1909 ad_hoc_type_output = [] |
1910 backend_agent_interface_list.append(ad_hoc_type_output) | 1910 backend_agent_interface_list.append(ad_hoc_type_output) |
1911 ad_hoc_type_writer = Writer(ad_hoc_type_output, " ") | 1911 ad_hoc_type_writer = Writer(ad_hoc_type_output, " ") |
1912 | 1912 |
1913 backend_agent_interface_list.append(" virtual void %s(ErrorString
*" % json_command_name) | 1913 backend_agent_interface_list.append(" virtual void %s(ErrorString
*" % json_command_name) |
1914 | 1914 |
1915 method_in_code = "" | 1915 method_in_code = "" |
1916 method_out_code = "" | 1916 method_out_code = "" |
| 1917 result_object_declaration = "" |
1917 agent_call_param_list = [] | 1918 agent_call_param_list = [] |
| 1919 send_response_call_params_list = ["error"] |
1918 request_message_param = "" | 1920 request_message_param = "" |
1919 normal_response_cook_text = "" | 1921 normal_response_cook_text = "" |
1920 error_response_cook_text = "" | |
1921 error_type_binding = None | 1922 error_type_binding = None |
1922 if "error" in json_command: | 1923 if "error" in json_command: |
1923 json_error = json_command["error"] | 1924 json_error = json_command["error"] |
1924 error_type_binding = Generator.resolve_type_and_generate_ad_hoc(json
_error, json_command_name + "Error", json_command_name, domain_name, ad_hoc_type
_writer, agent_interface_name + "::") | 1925 error_type_binding = Generator.resolve_type_and_generate_ad_hoc(json
_error, json_command_name + "Error", json_command_name, domain_name, ad_hoc_type
_writer, agent_interface_name + "::") |
1925 error_type_model = error_type_binding.get_type_model().get_optional(
) | 1926 error_type_model = error_type_binding.get_type_model().get_optional(
) |
1926 error_annotated_type = error_type_model.get_command_return_pass_mode
l().get_output_parameter_type() | 1927 error_annotated_type = error_type_model.get_command_return_pass_mode
l().get_output_parameter_type() |
1927 agent_call_param_list.append(", %serrorData" % error_type_model.get_
command_return_pass_model().get_output_argument_prefix()) | 1928 agent_call_param_list.append(", %serrorData" % error_type_model.get_
command_return_pass_model().get_output_argument_prefix()) |
1928 backend_agent_interface_list.append(", %s errorData" % error_annotat
ed_type) | 1929 backend_agent_interface_list.append(", %s errorData" % error_annotat
ed_type) |
1929 method_in_code += " %s errorData;\n" % error_type_model.get_comma
nd_return_pass_model().get_return_var_type() | 1930 method_in_code += " %s errorData;\n" % error_type_model.get_comma
nd_return_pass_model().get_return_var_type() |
1930 | 1931 send_response_call_params_list.append("errorData") |
1931 setter_argument = error_type_model.get_command_return_pass_model().g
et_output_to_raw_expression() % "errorData" | |
1932 if error_type_binding.get_setter_value_expression_pattern(): | |
1933 setter_argument = error_type_binding.get_setter_value_expression
_pattern() % setter_argument | |
1934 error_assigment_value = error_type_binding.reduce_to_raw_type().get_
constructor_pattern() % setter_argument | |
1935 | |
1936 cook = " resultErrorData = %s;\n" % error_assigment_value | |
1937 | |
1938 error_condition_pattern = error_type_model.get_command_return_pass_m
odel().get_set_return_condition() | |
1939 cook = (" if (%s)\n " % (error_condition_pattern % "er
rorData")) + cook | |
1940 error_response_cook_text = " if (error.length()) {\n" + cook
+ " }\n" | |
1941 | 1932 |
1942 if "parameters" in json_command: | 1933 if "parameters" in json_command: |
1943 json_params = json_command["parameters"] | 1934 json_params = json_command["parameters"] |
1944 request_message_param = " requestMessageObject" | 1935 request_message_param = " requestMessageObject" |
1945 | 1936 |
1946 if json_params: | 1937 if json_params: |
1947 method_in_code += Templates.param_container_access_code | 1938 method_in_code += Templates.param_container_access_code |
1948 | 1939 |
1949 for json_parameter in json_params: | 1940 for json_parameter in json_params: |
1950 json_param_name = json_parameter["name"] | 1941 json_param_name = json_parameter["name"] |
1951 param_raw_type = resolve_param_raw_type(json_parameter, domain_n
ame) | 1942 param_raw_type = resolve_param_raw_type(json_parameter, domain_n
ame) |
1952 | 1943 |
1953 getter_name = param_raw_type.get_getter_name() | 1944 getter_name = param_raw_type.get_getter_name() |
1954 | 1945 |
1955 optional = json_parameter.get("optional") | 1946 optional = json_parameter.get("optional") |
1956 | 1947 |
1957 non_optional_type_model = param_raw_type.get_raw_type_model() | 1948 non_optional_type_model = param_raw_type.get_raw_type_model() |
1958 if optional: | 1949 if optional: |
1959 type_model = non_optional_type_model.get_optional() | 1950 type_model = non_optional_type_model.get_optional() |
1960 else: | 1951 else: |
1961 type_model = non_optional_type_model | 1952 type_model = non_optional_type_model |
1962 | 1953 |
1963 if optional: | 1954 if optional: |
1964 code = (" bool %s_valueFound = false;\n" | 1955 code = (" bool %s_valueFound = false;\n" |
1965 " %s in_%s = get%s(paramsContainerPtr, \"%s\", &%
s_valueFound, protocolErrorsPtr);\n" % | 1956 " %s in_%s = get%s(paramsContainerPtr, \"%s\", &%
s_valueFound, protocolErrors);\n" % |
1966 (json_param_name, non_optional_type_model.get_command
_return_pass_model().get_return_var_type(), json_param_name, getter_name, json_p
aram_name, json_param_name)) | 1957 (json_param_name, non_optional_type_model.get_command
_return_pass_model().get_return_var_type(), json_param_name, getter_name, json_p
aram_name, json_param_name)) |
1967 param = ", %s_valueFound ? &in_%s : 0" % (json_param_name, j
son_param_name) | 1958 param = ", %s_valueFound ? &in_%s : 0" % (json_param_name, j
son_param_name) |
1968 # FIXME: pass optional refptr-values as PassRefPtr | 1959 # FIXME: pass optional refptr-values as PassRefPtr |
1969 formal_param_type_pattern = "const %s*" | 1960 formal_param_type_pattern = "const %s*" |
1970 else: | 1961 else: |
1971 code = (" %s in_%s = get%s(paramsContainerPtr, \"%s\", 0,
protocolErrorsPtr);\n" % | 1962 code = (" %s in_%s = get%s(paramsContainerPtr, \"%s\", 0,
protocolErrors);\n" % |
1972 (non_optional_type_model.get_command_return_pass_mod
el().get_return_var_type(), json_param_name, getter_name, json_param_name)) | 1963 (non_optional_type_model.get_command_return_pass_mod
el().get_return_var_type(), json_param_name, getter_name, json_param_name)) |
1973 param = ", in_%s" % json_param_name | 1964 param = ", in_%s" % json_param_name |
1974 # FIXME: pass not-optional refptr-values as NonNullPassRefPt
r | 1965 # FIXME: pass not-optional refptr-values as NonNullPassRefPt
r |
1975 if param_raw_type.is_heavy_value(): | 1966 if param_raw_type.is_heavy_value(): |
1976 formal_param_type_pattern = "const %s&" | 1967 formal_param_type_pattern = "const %s&" |
1977 else: | 1968 else: |
1978 formal_param_type_pattern = "%s" | 1969 formal_param_type_pattern = "%s" |
1979 | 1970 |
1980 method_in_code += code | 1971 method_in_code += code |
1981 agent_call_param_list.append(param) | 1972 agent_call_param_list.append(param) |
(...skipping 26 matching lines...) Expand all Loading... |
2008 | 1999 |
2009 assigment_value = error_type_model.get_event_setter_expression_p
attern() % "errorData" | 2000 assigment_value = error_type_model.get_event_setter_expression_p
attern() % "errorData" |
2010 assigment_value = error_type_binding.reduce_to_raw_type().get_co
nstructor_pattern() % assigment_value | 2001 assigment_value = error_type_binding.reduce_to_raw_type().get_co
nstructor_pattern() % assigment_value |
2011 | 2002 |
2012 Generator.backend_method_implementation_list.append(Templates.ca
llback_failure_method.substitute(None, | 2003 Generator.backend_method_implementation_list.append(Templates.ca
llback_failure_method.substitute(None, |
2013 agentName=agent_interface_name, | 2004 agentName=agent_interface_name, |
2014 callbackName=callback_name, | 2005 callbackName=callback_name, |
2015 parameter=annotated_type + " errorData", | 2006 parameter=annotated_type + " errorData", |
2016 argument=assigment_value)) | 2007 argument=assigment_value)) |
2017 | 2008 |
2018 | |
2019 | |
2020 ad_hoc_type_output.append(callback_output) | 2009 ad_hoc_type_output.append(callback_output) |
2021 | 2010 |
2022 method_out_code += " RefPtr<" + agent_interface_name + "::" + cal
lback_name + "> callback = adoptRef(new " + agent_interface_name + "::" + callba
ck_name + "(this, callId));\n" | 2011 method_out_code += " RefPtr<" + agent_interface_name + "::" + cal
lback_name + "> callback = adoptRef(new " + agent_interface_name + "::" + callba
ck_name + "(this, callId));\n" |
2023 agent_call_param_list.append(", callback") | 2012 agent_call_param_list.append(", callback") |
2024 normal_response_cook_text += " if (!error.length()) \n" | 2013 normal_response_cook_text += " if (!error.length()) \n" |
2025 normal_response_cook_text += " return;\n" | 2014 normal_response_cook_text += " return;\n" |
2026 normal_response_cook_text += " callback->disable();\n" | 2015 normal_response_cook_text += " callback->disable();\n" |
2027 backend_agent_interface_list.append(", PassRefPtr<%s> callback" % ca
llback_name) | 2016 backend_agent_interface_list.append(", PassRefPtr<%s> callback" % ca
llback_name) |
2028 else: | 2017 else: |
2029 if "returns" in json_command: | 2018 if "returns" in json_command: |
2030 method_out_code += "\n" | 2019 method_out_code += "\n" |
| 2020 result_object_declaration = "\n RefPtr<JSONObject> result = J
SONObject::create();" |
| 2021 send_response_call_params_list.append("result") |
2031 response_cook_list = [] | 2022 response_cook_list = [] |
2032 for json_return in json_command["returns"]: | 2023 for json_return in json_command["returns"]: |
2033 | 2024 |
2034 json_return_name = json_return["name"] | 2025 json_return_name = json_return["name"] |
2035 | 2026 |
2036 optional = bool(json_return.get("optional")) | 2027 optional = bool(json_return.get("optional")) |
2037 | 2028 |
2038 return_type_binding = Generator.resolve_param_type_and_gener
ate_ad_hoc(json_return, json_command_name, domain_name, ad_hoc_type_writer, agen
t_interface_name + "::") | 2029 return_type_binding = Generator.resolve_param_type_and_gener
ate_ad_hoc(json_return, json_command_name, domain_name, ad_hoc_type_writer, agen
t_interface_name + "::") |
2039 | 2030 |
2040 raw_type = return_type_binding.reduce_to_raw_type() | 2031 raw_type = return_type_binding.reduce_to_raw_type() |
2041 setter_type = raw_type.get_setter_name() | 2032 setter_type = raw_type.get_setter_name() |
2042 initializer = raw_type.get_c_initializer() | 2033 initializer = raw_type.get_c_initializer() |
2043 | 2034 |
2044 type_model = return_type_binding.get_type_model() | 2035 type_model = return_type_binding.get_type_model() |
2045 if optional: | 2036 if optional: |
2046 type_model = type_model.get_optional() | 2037 type_model = type_model.get_optional() |
2047 | 2038 |
2048 code = " %s out_%s;\n" % (type_model.get_command_return_p
ass_model().get_return_var_type(), json_return_name) | 2039 code = " %s out_%s;\n" % (type_model.get_command_return_p
ass_model().get_return_var_type(), json_return_name) |
2049 param = ", %sout_%s" % (type_model.get_command_return_pass_m
odel().get_output_argument_prefix(), json_return_name) | 2040 param = ", %sout_%s" % (type_model.get_command_return_pass_m
odel().get_output_argument_prefix(), json_return_name) |
2050 var_name = "out_%s" % json_return_name | 2041 var_name = "out_%s" % json_return_name |
2051 setter_argument = type_model.get_command_return_pass_model()
.get_output_to_raw_expression() % var_name | 2042 setter_argument = type_model.get_command_return_pass_model()
.get_output_to_raw_expression() % var_name |
2052 if return_type_binding.get_setter_value_expression_pattern()
: | 2043 if return_type_binding.get_setter_value_expression_pattern()
: |
2053 setter_argument = return_type_binding.get_setter_value_e
xpression_pattern() % setter_argument | 2044 setter_argument = return_type_binding.get_setter_value_e
xpression_pattern() % setter_argument |
2054 | 2045 |
2055 cook = " result->set%s(\"%s\", %s);\n" % (setter_
type, json_return_name, | 2046 cook = " result->set%s(\"%s\", %s);\n" % (setter_type
, json_return_name, |
2056 setter_
argument) | 2047 setter_
argument) |
2057 | 2048 |
2058 set_condition_pattern = type_model.get_command_return_pass_m
odel().get_set_return_condition() | 2049 set_condition_pattern = type_model.get_command_return_pass_m
odel().get_set_return_condition() |
2059 if set_condition_pattern: | 2050 if set_condition_pattern: |
2060 cook = (" if (%s)\n " % (set_condition_pat
tern % var_name)) + cook | 2051 cook = (" if (%s)\n " % (set_condition_pattern
% var_name)) + cook |
2061 annotated_type = type_model.get_command_return_pass_model().
get_output_parameter_type() | 2052 annotated_type = type_model.get_command_return_pass_model().
get_output_parameter_type() |
2062 | 2053 |
2063 param_name = var_name | 2054 param_name = var_name |
2064 if optional: | 2055 if optional: |
2065 param_name = "opt_" + param_name | 2056 param_name = "opt_" + param_name |
2066 | 2057 |
2067 backend_agent_interface_list.append(", %s %s" % (annotated_t
ype, param_name)) | 2058 backend_agent_interface_list.append(", %s %s" % (annotated_t
ype, param_name)) |
2068 response_cook_list.append(cook) | 2059 response_cook_list.append(cook) |
2069 | 2060 |
2070 method_out_code += code | 2061 method_out_code += code |
2071 agent_call_param_list.append(param) | 2062 agent_call_param_list.append(param) |
2072 | 2063 |
2073 normal_response_cook_text += "".join(response_cook_list) | 2064 normal_response_cook_text += "".join(response_cook_list) |
2074 | 2065 |
2075 if len(normal_response_cook_text) != 0: | 2066 if len(normal_response_cook_text) != 0: |
2076 normal_response_cook_text = " if (!error.length()) {\
n" + normal_response_cook_text + " }" | 2067 normal_response_cook_text = " if (!error.length()) {\n" +
normal_response_cook_text + " }" |
2077 | 2068 |
2078 # Redirect to another agent's implementation. | 2069 # Redirect to another agent's implementation. |
2079 agent_field = "m_" + agent_field_name | 2070 agent_field = "m_" + agent_field_name |
2080 if "redirect" in json_command: | 2071 if "redirect" in json_command: |
2081 domain_fixes = DomainNameFixes.get_fixed_data(json_command.get("redi
rect")) | 2072 domain_fixes = DomainNameFixes.get_fixed_data(json_command.get("redi
rect")) |
2082 agent_field = "m_" + domain_fixes.agent_field_name | 2073 agent_field = "m_" + domain_fixes.agent_field_name |
2083 | 2074 |
2084 Generator.backend_method_implementation_list.append(Templates.backend_me
thod.substitute(None, | 2075 Generator.backend_method_implementation_list.append(Templates.backend_me
thod.substitute(None, |
2085 domainName=domain_name, methodName=json_command_name, | 2076 domainName=domain_name, methodName=json_command_name, |
2086 agentField=agent_field, | 2077 agentField=agent_field, |
2087 methodInCode=method_in_code, | 2078 methodCode="".join([method_in_code, method_out_code, result_object_d
eclaration]), |
2088 methodOutCode=method_out_code, | |
2089 agentCallParams="".join(agent_call_param_list), | 2079 agentCallParams="".join(agent_call_param_list), |
2090 requestMessageObject=request_message_param, | 2080 requestMessageObject=request_message_param, |
2091 responseCook=normal_response_cook_text, | 2081 responseCook=normal_response_cook_text, |
2092 errorCook=error_response_cook_text, | 2082 sendResponseCallParams=", ".join(send_response_call_params_list), |
2093 commandNameIndex=cmd_enum_name)) | 2083 commandNameIndex=cmd_enum_name)) |
2094 declaration_command_name = "%s.%s\\0" % (domain_name, json_command_name) | 2084 declaration_command_name = "%s.%s\\0" % (domain_name, json_command_name) |
2095 Generator.backend_method_name_declaration_list.append(" \"%s\"" % dec
laration_command_name) | 2085 Generator.backend_method_name_declaration_list.append(" \"%s\"" % dec
laration_command_name) |
2096 Generator.backend_method_name_declaration_index_list.append(" %d," %
Generator.backend_method_name_declaration_current_index) | 2086 Generator.backend_method_name_declaration_index_list.append(" %d," %
Generator.backend_method_name_declaration_current_index) |
2097 Generator.backend_method_name_declaration_current_index += len(declarati
on_command_name) - 1 | 2087 Generator.backend_method_name_declaration_current_index += len(declarati
on_command_name) - 1 |
2098 | 2088 |
2099 backend_agent_interface_list.append(") = 0;\n") | 2089 backend_agent_interface_list.append(") = 0;\n") |
2100 | 2090 |
2101 class CallbackMethodStructTemplate: | 2091 class CallbackMethodStructTemplate: |
2102 @staticmethod | 2092 @staticmethod |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2363 validatorIfdefName=VALIDATOR_IFDEF_NAME)) | 2353 validatorIfdefName=VALIDATOR_IFDEF_NAME)) |
2364 | 2354 |
2365 backend_h_file.close() | 2355 backend_h_file.close() |
2366 backend_cpp_file.close() | 2356 backend_cpp_file.close() |
2367 | 2357 |
2368 frontend_h_file.close() | 2358 frontend_h_file.close() |
2369 frontend_cpp_file.close() | 2359 frontend_cpp_file.close() |
2370 | 2360 |
2371 typebuilder_h_file.close() | 2361 typebuilder_h_file.close() |
2372 typebuilder_cpp_file.close() | 2362 typebuilder_cpp_file.close() |
OLD | NEW |