Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Unified Diff: third_party/inspector_protocol/templates/TypeBuilder_cpp.template

Issue 2523583005: Roll third_party/inspector_protocol to 4ad35c45aca9834b67ec2cb152c816ea1b7ceb48 (Closed)
Patch Set: added default implementation Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/inspector_protocol/templates/TypeBuilder_cpp.template
diff --git a/third_party/inspector_protocol/templates/TypeBuilder_cpp.template b/third_party/inspector_protocol/templates/TypeBuilder_cpp.template
index b63a0e880ddc502d68ca0be325907cf8d33750f2..23b6f5399089609af71ac4c5878aae9e171e0a62 100644
--- a/third_party/inspector_protocol/templates/TypeBuilder_cpp.template
+++ b/third_party/inspector_protocol/templates/TypeBuilder_cpp.template
@@ -47,7 +47,7 @@ const char* {{type.id}}::{{property.name | to_title_case}}Enum::{{literal | dash
{% endfor %}
{% if not (type.type == "object") or not ("properties" in type) %}{% continue %}{% endif %}
-std::unique_ptr<{{type.id}}> {{type.id}}::parse(protocol::Value* value, ErrorSupport* errors)
+std::unique_ptr<{{type.id}}> {{type.id}}::fromValue(protocol::Value* value, ErrorSupport* errors)
{
if (!value || value->type() != protocol::Value::TypeObject) {
errors->addError("object expected");
@@ -62,11 +62,11 @@ std::unique_ptr<{{type.id}}> {{type.id}}::parse(protocol::Value* value, ErrorSup
{% if property.optional %}
if ({{property.name}}Value) {
errors->setName("{{property.name}}");
- result->m_{{property.name}} = ValueConversions<{{resolve_type(property).raw_type}}>::parse({{property.name}}Value, errors);
+ result->m_{{property.name}} = ValueConversions<{{resolve_type(property).raw_type}}>::fromValue({{property.name}}Value, errors);
}
{% else %}
errors->setName("{{property.name}}");
- result->m_{{property.name}} = ValueConversions<{{resolve_type(property).raw_type}}>::parse({{property.name}}Value, errors);
+ result->m_{{property.name}} = ValueConversions<{{resolve_type(property).raw_type}}>::fromValue({{property.name}}Value, errors);
{% endif %}
{% endfor %}
errors->pop();
@@ -75,15 +75,15 @@ std::unique_ptr<{{type.id}}> {{type.id}}::parse(protocol::Value* value, ErrorSup
return result;
}
-std::unique_ptr<protocol::DictionaryValue> {{type.id}}::serialize() const
+std::unique_ptr<protocol::DictionaryValue> {{type.id}}::toValue() const
{
std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
{% for property in type.properties %}
{% if property.optional %}
if (m_{{property.name}}.isJust())
- result->setValue("{{property.name}}", ValueConversions<{{resolve_type(property).raw_type}}>::serialize(m_{{property.name}}.fromJust()));
+ result->setValue("{{property.name}}", ValueConversions<{{resolve_type(property).raw_type}}>::toValue(m_{{property.name}}.fromJust()));
{% else %}
- result->setValue("{{property.name}}", ValueConversions<{{resolve_type(property).raw_type}}>::serialize({{resolve_type(property).to_raw_type % ("m_" + property.name)}}));
+ result->setValue("{{property.name}}", ValueConversions<{{resolve_type(property).raw_type}}>::toValue({{resolve_type(property).to_raw_type % ("m_" + property.name)}}));
{% endif %}
{% endfor %}
return result;
@@ -92,13 +92,13 @@ std::unique_ptr<protocol::DictionaryValue> {{type.id}}::serialize() const
std::unique_ptr<{{type.id}}> {{type.id}}::clone() const
{
ErrorSupport errors;
- return parse(serialize().get(), &errors);
+ return fromValue(toValue().get(), &errors);
}
{% if type.exported %}
{{config.exported.string_out}} {{type.id}}::toJSONString() const
{
- String json = serialize()->toJSONString();
+ String json = toValue()->serialize();
return {{config.exported.to_string_out % "json"}};
}
@@ -109,7 +109,7 @@ std::unique_ptr<API::{{type.id}}> API::{{type.id}}::fromJSONString(const {{confi
std::unique_ptr<Value> value = StringUtil::parseJSON(json);
if (!value)
return nullptr;
- return protocol::{{domain.domain}}::{{type.id}}::parse(value.get(), &errors);
+ return protocol::{{domain.domain}}::{{type.id}}::fromValue(value.get(), &errors);
}
{% endif %}
{% endfor %}
@@ -156,20 +156,26 @@ void Frontend::{{event.name | to_method_case}}(
{%- endif %} {{parameter.name}}{%- if not loop.last -%}, {% endif -%}
{% endfor -%})
{
- std::unique_ptr<protocol::DictionaryValue> jsonMessage = DictionaryValue::create();
- jsonMessage->setString("method", "{{domain.domain}}.{{event.name}}");
- std::unique_ptr<protocol::DictionaryValue> paramsObject = DictionaryValue::create();
- {% for parameter in event.parameters %}
- {% if "optional" in parameter %}
+ if (!m_frontendChannel)
+ return;
+ {% if event.parameters %}
+ std::unique_ptr<{{event.name | to_title_case}}Notification> messageData = {{event.name | to_title_case}}Notification::{{"create" | to_method_case}}()
+ {% for parameter in event.parameters %}
+ {% if not "optional" in parameter %}
+ .{{"set" | to_method_case}}{{parameter.name | to_title_case}}({{resolve_type(parameter).to_pass_type % parameter.name}})
+ {% endif %}
+ {% endfor %}
+ .{{ "build" | to_method_case }}();
+ {% for parameter in event.parameters %}
+ {% if "optional" in parameter %}
if ({{parameter.name}}.isJust())
- paramsObject->setValue("{{parameter.name}}", ValueConversions<{{resolve_type(parameter).raw_type}}>::serialize({{parameter.name}}.fromJust()));
+ messageData->{{"set" | to_method_case}}{{parameter.name | to_title_case}}(std::move({{parameter.name}}).takeJust());
+ {% endif %}
+ {% endfor %}
+ m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("{{domain.domain}}.{{event.name}}", std::move(messageData)));
{% else %}
- paramsObject->setValue("{{parameter.name}}", ValueConversions<{{resolve_type(parameter).raw_type}}>::serialize({{resolve_type(parameter).to_raw_type % parameter.name}}));
+ m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("{{domain.domain}}.{{event.name}}"));
{% endif %}
- {% endfor %}
- jsonMessage->setObject("params", std::move(paramsObject));
- if (m_frontendChannel)
- m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString());
}
{% endfor %}
@@ -180,7 +186,7 @@ void Frontend::flush()
void Frontend::sendRawNotification(const String& notification)
{
- m_frontendChannel->sendProtocolNotification(notification);
+ m_frontendChannel->sendProtocolNotification(InternalRawNotification::create(notification));
}
// --------------------- Dispatcher.
@@ -253,9 +259,9 @@ public:
{% for parameter in command.returns %}
{% if "optional" in parameter %}
if ({{parameter.name}}.isJust())
- resultObject->setValue("{{parameter.name}}", ValueConversions<{{resolve_type(parameter).raw_type}}>::serialize({{parameter.name}}.fromJust()));
+ resultObject->setValue("{{parameter.name}}", ValueConversions<{{resolve_type(parameter).raw_type}}>::toValue({{parameter.name}}.fromJust()));
{% else %}
- resultObject->setValue("{{parameter.name}}", ValueConversions<{{resolve_type(parameter).raw_type}}>::serialize({{resolve_type(parameter).to_raw_type % parameter.name}}));
+ resultObject->setValue("{{parameter.name}}", ValueConversions<{{resolve_type(parameter).raw_type}}>::toValue({{resolve_type(parameter).to_raw_type % parameter.name}}));
{% endif %}
{% endfor %}
sendIfActive(std::move(resultObject), DispatchResponse::OK());
@@ -286,11 +292,11 @@ DispatchResponse::Status DispatcherImpl::{{command.name}}(int callId, std::uniqu
Maybe<{{resolve_type(property).raw_type}}> in_{{property.name}};
if ({{property.name}}Value) {
errors->setName("{{property.name}}");
- in_{{property.name}} = ValueConversions<{{resolve_type(property).raw_type}}>::parse({{property.name}}Value, errors);
+ in_{{property.name}} = ValueConversions<{{resolve_type(property).raw_type}}>::fromValue({{property.name}}Value, errors);
}
{% else %}
errors->setName("{{property.name}}");
- {{resolve_type(property).type}} in_{{property.name}} = ValueConversions<{{resolve_type(property).raw_type}}>::parse({{property.name}}Value, errors);
+ {{resolve_type(property).type}} in_{{property.name}} = ValueConversions<{{resolve_type(property).raw_type}}>::fromValue({{property.name}}Value, errors);
{% endif %}
{% endfor %}
errors->pop();
@@ -335,9 +341,9 @@ DispatchResponse::Status DispatcherImpl::{{command.name}}(int callId, std::uniqu
{% for parameter in command.returns %}
{% if "optional" in parameter %}
if (out_{{parameter.name}}.isJust())
- result->setValue("{{parameter.name}}", ValueConversions<{{resolve_type(parameter).raw_type}}>::serialize(out_{{parameter.name}}.fromJust()));
+ result->setValue("{{parameter.name}}", ValueConversions<{{resolve_type(parameter).raw_type}}>::toValue(out_{{parameter.name}}.fromJust()));
{% else %}
- result->setValue("{{parameter.name}}", ValueConversions<{{resolve_type(parameter).raw_type}}>::serialize({{resolve_type(parameter).to_raw_type % ("out_" + parameter.name)}}));
+ result->setValue("{{parameter.name}}", ValueConversions<{{resolve_type(parameter).raw_type}}>::toValue({{resolve_type(parameter).to_raw_type % ("out_" + parameter.name)}}));
{% endif %}
{% endfor %}
}

Powered by Google App Engine
This is Rietveld 408576698