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..ef53003acc38b14eaff005eebdf8e6cab45c3cc0 100644 |
--- a/third_party/inspector_protocol/templates/TypeBuilder_cpp.template |
+++ b/third_party/inspector_protocol/templates/TypeBuilder_cpp.template |
@@ -11,6 +11,28 @@ |
{% for namespace in config.protocol.namespace %} |
namespace {{namespace}} { |
{% endfor %} |
+ |
+namespace { |
+ |
+class RawNotification : public Serializable { |
dgozman
2016/11/22 22:36:00
Move this to DispatcherBase.h
kozy
2016/11/22 23:01:24
Done.
|
+public: |
+ explicit RawNotification(const String& notification) |
+ : m_notification(notification) |
+ { |
+ } |
+ ~RawNotification() override {} |
+ |
+ String serialize() override |
+ { |
+ return m_notification; |
+ } |
+ |
+private: |
+ String m_notification; |
+}; |
+ |
+} // namespace |
+ |
namespace {{domain.domain}} { |
// ------------- Enum values from types. |
@@ -47,7 +69,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 +84,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,7 +97,7 @@ 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 %} |
@@ -92,13 +114,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()->toJSONString(); |
return {{config.exported.to_string_out % "json"}}; |
} |
@@ -109,7 +131,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 +178,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 +208,7 @@ void Frontend::flush() |
void Frontend::sendRawNotification(const String& notification) |
{ |
- m_frontendChannel->sendProtocolNotification(notification); |
+ m_frontendChannel->sendProtocolNotification(std::unique_ptr<Serializable>(new RawNotification(notification))); |
} |
// --------------------- Dispatcher. |
@@ -286,11 +314,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(); |