Skip to content

Commit

Permalink
Revert of Remove all reference to carbon api (patchset #2 id:20001 of h…
Browse files Browse the repository at this point in the history
…ttps://codereview.webrtc.org/2299633002/ )

Reason for revert:
Breaks chromium build

Original issue's description:
> Remove all reference to carbon api
>
> BUG=webrtc:6282
>
> Committed: https://crrev.com/dbd8b6bec4143c940b2f2ca8cd85c25d17327964
> Cr-Commit-Position: refs/heads/master@{#14080}

TBR=magjed@webrtc.org,mflodman@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:6282

Review-Url: https://codereview.webrtc.org/2316563002
Cr-Commit-Position: refs/heads/master@{#14081}
  • Loading branch information
kthelgason authored and Commit bot committed Sep 6, 2016
1 parent dbd8b6b commit b096aa7
Show file tree
Hide file tree
Showing 21 changed files with 830 additions and 22 deletions.
7 changes: 7 additions & 0 deletions webrtc/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,10 @@ if (rtc_include_tests) {
"base/sslstreamadapter_unittest.cc",
]
}
if (is_ios || (is_mac && target_cpu != "x86")) {
defines = [ "CARBON_DEPRECATED=YES" ]
}

if (rtc_use_quic) {
sources += [
"p2p/quic/quicconnectionhelper_unittest.cc",
Expand Down Expand Up @@ -824,6 +828,9 @@ if (rtc_include_tests) {
if (is_mac) {
sources += [ "base/macsocketserver_unittest.cc" ]
}
if (is_ios || (is_mac && target_cpu != "x86")) {
defines = [ "CARBON_DEPRECATED=YES" ]
}
if (is_clang) {
# Suppress warnings from the Chromium Clang plugin.
# See http://code.google.com/p/webrtc/issues/detail?id=163 for details.
Expand Down
9 changes: 8 additions & 1 deletion webrtc/base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ config("rtc_base_all_dependent_config") {
"Security.framework",
"SystemConfiguration.framework",
]
if (current_cpu == "x86") {
libs += [ "Carbon.framework" ]
}
}
}

Expand Down Expand Up @@ -288,7 +291,6 @@ rtc_static_library("rtc_base") {
defines = [ "LOGGING=1" ]

sources = [
"applefilesystem.mm",
"arraysize.h",
"asyncfile.cc",
"asyncfile.h",
Expand Down Expand Up @@ -337,6 +339,7 @@ rtc_static_library("rtc_base") {
"httpcommon.h",
"httprequest.cc",
"httprequest.h",
"iosfilesystem.mm",
"ipaddress.cc",
"ipaddress.h",
"linked_ptr.h",
Expand Down Expand Up @@ -666,6 +669,10 @@ rtc_static_library("rtc_base") {
}
}

if (is_ios || (is_mac && current_cpu != "x86")) {
defines += [ "CARBON_DEPRECATED=YES" ]
}

if (is_linux || is_android) {
sources += [
"linux.cc",
Expand Down
20 changes: 19 additions & 1 deletion webrtc/base/base.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@
'LOGGING=1',
],
'sources': [
'applefilesystem.mm',
'arraysize.h',
'asyncfile.cc',
'asyncfile.h',
Expand Down Expand Up @@ -278,6 +277,7 @@
'httpcommon.h',
'httprequest.cc',
'httprequest.h',
'iosfilesystem.mm',
'ipaddress.cc',
'ipaddress.h',
'linked_ptr.h',
Expand Down Expand Up @@ -603,6 +603,19 @@
},
},
},
'conditions': [
['target_arch=="ia32"', {
'all_dependent_settings': {
'link_settings': {
'xcode_settings': {
'OTHER_LDFLAGS': [
'-framework Carbon',
],
},
},
},
}],
],
}],
['OS=="win" and nacl_untrusted_build==0', {
'sources': [
Expand Down Expand Up @@ -651,6 +664,11 @@
},
}
}],
['OS=="ios" or (OS=="mac" and target_arch!="ia32")', {
'defines': [
'CARBON_DEPRECATED=YES',
],
}],
['OS=="linux" or OS=="android"', {
'sources': [
'linux.cc',
Expand Down
12 changes: 6 additions & 6 deletions webrtc/base/applefilesystem.mm → webrtc/base/iosfilesystem.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/

// This file only exists because various iOS and macOS system APIs are only
// available from Objective-C. See unixfilesystem.cc for the only use
// This file only exists because various iOS system APIs are only
// available from Objective-C. See unixfilesystem.cc for the only use
// (enforced by a lack of a header file).

#import <Foundation/NSPathUtilities.h>
Expand All @@ -33,21 +33,21 @@
}

// Return a (leaked) copy of a directory name suitable for application data.
char* AppleDataDirectory() {
char* IOSDataDirectory() {
NSArray* paths = NSSearchPathForDirectoriesInDomains(
NSApplicationSupportDirectory, NSUserDomainMask, YES);
ASSERT([paths count] == 1);
return copyString([paths objectAtIndex:0]);
}

// Return a (leaked) copy of a directory name suitable for use as a $TEMP.
char* AppleTempDirectory() {
char* IOSTempDirectory() {
return copyString(NSTemporaryDirectory());
}

// Return the binary's path.
void AppleAppName(rtc::Pathname* path) {
NSProcessInfo* pInfo = [NSProcessInfo processInfo];
void IOSAppName(rtc::Pathname* path) {
NSProcessInfo *pInfo = [NSProcessInfo processInfo];
NSString* argv0 = [[pInfo arguments] objectAtIndex:0];
path->SetPathname([argv0 UTF8String]);
}
171 changes: 171 additions & 0 deletions webrtc/base/macsocketserver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,175 @@ void MacCFSocketServer::OnWakeUpCallback() {
ASSERT(run_loop_ == CFRunLoopGetCurrent());
CFRunLoopStop(run_loop_);
}

///////////////////////////////////////////////////////////////////////////////
// MacCarbonSocketServer
///////////////////////////////////////////////////////////////////////////////
#ifndef CARBON_DEPRECATED

const UInt32 kEventClassSocketServer = 'MCSS';
const UInt32 kEventWakeUp = 'WAKE';
const EventTypeSpec kEventWakeUpSpec[] = {
{ kEventClassSocketServer, kEventWakeUp }
};

std::string DecodeEvent(EventRef event) {
std::string str;
DecodeFourChar(::GetEventClass(event), &str);
str.push_back(':');
DecodeFourChar(::GetEventKind(event), &str);
return str;
}

MacCarbonSocketServer::MacCarbonSocketServer()
: event_queue_(GetCurrentEventQueue()), wake_up_(NULL) {
VERIFY(noErr == CreateEvent(NULL, kEventClassSocketServer, kEventWakeUp, 0,
kEventAttributeUserEvent, &wake_up_));
}

MacCarbonSocketServer::~MacCarbonSocketServer() {
if (wake_up_) {
ReleaseEvent(wake_up_);
}
}

bool MacCarbonSocketServer::Wait(int cms, bool process_io) {
ASSERT(GetCurrentEventQueue() == event_queue_);

// Listen to all events if we're processing I/O.
// Only listen for our wakeup event if we're not.
UInt32 num_types = 0;
const EventTypeSpec* events = NULL;
if (!process_io) {
num_types = GetEventTypeCount(kEventWakeUpSpec);
events = kEventWakeUpSpec;
}

EventTargetRef target = GetEventDispatcherTarget();
EventTimeout timeout =
(kForever == cms) ? kEventDurationForever : cms / 1000.0;
EventTimeout end_time = GetCurrentEventTime() + timeout;

bool done = false;
while (!done) {
EventRef event;
OSStatus result = ReceiveNextEvent(num_types, events, timeout, true,
&event);
if (noErr == result) {
if (wake_up_ != event) {
LOG_F(LS_VERBOSE) << "Dispatching event: " << DecodeEvent(event);
result = SendEventToEventTarget(event, target);
if ((noErr != result) && (eventNotHandledErr != result)) {
LOG_E(LS_ERROR, OS, result) << "SendEventToEventTarget";
}
} else {
done = true;
}
ReleaseEvent(event);
} else if (eventLoopTimedOutErr == result) {
ASSERT(cms != kForever);
done = true;
} else if (eventLoopQuitErr == result) {
// Ignore this... we get spurious quits for a variety of reasons.
LOG_E(LS_VERBOSE, OS, result) << "ReceiveNextEvent";
} else {
// Some strange error occurred. Log it.
LOG_E(LS_WARNING, OS, result) << "ReceiveNextEvent";
return false;
}
if (kForever != cms) {
timeout = end_time - GetCurrentEventTime();
}
}
return true;
}

void MacCarbonSocketServer::WakeUp() {
if (!IsEventInQueue(event_queue_, wake_up_)) {
RetainEvent(wake_up_);
OSStatus result = PostEventToQueue(event_queue_, wake_up_,
kEventPriorityStandard);
if (noErr != result) {
LOG_E(LS_ERROR, OS, result) << "PostEventToQueue";
}
}
}

///////////////////////////////////////////////////////////////////////////////
// MacCarbonAppSocketServer
///////////////////////////////////////////////////////////////////////////////

MacCarbonAppSocketServer::MacCarbonAppSocketServer()
: event_queue_(GetCurrentEventQueue()) {
// Install event handler
VERIFY(noErr == InstallApplicationEventHandler(
NewEventHandlerUPP(WakeUpEventHandler), 1, kEventWakeUpSpec, this,
&event_handler_));

// Install a timer and set it idle to begin with.
VERIFY(noErr == InstallEventLoopTimer(GetMainEventLoop(),
kEventDurationForever,
kEventDurationForever,
NewEventLoopTimerUPP(TimerHandler),
this,
&timer_));
}

MacCarbonAppSocketServer::~MacCarbonAppSocketServer() {
RemoveEventLoopTimer(timer_);
RemoveEventHandler(event_handler_);
}

OSStatus MacCarbonAppSocketServer::WakeUpEventHandler(
EventHandlerCallRef next, EventRef event, void *data) {
QuitApplicationEventLoop();
return noErr;
}

void MacCarbonAppSocketServer::TimerHandler(
EventLoopTimerRef timer, void *data) {
QuitApplicationEventLoop();
}

bool MacCarbonAppSocketServer::Wait(int cms, bool process_io) {
if (!process_io && cms == 0) {
// No op.
return true;
}
if (kForever != cms) {
// Start a timer.
OSStatus error =
SetEventLoopTimerNextFireTime(timer_, cms / 1000.0);
if (error != noErr) {
LOG(LS_ERROR) << "Failed setting next fire time.";
}
}
if (!process_io) {
// No way to listen to common modes and not get socket events, unless
// we disable each one's callbacks.
EnableSocketCallbacks(false);
}
RunApplicationEventLoop();
if (!process_io) {
// Reenable them. Hopefully this won't cause spurious callbacks or
// missing ones while they were disabled.
EnableSocketCallbacks(true);
}
return true;
}

void MacCarbonAppSocketServer::WakeUp() {
// TODO: No-op if there's already a WakeUp in flight.
EventRef wake_up;
VERIFY(noErr == CreateEvent(NULL, kEventClassSocketServer, kEventWakeUp, 0,
kEventAttributeUserEvent, &wake_up));
OSStatus result = PostEventToQueue(event_queue_, wake_up,
kEventPriorityStandard);
if (noErr != result) {
LOG_E(LS_ERROR, OS, result) << "PostEventToQueue";
}
ReleaseEvent(wake_up);
}

#endif
} // namespace rtc
59 changes: 58 additions & 1 deletion webrtc/base/macsocketserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#define WEBRTC_BASE_MACSOCKETSERVER_H__

#include <set>
#include <CoreFoundation/CoreFoundation.h>
#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) // Invalid on IOS
#include <Carbon/Carbon.h>
#endif
#include "webrtc/base/physicalsocketserver.h"

namespace rtc {
Expand Down Expand Up @@ -74,6 +76,61 @@ class MacCFSocketServer : public MacBaseSocketServer {
CFRunLoopRef run_loop_;
CFRunLoopSourceRef wake_up_;
};

#ifndef CARBON_DEPRECATED

///////////////////////////////////////////////////////////////////////////////
// MacCarbonSocketServer
///////////////////////////////////////////////////////////////////////////////

// Interacts with the Carbon event queue. While idle it will block,
// waiting for events. When the socket server has work to do, it will
// post a 'wake up' event to the queue, causing the thread to exit the
// event loop until the next call to Wait. Other events are dispatched
// to their target. Supports Carbon and Cocoa UI interaction.
class MacCarbonSocketServer : public MacBaseSocketServer {
public:
MacCarbonSocketServer();
virtual ~MacCarbonSocketServer();

// SocketServer Interface
virtual bool Wait(int cms, bool process_io);
virtual void WakeUp();

private:
EventQueueRef event_queue_;
EventRef wake_up_;
};

///////////////////////////////////////////////////////////////////////////////
// MacCarbonAppSocketServer
///////////////////////////////////////////////////////////////////////////////

// Runs the Carbon application event loop on the current thread while
// idle. When the socket server has work to do, it will post an event
// to the queue, causing the thread to exit the event loop until the
// next call to Wait. Other events are automatically dispatched to
// their target.
class MacCarbonAppSocketServer : public MacBaseSocketServer {
public:
MacCarbonAppSocketServer();
virtual ~MacCarbonAppSocketServer();

// SocketServer Interface
virtual bool Wait(int cms, bool process_io);
virtual void WakeUp();

private:
static OSStatus WakeUpEventHandler(EventHandlerCallRef next, EventRef event,
void *data);
static void TimerHandler(EventLoopTimerRef timer, void *data);

EventQueueRef event_queue_;
EventHandlerRef event_handler_;
EventLoopTimerRef timer_;
};

#endif
} // namespace rtc

#endif // WEBRTC_BASE_MACSOCKETSERVER_H__
Loading

0 comments on commit b096aa7

Please sign in to comment.