ipc/chromium/src/chrome/common/ipc_sync_message.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/chrome/common/ipc_sync_message.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,97 @@
     1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#ifndef CHROME_COMMON_IPC_SYNC_MESSAGE_H__
     1.9 +#define CHROME_COMMON_IPC_SYNC_MESSAGE_H__
    1.10 +
    1.11 +#if defined(OS_WIN)
    1.12 +#include <windows.h>
    1.13 +#endif
    1.14 +#include <string>
    1.15 +#include "base/basictypes.h"
    1.16 +#include "chrome/common/ipc_message.h"
    1.17 +
    1.18 +namespace base {
    1.19 +class WaitableEvent;
    1.20 +}
    1.21 +
    1.22 +namespace IPC {
    1.23 +
    1.24 +class MessageReplyDeserializer;
    1.25 +
    1.26 +class SyncMessage : public Message {
    1.27 + public:
    1.28 +  SyncMessage(int32_t routing_id, uint16_t type, PriorityValue priority,
    1.29 +              MessageReplyDeserializer* deserializer);
    1.30 +
    1.31 +  // Call this to get a deserializer for the output parameters.
    1.32 +  // Note that this can only be called once, and the caller is responsible
    1.33 +  // for deleting the deserializer when they're done.
    1.34 +  MessageReplyDeserializer* GetReplyDeserializer();
    1.35 +
    1.36 +  // If this message can cause the receiver to block while waiting for user
    1.37 +  // input (i.e. by calling MessageBox), then the caller needs to pump window
    1.38 +  // messages and dispatch asynchronous messages while waiting for the reply.
    1.39 +  // If this event is passed in, then window messages will start being pumped
    1.40 +  // when it's set.  Note that this behavior will continue even if the event is
    1.41 +  // later reset.  The event must be valid until after the Send call returns.
    1.42 +  void set_pump_messages_event(base::WaitableEvent* event) {
    1.43 +    pump_messages_event_ = event;
    1.44 +    if (event) {
    1.45 +      header()->flags |= PUMPING_MSGS_BIT;
    1.46 +    } else {
    1.47 +      header()->flags &= ~PUMPING_MSGS_BIT;
    1.48 +    }
    1.49 +  }
    1.50 +
    1.51 +  // Call this if you always want to pump messages.  You can call this method
    1.52 +  // or set_pump_messages_event but not both.
    1.53 +  void EnableMessagePumping();
    1.54 +
    1.55 +  base::WaitableEvent* pump_messages_event() const {
    1.56 +    return pump_messages_event_;
    1.57 +  }
    1.58 +
    1.59 +  // Returns true if the message is a reply to the given request id.
    1.60 +  static bool IsMessageReplyTo(const Message& msg, int request_id);
    1.61 +
    1.62 +  // Given a reply message, returns an iterator to the beginning of the data
    1.63 +  // (i.e. skips over the synchronous specific data).
    1.64 +  static void* GetDataIterator(const Message* msg);
    1.65 +
    1.66 +  // Given a synchronous message (or its reply), returns its id.
    1.67 +  static int GetMessageId(const Message& msg);
    1.68 +
    1.69 +  // Generates a reply message to the given message.
    1.70 +  static Message* GenerateReply(const Message* msg);
    1.71 +
    1.72 + private:
    1.73 +  struct SyncHeader {
    1.74 +    // unique ID (unique per sender)
    1.75 +    int message_id;
    1.76 +  };
    1.77 +
    1.78 +  static bool ReadSyncHeader(const Message& msg, SyncHeader* header);
    1.79 +  static bool WriteSyncHeader(Message* msg, const SyncHeader& header);
    1.80 +
    1.81 +  MessageReplyDeserializer* deserializer_;
    1.82 +  base::WaitableEvent* pump_messages_event_;
    1.83 +
    1.84 +  static uint32_t next_id_;  // for generation of unique ids
    1.85 +};
    1.86 +
    1.87 +// Used to deserialize parameters from a reply to a synchronous message
    1.88 +class MessageReplyDeserializer {
    1.89 + public:
    1.90 +  bool SerializeOutputParameters(const Message& msg);
    1.91 +  virtual ~MessageReplyDeserializer() {}
    1.92 + private:
    1.93 +  // Derived classes need to implement this, using the given iterator (which
    1.94 +  // is skipped past the header for synchronous messages).
    1.95 +  virtual bool SerializeOutputParameters(const Message& msg, void* iter) = 0;
    1.96 +};
    1.97 +
    1.98 +}  // namespace IPC
    1.99 +
   1.100 +#endif  // CHROME_COMMON_IPC_SYNC_MESSAGE_H__

mercurial