def generate_messages_header(file): receiver = parser.parse(file) header_guard = messages_header_filename(receiver).replace('.', '_') result = [] result.append(_license_header) result.append('#ifndef %s\n' % header_guard) result.append('#define %s\n\n' % header_guard) if receiver.condition: result.append('#if %s\n\n' % receiver.condition) forward_declarations, headers = forward_declarations_and_headers(receiver) result += headers result.append('\n') result.append(forward_declarations) result.append('\n') result.append('namespace Messages {\nnamespace %s {\n' % receiver.name) result.append('\n') result.append( 'static inline CoreIPC::StringReference messageReceiverName()\n') result.append('{\n') result.append(' return CoreIPC::StringReference("%s");\n' % receiver.name) result.append('}\n') result.append('\n') result.append(messages_to_kind_enum(receiver.messages)) result.append('\n') result.append('\n'.join( [message_to_struct_declaration(x) for x in receiver.messages])) result.append('\n') result.append('} // namespace %s\n} // namespace Messages\n' % receiver.name) result.append('\nnamespace CoreIPC {\n\n') result.append( 'template<> struct MessageKindTraits<Messages::%s::Kind> {\n' % receiver.name) result.append( ' static const MessageClass messageClass = MessageClass%s;\n' % receiver.name) result.append('};\n') result.append('\n} // namespace CoreIPC\n') if receiver.condition: result.append('\n#endif // %s\n' % receiver.condition) result.append('\n#endif // %s\n' % header_guard) return ''.join(result)
def generate_messages_header(file): receiver = parser.parse(file) header_guard = messages_header_filename(receiver).replace(".", "_") result = [] result.append(_license_header) result.append("#ifndef %s\n" % header_guard) result.append("#define %s\n\n" % header_guard) if receiver.condition: result.append("#if %s\n\n" % receiver.condition) forward_declarations, headers = forward_declarations_and_headers(receiver) result += headers result.append("\n") result.append(forward_declarations) result.append("\n") result.append("namespace Messages {\nnamespace %s {\n" % receiver.name) result.append("\n") result.append("static inline CoreIPC::StringReference messageReceiverName()\n") result.append("{\n") result.append(' return CoreIPC::StringReference("%s");\n' % receiver.name) result.append("}\n") result.append("\n") result.append(messages_to_kind_enum(receiver.messages)) result.append("\n") result.append("\n".join([message_to_struct_declaration(x) for x in receiver.messages])) result.append("\n") result.append("} // namespace %s\n} // namespace Messages\n" % receiver.name) result.append("\nnamespace CoreIPC {\n\n") result.append("template<> struct MessageKindTraits<Messages::%s::Kind> {\n" % receiver.name) result.append(" static const MessageClass messageClass = MessageClass%s;\n" % receiver.name) result.append("};\n") result.append("\n} // namespace CoreIPC\n") if receiver.condition: result.append("\n#endif // %s\n" % receiver.condition) result.append("\n#endif // %s\n" % header_guard) return "".join(result)
def generate_messages_header(file): receiver = parser.parse(file) header_guard = messages_header_filename(receiver).replace('.', '_') result = [] result.append(_license_header) result.append('#ifndef %s\n' % header_guard) result.append('#define %s\n\n' % header_guard) if receiver.condition: result.append('#if %s\n\n' % receiver.condition) forward_declarations, headers = forward_declarations_and_headers(receiver) result += headers result.append('\n') result.append(forward_declarations) result.append('\n') result.append('namespace Messages {\n\nnamespace %s {\n\n' % receiver.name) result.append(messages_to_kind_enum(receiver.messages)) result.append('\n') result.append('\n'.join([message_to_struct_declaration(x) for x in receiver.messages])) result.append('\n} // namespace %s\n\n} // namespace Messages\n' % receiver.name) result.append('\nnamespace CoreIPC {\n\n') result.append('template<> struct MessageKindTraits<Messages::%s::Kind> {\n' % receiver.name) result.append(' static const MessageClass messageClass = MessageClass%s;\n' % receiver.name) result.append('};\n') result.append('\n} // namespace CoreIPC\n') if receiver.condition: result.append('\n#endif // %s\n' % receiver.condition) result.append('\n#endif // %s\n' % header_guard) return ''.join(result)
def generate_messages_header(file): receiver = parser.parse(file) header_guard = messages_header_filename(receiver).replace('.', '_') result = [] result.append(_license_header) result.append('#ifndef %s\n' % header_guard) result.append('#define %s\n\n' % header_guard) if receiver.condition: result.append('#if %s\n\n' % receiver.condition) forward_declarations, headers = forward_declarations_and_headers(receiver) result += headers result.append('\n') result.append(forward_declarations) result.append('\n') result.append('namespace Messages {\nnamespace %s {\n' % receiver.name) result.append('\n') result.append('static inline IPC::StringReference messageReceiverName()\n') result.append('{\n') result.append(' return IPC::StringReference("%s");\n' % receiver.name) result.append('}\n') result.append('\n') result.append('\n'.join([message_to_struct_declaration(x) for x in receiver.messages])) result.append('\n') result.append('} // namespace %s\n} // namespace Messages\n' % receiver.name) if receiver.condition: result.append('\n#endif // %s\n' % receiver.condition) result.append('\n#endif // %s\n' % header_guard) return ''.join(result)
def generate_message_handler(file): receiver = parser.parse(file) header_conditions = { '"%s"' % messages_header_filename(receiver): [None], '"HandleMessage.h"': [None], '"MessageDecoder.h"': [None], } type_conditions = {} for parameter in receiver.iterparameters(): if not parameter.type in type_conditions: type_conditions[parameter.type] = [] if not parameter.condition in type_conditions[parameter.type]: type_conditions[parameter.type].append(parameter.condition) for parameter in receiver.iterparameters(): type = parameter.type conditions = type_conditions[type] argument_encoder_headers = argument_coder_headers_for_type(type) if argument_encoder_headers: for header in argument_encoder_headers: if header not in header_conditions: header_conditions[header] = [] header_conditions[header].extend(conditions) type_headers = headers_for_type(type) for header in type_headers: if header not in header_conditions: header_conditions[header] = [] header_conditions[header].extend(conditions) for message in receiver.messages: if message.reply_parameters is not None: for reply_parameter in message.reply_parameters: type = reply_parameter.type argument_encoder_headers = argument_coder_headers_for_type(type) if argument_encoder_headers: for header in argument_encoder_headers: if header not in header_conditions: header_conditions[header] = [] header_conditions[header].append(message.condition) type_headers = headers_for_type(type) for header in type_headers: if header not in header_conditions: header_conditions[header] = [] header_conditions[header].append(message.condition) result = [] result.append(_license_header) result.append('#include "config.h"\n') result.append('\n') if receiver.condition: result.append('#if %s\n\n' % receiver.condition) result.append('#include "%s.h"\n\n' % receiver.name) for header in sorted(header_conditions): if header_conditions[header] and not None in header_conditions[header]: result.append('#if %s\n' % ' || '.join(set(header_conditions[header]))) result += ['#include %s\n' % header] result.append('#endif\n') else: result += ['#include %s\n' % header] result.append('\n') sync_delayed_messages = [] for message in receiver.messages: if message.reply_parameters != None and message.has_attribute(DELAYED_ATTRIBUTE): sync_delayed_messages.append(message) if sync_delayed_messages: result.append('namespace Messages {\n\nnamespace %s {\n\n' % receiver.name) for message in sync_delayed_messages: send_parameters = [(function_parameter_type(x.type), x.name) for x in message.reply_parameters] if message.condition: result.append('#if %s\n\n' % message.condition) result.append('%s::DelayedReply::DelayedReply(PassRefPtr<IPC::Connection> connection, std::unique_ptr<IPC::MessageEncoder> encoder)\n' % message.name) result.append(' : m_connection(connection)\n') result.append(' , m_encoder(std::move(encoder))\n') result.append('{\n') result.append('}\n') result.append('\n') result.append('%s::DelayedReply::~DelayedReply()\n' % message.name) result.append('{\n') result.append(' ASSERT(!m_connection);\n') result.append('}\n') result.append('\n') result.append('bool %s::DelayedReply::send(%s)\n' % (message.name, ', '.join([' '.join(x) for x in send_parameters]))) result.append('{\n') result.append(' ASSERT(m_encoder);\n') result += [' *m_encoder << %s;\n' % x.name for x in message.reply_parameters] result.append(' bool _result = m_connection->sendSyncReply(std::move(m_encoder));\n') result.append(' m_connection = nullptr;\n') result.append(' return _result;\n') result.append('}\n') result.append('\n') if message.condition: result.append('#endif\n\n') result.append('} // namespace %s\n\n} // namespace Messages\n\n' % receiver.name) result.append('namespace WebKit {\n\n') async_messages = [] sync_messages = [] for message in receiver.messages: if message.reply_parameters is not None: sync_messages.append(message) else: async_messages.append(message) if async_messages: if receiver.has_attribute(LEGACY_RECEIVER_ATTRIBUTE): result.append('void %s::didReceive%sMessage(IPC::Connection*, IPC::MessageDecoder& decoder)\n' % (receiver.name, receiver.name)) else: result.append('void %s::didReceiveMessage(IPC::Connection* connection, IPC::MessageDecoder& decoder)\n' % (receiver.name)) result.append('{\n') result += [async_message_statement(receiver, message) for message in async_messages] if (receiver.superclass): result.append(' %s::didReceiveMessage(connection, decoder);\n' % (receiver.superclass)) else: if not receiver.has_attribute(LEGACY_RECEIVER_ATTRIBUTE): result.append(' UNUSED_PARAM(connection);\n') result.append(' ASSERT_NOT_REACHED();\n') result.append('}\n') if sync_messages: result.append('\n') if receiver.has_attribute(LEGACY_RECEIVER_ATTRIBUTE): result.append('void %s::didReceiveSync%sMessage(IPC::Connection*%s, IPC::MessageDecoder& decoder, std::unique_ptr<IPC::MessageEncoder>& replyEncoder)\n' % (receiver.name, receiver.name, ' connection' if sync_delayed_messages else '')) else: result.append('void %s::didReceiveSyncMessage(IPC::Connection* connection, IPC::MessageDecoder& decoder, std::unique_ptr<IPC::MessageEncoder>& replyEncoder)\n' % (receiver.name)) result.append('{\n') result += [sync_message_statement(receiver, message) for message in sync_messages] if not receiver.has_attribute(LEGACY_RECEIVER_ATTRIBUTE): result.append(' UNUSED_PARAM(connection);\n') result.append(' ASSERT_NOT_REACHED();\n') result.append('}\n') result.append('\n} // namespace WebKit\n') if receiver.condition: result.append('\n#endif // %s\n' % receiver.condition) return ''.join(result)
def generate_message_handler(file): receiver = parser.parse(file) header_conditions = { '"%s"' % messages_header_filename(receiver): [None], '"HandleMessage.h"': [None], '"MessageDecoder.h"': [None], } type_conditions = {} for parameter in receiver.iterparameters(): if not parameter.type in type_conditions: type_conditions[parameter.type] = [] if not parameter.condition in type_conditions[parameter.type]: type_conditions[parameter.type].append(parameter.condition) for parameter in receiver.iterparameters(): type = parameter.type conditions = type_conditions[type] argument_encoder_headers = argument_coder_headers_for_type(type) if argument_encoder_headers: for header in argument_encoder_headers: if header not in header_conditions: header_conditions[header] = [] header_conditions[header].extend(conditions) type_headers = headers_for_type(type) for header in type_headers: if header not in header_conditions: header_conditions[header] = [] header_conditions[header].extend(conditions) for message in receiver.messages: if message.reply_parameters is not None: for reply_parameter in message.reply_parameters: type = reply_parameter.type argument_encoder_headers = argument_coder_headers_for_type( type) if argument_encoder_headers: for header in argument_encoder_headers: if header not in header_conditions: header_conditions[header] = [] header_conditions[header].append(message.condition) type_headers = headers_for_type(type) for header in type_headers: if header not in header_conditions: header_conditions[header] = [] header_conditions[header].append(message.condition) result = [] result.append(_license_header) result.append('#include "config.h"\n') result.append('\n') if receiver.condition: result.append('#if %s\n\n' % receiver.condition) result.append('#include "%s.h"\n\n' % receiver.name) for header in sorted(header_conditions): if header_conditions[header] and not None in header_conditions[header]: result.append('#if %s\n' % ' || '.join(set(header_conditions[header]))) result += ['#include %s\n' % header] result.append('#endif\n') else: result += ['#include %s\n' % header] result.append('\n') sync_delayed_messages = [] for message in receiver.messages: if message.reply_parameters != None and message.has_attribute( DELAYED_ATTRIBUTE): sync_delayed_messages.append(message) if sync_delayed_messages: result.append('namespace Messages {\n\nnamespace %s {\n\n' % receiver.name) for message in sync_delayed_messages: send_parameters = [(function_parameter_type(x.type), x.name) for x in message.reply_parameters] if message.condition: result.append('#if %s\n\n' % message.condition) result.append( '%s::DelayedReply::DelayedReply(PassRefPtr<IPC::Connection> connection, std::unique_ptr<IPC::MessageEncoder> encoder)\n' % message.name) result.append(' : m_connection(connection)\n') result.append(' , m_encoder(std::move(encoder))\n') result.append('{\n') result.append('}\n') result.append('\n') result.append('%s::DelayedReply::~DelayedReply()\n' % message.name) result.append('{\n') result.append(' ASSERT(!m_connection);\n') result.append('}\n') result.append('\n') result.append('bool %s::DelayedReply::send(%s)\n' % (message.name, ', '.join( [' '.join(x) for x in send_parameters]))) result.append('{\n') result.append(' ASSERT(m_encoder);\n') result += [ ' *m_encoder << %s;\n' % x.name for x in message.reply_parameters ] result.append( ' bool _result = m_connection->sendSyncReply(std::move(m_encoder));\n' ) result.append(' m_connection = nullptr;\n') result.append(' return _result;\n') result.append('}\n') result.append('\n') if message.condition: result.append('#endif\n\n') result.append('} // namespace %s\n\n} // namespace Messages\n\n' % receiver.name) result.append('namespace WebKit {\n\n') async_messages = [] sync_messages = [] for message in receiver.messages: if message.reply_parameters is not None: sync_messages.append(message) else: async_messages.append(message) if async_messages: if receiver.has_attribute(LEGACY_RECEIVER_ATTRIBUTE): result.append( 'void %s::didReceive%sMessage(IPC::Connection*, IPC::MessageDecoder& decoder)\n' % (receiver.name, receiver.name)) else: result.append( 'void %s::didReceiveMessage(IPC::Connection* connection, IPC::MessageDecoder& decoder)\n' % (receiver.name)) result.append('{\n') result += [ async_message_statement(receiver, message) for message in async_messages ] if (receiver.superclass): result.append(' %s::didReceiveMessage(connection, decoder);\n' % (receiver.superclass)) else: if not receiver.has_attribute(LEGACY_RECEIVER_ATTRIBUTE): result.append(' UNUSED_PARAM(connection);\n') result.append(' ASSERT_NOT_REACHED();\n') result.append('}\n') if sync_messages: result.append('\n') if receiver.has_attribute(LEGACY_RECEIVER_ATTRIBUTE): result.append( 'void %s::didReceiveSync%sMessage(IPC::Connection*%s, IPC::MessageDecoder& decoder, std::unique_ptr<IPC::MessageEncoder>& replyEncoder)\n' % (receiver.name, receiver.name, ' connection' if sync_delayed_messages else '')) else: result.append( 'void %s::didReceiveSyncMessage(IPC::Connection* connection, IPC::MessageDecoder& decoder, std::unique_ptr<IPC::MessageEncoder>& replyEncoder)\n' % (receiver.name)) result.append('{\n') result += [ sync_message_statement(receiver, message) for message in sync_messages ] if not receiver.has_attribute(LEGACY_RECEIVER_ATTRIBUTE): result.append(' UNUSED_PARAM(connection);\n') result.append(' ASSERT_NOT_REACHED();\n') result.append('}\n') result.append('\n} // namespace WebKit\n') if receiver.condition: result.append('\n#endif // %s\n' % receiver.condition) return ''.join(result)
def generate_message_handler(file): receiver = parser.parse(file) headers = { '"%s"' % messages_header_filename(receiver): [None], '"HandleMessage.h"': [None], '"MessageDecoder.h"': [None], } type_conditions = {} for parameter in receiver.iterparameters(): if not parameter.type in type_conditions: type_conditions[parameter.type] = [] if not parameter.condition in type_conditions[parameter.type]: type_conditions[parameter.type].append(parameter.condition) for parameter in receiver.iterparameters(): type = parameter.type conditions = type_conditions[type] argument_encoder_headers = argument_coder_headers_for_type(type) if argument_encoder_headers: for header in argument_encoder_headers: if header not in headers: headers[header] = [] headers[header].extend(conditions) type_headers = headers_for_type(type) for header in type_headers: if header not in headers: headers[header] = [] headers[header].extend(conditions) for message in receiver.messages: if message.reply_parameters is not None: for reply_parameter in message.reply_parameters: type = reply_parameter.type argument_encoder_headers = argument_coder_headers_for_type(type) if argument_encoder_headers: for header in argument_encoder_headers: if header not in headers: headers[header] = [] headers[header].append(message.condition) type_headers = headers_for_type(type) for header in type_headers: if header not in headers: headers[header] = [] headers[header].append(message.condition) result = [] result.append(_license_header) result.append('#include "config.h"\n') result.append("\n") if receiver.condition: result.append("#if %s\n\n" % receiver.condition) result.append('#include "%s.h"\n\n' % receiver.name) for headercondition in sorted(headers): if headers[headercondition] and not None in headers[headercondition]: result.append("#if %s\n" % " || ".join(set(headers[headercondition]))) result += ["#include %s\n" % headercondition] result.append("#endif\n") else: result += ["#include %s\n" % headercondition] result.append("\n") sync_delayed_messages = [] for message in receiver.messages: if message.reply_parameters != None and message.has_attribute(DELAYED_ATTRIBUTE): sync_delayed_messages.append(message) if sync_delayed_messages: result.append("namespace Messages {\n\nnamespace %s {\n\n" % receiver.name) for message in sync_delayed_messages: send_parameters = [(function_parameter_type(x.type), x.name) for x in message.reply_parameters] if message.condition: result.append("#if %s\n\n" % message.condition) result.append( "%s::DelayedReply::DelayedReply(PassRefPtr<CoreIPC::Connection> connection, PassOwnPtr<CoreIPC::MessageEncoder> encoder)\n" % message.name ) result.append(" : m_connection(connection)\n") result.append(" , m_encoder(encoder)\n") result.append("{\n") result.append("}\n") result.append("\n") result.append("%s::DelayedReply::~DelayedReply()\n" % message.name) result.append("{\n") result.append(" ASSERT(!m_connection);\n") result.append("}\n") result.append("\n") result.append( "bool %s::DelayedReply::send(%s)\n" % (message.name, ", ".join([" ".join(x) for x in send_parameters])) ) result.append("{\n") result.append(" ASSERT(m_encoder);\n") result += [" m_encoder->encode(%s);\n" % x.name for x in message.reply_parameters] result.append(" bool result = m_connection->sendSyncReply(m_encoder.release());\n") result.append(" m_connection = nullptr;\n") result.append(" return result;\n") result.append("}\n") result.append("\n") if message.condition: result.append("#endif\n\n") result.append("} // namespace %s\n\n} // namespace Messages\n\n" % receiver.name) result.append("namespace WebKit {\n\n") async_dispatch_on_connection_queue_messages = [] sync_dispatch_on_connection_queue_messages = [] async_messages = [] sync_messages = [] for message in receiver.messages: if message.reply_parameters is not None: if message.has_attribute(DISPATCH_ON_CONNECTION_QUEUE_ATTRIBUTE): sync_dispatch_on_connection_queue_messages.append(message) else: sync_messages.append(message) else: if message.has_attribute(DISPATCH_ON_CONNECTION_QUEUE_ATTRIBUTE): async_dispatch_on_connection_queue_messages.append(message) else: async_messages.append(message) if async_dispatch_on_connection_queue_messages: result.append( "void %s::didReceive%sMessageOnConnectionWorkQueue(CoreIPC::Connection* connection, CoreIPC::MessageID, CoreIPC::MessageDecoder& decoder, bool& didHandleMessage)\n" % (receiver.name, receiver.name) ) result.append("{\n") result.append("#if COMPILER(MSVC)\n") result.append("#pragma warning(push)\n") result.append("#pragma warning(disable: 4065)\n") result.append("#endif\n") result += [ async_message_statement(receiver, message) for message in async_dispatch_on_connection_queue_messages ] result.append("#if COMPILER(MSVC)\n") result.append("#pragma warning(pop)\n") result.append("#endif\n") result.append("}\n\n") if async_messages: if receiver.has_attribute(LEGACY_RECEIVER_ATTRIBUTE): result.append( "void %s::didReceive%sMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder& decoder)\n" % (receiver.name, receiver.name) ) else: result.append( "void %s::didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder& decoder)\n" % (receiver.name) ) result.append("{\n") result += [async_message_statement(receiver, message) for message in async_messages] result.append(" ASSERT_NOT_REACHED();\n") result.append("}\n") if sync_messages: result.append("\n") if receiver.has_attribute(LEGACY_RECEIVER_ATTRIBUTE): result.append( "void %s::didReceiveSync%sMessage(CoreIPC::Connection*%s, CoreIPC::MessageID, CoreIPC::MessageDecoder& decoder, OwnPtr<CoreIPC::MessageEncoder>& replyEncoder)\n" % (receiver.name, receiver.name, " connection" if sync_delayed_messages else "") ) else: result.append( "void %s::didReceiveSyncMessage(CoreIPC::Connection*%s,CoreIPC::MessageID, CoreIPC::MessageDecoder& decoder, OwnPtr<CoreIPC::MessageEncoder>& replyEncoder)\n" % (receiver.name, " connection" if sync_delayed_messages else "") ) result.append("{\n") result += [sync_message_statement(receiver, message) for message in sync_messages] result.append(" ASSERT_NOT_REACHED();\n") result.append("}\n") result.append("\n} // namespace WebKit\n") if receiver.condition: result.append("\n#endif // %s\n" % receiver.condition) return "".join(result)
def generate_message_handler(file): receiver = parser.parse(file) headers = { '"%s"' % messages_header_filename(receiver): [None], '"HandleMessage.h"': [None], '"MessageDecoder.h"': [None], } type_conditions = {} for parameter in receiver.iterparameters(): if not parameter.type in type_conditions: type_conditions[parameter.type] = [] if not parameter.condition in type_conditions[parameter.type]: type_conditions[parameter.type].append(parameter.condition) for parameter in receiver.iterparameters(): type = parameter.type conditions = type_conditions[type] argument_encoder_headers = argument_coder_headers_for_type(type) if argument_encoder_headers: for header in argument_encoder_headers: if header not in headers: headers[header] = [] headers[header].extend(conditions) type_headers = headers_for_type(type) for header in type_headers: if header not in headers: headers[header] = [] headers[header].extend(conditions) for message in receiver.messages: if message.reply_parameters is not None: for reply_parameter in message.reply_parameters: type = reply_parameter.type argument_encoder_headers = argument_coder_headers_for_type(type) if argument_encoder_headers: for header in argument_encoder_headers: if header not in headers: headers[header] = [] headers[header].append(message.condition) type_headers = headers_for_type(type) for header in type_headers: if header not in headers: headers[header] = [] headers[header].append(message.condition) result = [] result.append(_license_header) result.append('#include "config.h"\n') result.append('\n') if receiver.condition: result.append('#if %s\n\n' % receiver.condition) result.append('#include "%s.h"\n\n' % receiver.name) for headercondition in sorted(headers): if headers[headercondition] and not None in headers[headercondition]: result.append('#if %s\n' % ' || '.join(set(headers[headercondition]))) result += ['#include %s\n' % headercondition] result.append('#endif\n') else: result += ['#include %s\n' % headercondition] result.append('\n') sync_delayed_messages = [] for message in receiver.messages: if message.reply_parameters != None and message.has_attribute(DELAYED_ATTRIBUTE): sync_delayed_messages.append(message) if sync_delayed_messages: result.append('namespace Messages {\n\nnamespace %s {\n\n' % receiver.name) for message in sync_delayed_messages: send_parameters = [(function_parameter_type(x.type), x.name) for x in message.reply_parameters] if message.condition: result.append('#if %s\n\n' % message.condition) result.append('%s::DelayedReply::DelayedReply(PassRefPtr<CoreIPC::Connection> connection, PassOwnPtr<CoreIPC::MessageEncoder> encoder)\n' % message.name) result.append(' : m_connection(connection)\n') result.append(' , m_encoder(encoder)\n') result.append('{\n') result.append('}\n') result.append('\n') result.append('%s::DelayedReply::~DelayedReply()\n' % message.name) result.append('{\n') result.append(' ASSERT(!m_connection);\n') result.append('}\n') result.append('\n') result.append('bool %s::DelayedReply::send(%s)\n' % (message.name, ', '.join([' '.join(x) for x in send_parameters]))) result.append('{\n') result.append(' ASSERT(m_encoder);\n') result += [' m_encoder->encode(%s);\n' % x.name for x in message.reply_parameters] result.append(' bool result = m_connection->sendSyncReply(m_encoder.release());\n') result.append(' m_connection = nullptr;\n') result.append(' return result;\n') result.append('}\n') result.append('\n') if message.condition: result.append('#endif\n\n') result.append('} // namespace %s\n\n} // namespace Messages\n\n' % receiver.name) result.append('namespace WebKit {\n\n') async_dispatch_on_connection_queue_messages = [] sync_dispatch_on_connection_queue_messages = [] async_messages = [] sync_messages = [] for message in receiver.messages: if message.reply_parameters is not None: if message.has_attribute(DISPATCH_ON_CONNECTION_QUEUE_ATTRIBUTE): sync_dispatch_on_connection_queue_messages.append(message) else: sync_messages.append(message) else: if message.has_attribute(DISPATCH_ON_CONNECTION_QUEUE_ATTRIBUTE): async_dispatch_on_connection_queue_messages.append(message) else: async_messages.append(message) if async_dispatch_on_connection_queue_messages: result.append('void %s::didReceive%sMessageOnConnectionWorkQueue(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::MessageDecoder& decoder, bool& didHandleMessage)\n' % (receiver.name, receiver.name)) result.append('{\n') result.append('#if COMPILER(MSVC)\n') result.append('#pragma warning(push)\n') result.append('#pragma warning(disable: 4065)\n') result.append('#endif\n') result.append(' switch (messageID.get<Messages::%s::Kind>()) {\n' % receiver.name) result += [async_case_statement(receiver, message) for message in async_dispatch_on_connection_queue_messages] result.append(' default:\n') result.append(' return;\n') result.append(' }\n') result.append('#if COMPILER(MSVC)\n') result.append('#pragma warning(pop)\n') result.append('#endif\n') result.append('}\n\n') if async_messages: result.append('void %s::didReceive%sMessage(CoreIPC::Connection*, CoreIPC::MessageID messageID, CoreIPC::MessageDecoder& decoder)\n' % (receiver.name, receiver.name)) result.append('{\n') result.append(' switch (messageID.get<Messages::%s::Kind>()) {\n' % receiver.name) result += [async_case_statement(receiver, message) for message in async_messages] result.append(' default:\n') result.append(' break;\n') result.append(' }\n\n') result.append(' ASSERT_NOT_REACHED();\n') result.append('}\n') if sync_messages: result.append('\n') result.append('void %s::didReceiveSync%sMessage(CoreIPC::Connection*%s, CoreIPC::MessageID messageID, CoreIPC::MessageDecoder& decoder, OwnPtr<CoreIPC::MessageEncoder>& replyEncoder)\n' % (receiver.name, receiver.name, ' connection' if sync_delayed_messages else '')) result.append('{\n') result.append(' switch (messageID.get<Messages::%s::Kind>()) {\n' % receiver.name) result += [sync_case_statement(receiver, message) for message in sync_messages] result.append(' default:\n') result.append(' break;\n') result.append(' }\n\n') result.append(' ASSERT_NOT_REACHED();\n') result.append('}\n') result.append('\n} // namespace WebKit\n') if receiver.condition: result.append('\n#endif // %s\n' % receiver.condition) return ''.join(result)
def generate_message_handler(file): receiver = parser.parse(file) headers = { '"%s"' % messages_header_filename(receiver): [None], '"HandleMessage.h"': [None], '"ArgumentDecoder.h"': [None], } type_conditions = {} for parameter in receiver.iterparameters(): if not parameter.type in type_conditions: type_conditions[parameter.type] = [] if not parameter.condition in type_conditions[parameter.type]: type_conditions[parameter.type].append(parameter.condition) for parameter in receiver.iterparameters(): type = parameter.type conditions = type_conditions[type] argument_encoder_headers = argument_coder_headers_for_type(type) if argument_encoder_headers: for header in argument_encoder_headers: if header not in headers: headers[header] = [] headers[header].extend(conditions) type_headers = headers_for_type(type) for header in type_headers: if header not in headers: headers[header] = [] headers[header].extend(conditions) for message in receiver.messages: if message.reply_parameters is not None: for reply_parameter in message.reply_parameters: type = reply_parameter.type argument_encoder_headers = argument_coder_headers_for_type(type) if argument_encoder_headers: for header in argument_encoder_headers: if header not in headers: headers[header] = [] headers[header].append(message.condition) type_headers = headers_for_type(type) for header in type_headers: if header not in headers: headers[header] = [] headers[header].append(message.condition) result = [] result.append(_license_header) result.append('#include "config.h"\n') result.append('\n') if receiver.condition: result.append('#if %s\n\n' % receiver.condition) result.append('#include "%s.h"\n\n' % receiver.name) for headercondition in sorted(headers): if headers[headercondition] and not None in headers[headercondition]: result.append('#if %s\n' % ' || '.join(set(headers[headercondition]))) result += ['#include %s\n' % headercondition] result.append('#endif\n') else: result += ['#include %s\n' % headercondition] result.append('\n') sync_delayed_messages = [] for message in receiver.messages: if message.reply_parameters != None and message.has_attribute(DELAYED_ATTRIBUTE): sync_delayed_messages.append(message) if sync_delayed_messages: result.append('namespace Messages {\n\nnamespace %s {\n\n' % receiver.name) for message in sync_delayed_messages: send_parameters = [(function_parameter_type(x.type), x.name) for x in message.reply_parameters] if message.condition: result.append('#if %s\n\n' % message.condition) result.append('%s::DelayedReply::DelayedReply(PassRefPtr<CoreIPC::Connection> connection, PassOwnPtr<CoreIPC::ArgumentEncoder> arguments)\n' % message.name) result.append(' : m_connection(connection)\n') result.append(' , m_arguments(arguments)\n') result.append('{\n') result.append('}\n') result.append('\n') result.append('%s::DelayedReply::~DelayedReply()\n' % message.name) result.append('{\n') result.append(' ASSERT(!m_connection);\n') result.append('}\n') result.append('\n') result.append('bool %s::DelayedReply::send(%s)\n' % (message.name, ', '.join([' '.join(x) for x in send_parameters]))) result.append('{\n') result.append(' ASSERT(m_arguments);\n') result += [' m_arguments->encode(%s);\n' % x.name for x in message.reply_parameters] result.append(' bool result = m_connection->sendSyncReply(m_arguments.release());\n') result.append(' m_connection = nullptr;\n') result.append(' return result;\n') result.append('}\n') result.append('\n') if message.condition: result.append('#endif\n\n') result.append('} // namespace %s\n\n} // namespace Messages\n\n' % receiver.name) result.append('namespace WebKit {\n\n') async_dispatch_on_connection_queue_messages = [] sync_dispatch_on_connection_queue_messages = [] async_messages = [] sync_messages = [] for message in receiver.messages: if message.reply_parameters is not None: if message.has_attribute(DISPATCH_ON_CONNECTION_QUEUE_ATTRIBUTE): sync_dispatch_on_connection_queue_messages.append(message) else: sync_messages.append(message) else: if message.has_attribute(DISPATCH_ON_CONNECTION_QUEUE_ATTRIBUTE): async_dispatch_on_connection_queue_messages.append(message) else: async_messages.append(message) if async_dispatch_on_connection_queue_messages: result.append('void %s::didReceive%sMessageOnConnectionWorkQueue(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, bool& didHandleMessage)\n' % (receiver.name, receiver.name)) result.append('{\n') result.append('#if COMPILER(MSVC)\n') result.append('#pragma warning(push)\n') result.append('#pragma warning(disable: 4065)\n') result.append('#endif\n') result.append(' switch (messageID.get<Messages::%s::Kind>()) {\n' % receiver.name) result += [async_case_statement(receiver, message) for message in async_dispatch_on_connection_queue_messages] result.append(' default:\n') result.append(' return;\n') result.append(' }\n') result.append('#if COMPILER(MSVC)\n') result.append('#pragma warning(pop)\n') result.append('#endif\n') result.append('}\n\n') if async_messages: result.append('void %s::didReceive%sMessage(CoreIPC::Connection*, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments)\n' % (receiver.name, receiver.name)) result.append('{\n') result.append(' switch (messageID.get<Messages::%s::Kind>()) {\n' % receiver.name) result += [async_case_statement(receiver, message) for message in async_messages] result.append(' default:\n') result.append(' break;\n') result.append(' }\n\n') result.append(' ASSERT_NOT_REACHED();\n') result.append('}\n') if sync_messages: result.append('\n') result.append('void %s::didReceiveSync%sMessage(CoreIPC::Connection*%s, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, OwnPtr<CoreIPC::ArgumentEncoder>& reply)\n' % (receiver.name, receiver.name, ' connection' if sync_delayed_messages else '')) result.append('{\n') result.append(' switch (messageID.get<Messages::%s::Kind>()) {\n' % receiver.name) result += [sync_case_statement(receiver, message) for message in sync_messages] result.append(' default:\n') result.append(' break;\n') result.append(' }\n\n') result.append(' ASSERT_NOT_REACHED();\n') result.append('}\n') result.append('\n} // namespace WebKit\n') if receiver.condition: result.append('\n#endif // %s\n' % receiver.condition) return ''.join(result)