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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 // Copyright (c) 2008 The Chromium Authors. All rights reserved.
     2 // Use of this source code is governed by a BSD-style license that can be
     3 // found in the LICENSE file.
     5 #ifndef CHROME_COMMON_MACH_MESSAGE_SOURCE_MAC_H_
     6 #define CHROME_COMMON_MACH_MESSAGE_SOURCE_MAC_H_
     8 #include <CoreServices/CoreServices.h>
    10 #include "base/scoped_cftyperef.h"
    12 // Handles registering and cleaning up after a CFRunloopSource for a Mach port.
    13 // Messages received on the port are piped through to a delegate.
    14 //
    15 // Example:
    16 //  class MyListener : public MachMessageSource::MachPortListener {
    17 //   public:
    18 //    void OnMachMessageReceived(void* mach_msg, size_t size) {
    19 //      printf("received message on Mach port\n");
    20 //    }
    21 //  };
    22 //
    23 //  mach_port_t a_port = ...;
    24 //  MyListener listener;
    25 //  bool success = false;
    26 //  MachMessageSource message_source(port, listener, &success);
    27 //
    28 //  if (!success) {
    29 //    exit(1);  // Couldn't register mach runloop source.
    30 //  }
    31 //
    32 //  CFRunLoopRun();  // Process messages on runloop...
    33 class MachMessageSource {
    34  public:
    35   // Classes that want to listen on a Mach port can implement
    36   // OnMachMessageReceived, |mach_msg| is a pointer to the raw message data and
    37   // |size| is the buffer size;
    38   class MachPortListener {
    39    public:
    40     virtual void OnMachMessageReceived(void* mach_msg, size_t size) = 0;
    41   };
    43   // |listener| is a week reference passed to CF, it needs to remain in
    44   // existence till this object is destroeyd.
    45   MachMessageSource(mach_port_t port,
    46                     MachPortListener* listener,
    47                     bool* success);
    48   ~MachMessageSource();
    50  private:
    51   // Called by CF when a new message arrives on the Mach port.
    52   static void OnReceiveMachMessage(CFMachPortRef port, void* msg, CFIndex size,
    53                                    void* closure);
    55   scoped_cftyperef<CFRunLoopSourceRef> machport_runloop_ref_;
    56   DISALLOW_COPY_AND_ASSIGN(MachMessageSource);
    57 };
    59 #endif // CHROME_COMMON_MACH_MESSAGE_SOURCE_MAC_H_

mercurial