OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef IPC_IPC_SYNC_MESSAGE_H_ | 5 #ifndef IPC_IPC_SYNC_MESSAGE_H_ |
6 #define IPC_IPC_SYNC_MESSAGE_H_ | 6 #define IPC_IPC_SYNC_MESSAGE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <windows.h> | 10 #include <windows.h> |
11 #endif | 11 #endif |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 base::WaitableEvent* pump_messages_event() const { | 55 base::WaitableEvent* pump_messages_event() const { |
56 return pump_messages_event_; | 56 return pump_messages_event_; |
57 } | 57 } |
58 | 58 |
59 // Returns true if the message is a reply to the given request id. | 59 // Returns true if the message is a reply to the given request id. |
60 static bool IsMessageReplyTo(const Message& msg, int request_id); | 60 static bool IsMessageReplyTo(const Message& msg, int request_id); |
61 | 61 |
62 // Given a reply message, returns an iterator to the beginning of the data | 62 // Given a reply message, returns an iterator to the beginning of the data |
63 // (i.e. skips over the synchronous specific data). | 63 // (i.e. skips over the synchronous specific data). |
64 static void* GetDataIterator(const Message* msg); | 64 static PickleIterator GetDataIterator(const Message* msg); |
65 | 65 |
66 // Given a synchronous message (or its reply), returns its id. | 66 // Given a synchronous message (or its reply), returns its id. |
67 static int GetMessageId(const Message& msg); | 67 static int GetMessageId(const Message& msg); |
68 | 68 |
69 // Generates a reply message to the given message. | 69 // Generates a reply message to the given message. |
70 static Message* GenerateReply(const Message* msg); | 70 static Message* GenerateReply(const Message* msg); |
71 | 71 |
72 private: | 72 private: |
73 struct SyncHeader { | 73 struct SyncHeader { |
74 // unique ID (unique per sender) | 74 // unique ID (unique per sender) |
75 int message_id; | 75 int message_id; |
76 }; | 76 }; |
77 | 77 |
78 static bool ReadSyncHeader(const Message& msg, SyncHeader* header); | 78 static bool ReadSyncHeader(const Message& msg, SyncHeader* header); |
79 static bool WriteSyncHeader(Message* msg, const SyncHeader& header); | 79 static bool WriteSyncHeader(Message* msg, const SyncHeader& header); |
80 | 80 |
81 scoped_ptr<MessageReplyDeserializer> deserializer_; | 81 scoped_ptr<MessageReplyDeserializer> deserializer_; |
82 base::WaitableEvent* pump_messages_event_; | 82 base::WaitableEvent* pump_messages_event_; |
83 }; | 83 }; |
84 | 84 |
85 // Used to deserialize parameters from a reply to a synchronous message | 85 // Used to deserialize parameters from a reply to a synchronous message |
86 class IPC_EXPORT MessageReplyDeserializer { | 86 class IPC_EXPORT MessageReplyDeserializer { |
87 public: | 87 public: |
88 virtual ~MessageReplyDeserializer() {} | 88 virtual ~MessageReplyDeserializer() {} |
89 bool SerializeOutputParameters(const Message& msg); | 89 bool SerializeOutputParameters(const Message& msg); |
90 private: | 90 private: |
91 // Derived classes need to implement this, using the given iterator (which | 91 // Derived classes need to implement this, using the given iterator (which |
92 // is skipped past the header for synchronous messages). | 92 // is skipped past the header for synchronous messages). |
93 virtual bool SerializeOutputParameters(const Message& msg, void* iter) = 0; | 93 virtual bool SerializeOutputParameters(const Message& msg, |
| 94 PickleIterator iter) = 0; |
94 }; | 95 }; |
95 | 96 |
96 // When sending a synchronous message, this structure contains an object | 97 // When sending a synchronous message, this structure contains an object |
97 // that knows how to deserialize the response. | 98 // that knows how to deserialize the response. |
98 struct PendingSyncMsg { | 99 struct PendingSyncMsg { |
99 PendingSyncMsg(int id, | 100 PendingSyncMsg(int id, |
100 MessageReplyDeserializer* d, | 101 MessageReplyDeserializer* d, |
101 base::WaitableEvent* e) | 102 base::WaitableEvent* e) |
102 : id(id), deserializer(d), done_event(e), send_result(false) { } | 103 : id(id), deserializer(d), done_event(e), send_result(false) { } |
103 int id; | 104 int id; |
104 MessageReplyDeserializer* deserializer; | 105 MessageReplyDeserializer* deserializer; |
105 base::WaitableEvent* done_event; | 106 base::WaitableEvent* done_event; |
106 bool send_result; | 107 bool send_result; |
107 }; | 108 }; |
108 | 109 |
109 } // namespace IPC | 110 } // namespace IPC |
110 | 111 |
111 #endif // IPC_IPC_SYNC_MESSAGE_H_ | 112 #endif // IPC_IPC_SYNC_MESSAGE_H_ |
OLD | NEW |