Skip to content

Commit b096aa7

Browse files
kthelgasonCommit bot
authored and
Commit bot
committed
Revert of Remove all reference to carbon api (patchset #2 id:20001 of https://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} [email protected],[email protected] # 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}
1 parent dbd8b6b commit b096aa7

21 files changed

+830
-22
lines changed

webrtc/BUILD.gn

+7
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,10 @@ if (rtc_include_tests) {
562562
"base/sslstreamadapter_unittest.cc",
563563
]
564564
}
565+
if (is_ios || (is_mac && target_cpu != "x86")) {
566+
defines = [ "CARBON_DEPRECATED=YES" ]
567+
}
568+
565569
if (rtc_use_quic) {
566570
sources += [
567571
"p2p/quic/quicconnectionhelper_unittest.cc",
@@ -824,6 +828,9 @@ if (rtc_include_tests) {
824828
if (is_mac) {
825829
sources += [ "base/macsocketserver_unittest.cc" ]
826830
}
831+
if (is_ios || (is_mac && target_cpu != "x86")) {
832+
defines = [ "CARBON_DEPRECATED=YES" ]
833+
}
827834
if (is_clang) {
828835
# Suppress warnings from the Chromium Clang plugin.
829836
# See http://code.google.com/p/webrtc/issues/detail?id=163 for details.

webrtc/base/BUILD.gn

+8-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ config("rtc_base_all_dependent_config") {
6565
"Security.framework",
6666
"SystemConfiguration.framework",
6767
]
68+
if (current_cpu == "x86") {
69+
libs += [ "Carbon.framework" ]
70+
}
6871
}
6972
}
7073

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

290293
sources = [
291-
"applefilesystem.mm",
292294
"arraysize.h",
293295
"asyncfile.cc",
294296
"asyncfile.h",
@@ -337,6 +339,7 @@ rtc_static_library("rtc_base") {
337339
"httpcommon.h",
338340
"httprequest.cc",
339341
"httprequest.h",
342+
"iosfilesystem.mm",
340343
"ipaddress.cc",
341344
"ipaddress.h",
342345
"linked_ptr.h",
@@ -666,6 +669,10 @@ rtc_static_library("rtc_base") {
666669
}
667670
}
668671

672+
if (is_ios || (is_mac && current_cpu != "x86")) {
673+
defines += [ "CARBON_DEPRECATED=YES" ]
674+
}
675+
669676
if (is_linux || is_android) {
670677
sources += [
671678
"linux.cc",

webrtc/base/base.gyp

+19-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@
229229
'LOGGING=1',
230230
],
231231
'sources': [
232-
'applefilesystem.mm',
233232
'arraysize.h',
234233
'asyncfile.cc',
235234
'asyncfile.h',
@@ -278,6 +277,7 @@
278277
'httpcommon.h',
279278
'httprequest.cc',
280279
'httprequest.h',
280+
'iosfilesystem.mm',
281281
'ipaddress.cc',
282282
'ipaddress.h',
283283
'linked_ptr.h',
@@ -603,6 +603,19 @@
603603
},
604604
},
605605
},
606+
'conditions': [
607+
['target_arch=="ia32"', {
608+
'all_dependent_settings': {
609+
'link_settings': {
610+
'xcode_settings': {
611+
'OTHER_LDFLAGS': [
612+
'-framework Carbon',
613+
],
614+
},
615+
},
616+
},
617+
}],
618+
],
606619
}],
607620
['OS=="win" and nacl_untrusted_build==0', {
608621
'sources': [
@@ -651,6 +664,11 @@
651664
},
652665
}
653666
}],
667+
['OS=="ios" or (OS=="mac" and target_arch!="ia32")', {
668+
'defines': [
669+
'CARBON_DEPRECATED=YES',
670+
],
671+
}],
654672
['OS=="linux" or OS=="android"', {
655673
'sources': [
656674
'linux.cc',

webrtc/base/applefilesystem.mm renamed to webrtc/base/iosfilesystem.mm

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
* be found in the AUTHORS file in the root of the source tree.
99
*/
1010

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

1515
#import <Foundation/NSPathUtilities.h>
@@ -33,21 +33,21 @@
3333
}
3434

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

4343
// Return a (leaked) copy of a directory name suitable for use as a $TEMP.
44-
char* AppleTempDirectory() {
44+
char* IOSTempDirectory() {
4545
return copyString(NSTemporaryDirectory());
4646
}
4747

4848
// Return the binary's path.
49-
void AppleAppName(rtc::Pathname* path) {
50-
NSProcessInfo* pInfo = [NSProcessInfo processInfo];
49+
void IOSAppName(rtc::Pathname* path) {
50+
NSProcessInfo *pInfo = [NSProcessInfo processInfo];
5151
NSString* argv0 = [[pInfo arguments] objectAtIndex:0];
5252
path->SetPathname([argv0 UTF8String]);
5353
}

webrtc/base/macsocketserver.cc

+171
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,175 @@ void MacCFSocketServer::OnWakeUpCallback() {
212212
ASSERT(run_loop_ == CFRunLoopGetCurrent());
213213
CFRunLoopStop(run_loop_);
214214
}
215+
216+
///////////////////////////////////////////////////////////////////////////////
217+
// MacCarbonSocketServer
218+
///////////////////////////////////////////////////////////////////////////////
219+
#ifndef CARBON_DEPRECATED
220+
221+
const UInt32 kEventClassSocketServer = 'MCSS';
222+
const UInt32 kEventWakeUp = 'WAKE';
223+
const EventTypeSpec kEventWakeUpSpec[] = {
224+
{ kEventClassSocketServer, kEventWakeUp }
225+
};
226+
227+
std::string DecodeEvent(EventRef event) {
228+
std::string str;
229+
DecodeFourChar(::GetEventClass(event), &str);
230+
str.push_back(':');
231+
DecodeFourChar(::GetEventKind(event), &str);
232+
return str;
233+
}
234+
235+
MacCarbonSocketServer::MacCarbonSocketServer()
236+
: event_queue_(GetCurrentEventQueue()), wake_up_(NULL) {
237+
VERIFY(noErr == CreateEvent(NULL, kEventClassSocketServer, kEventWakeUp, 0,
238+
kEventAttributeUserEvent, &wake_up_));
239+
}
240+
241+
MacCarbonSocketServer::~MacCarbonSocketServer() {
242+
if (wake_up_) {
243+
ReleaseEvent(wake_up_);
244+
}
245+
}
246+
247+
bool MacCarbonSocketServer::Wait(int cms, bool process_io) {
248+
ASSERT(GetCurrentEventQueue() == event_queue_);
249+
250+
// Listen to all events if we're processing I/O.
251+
// Only listen for our wakeup event if we're not.
252+
UInt32 num_types = 0;
253+
const EventTypeSpec* events = NULL;
254+
if (!process_io) {
255+
num_types = GetEventTypeCount(kEventWakeUpSpec);
256+
events = kEventWakeUpSpec;
257+
}
258+
259+
EventTargetRef target = GetEventDispatcherTarget();
260+
EventTimeout timeout =
261+
(kForever == cms) ? kEventDurationForever : cms / 1000.0;
262+
EventTimeout end_time = GetCurrentEventTime() + timeout;
263+
264+
bool done = false;
265+
while (!done) {
266+
EventRef event;
267+
OSStatus result = ReceiveNextEvent(num_types, events, timeout, true,
268+
&event);
269+
if (noErr == result) {
270+
if (wake_up_ != event) {
271+
LOG_F(LS_VERBOSE) << "Dispatching event: " << DecodeEvent(event);
272+
result = SendEventToEventTarget(event, target);
273+
if ((noErr != result) && (eventNotHandledErr != result)) {
274+
LOG_E(LS_ERROR, OS, result) << "SendEventToEventTarget";
275+
}
276+
} else {
277+
done = true;
278+
}
279+
ReleaseEvent(event);
280+
} else if (eventLoopTimedOutErr == result) {
281+
ASSERT(cms != kForever);
282+
done = true;
283+
} else if (eventLoopQuitErr == result) {
284+
// Ignore this... we get spurious quits for a variety of reasons.
285+
LOG_E(LS_VERBOSE, OS, result) << "ReceiveNextEvent";
286+
} else {
287+
// Some strange error occurred. Log it.
288+
LOG_E(LS_WARNING, OS, result) << "ReceiveNextEvent";
289+
return false;
290+
}
291+
if (kForever != cms) {
292+
timeout = end_time - GetCurrentEventTime();
293+
}
294+
}
295+
return true;
296+
}
297+
298+
void MacCarbonSocketServer::WakeUp() {
299+
if (!IsEventInQueue(event_queue_, wake_up_)) {
300+
RetainEvent(wake_up_);
301+
OSStatus result = PostEventToQueue(event_queue_, wake_up_,
302+
kEventPriorityStandard);
303+
if (noErr != result) {
304+
LOG_E(LS_ERROR, OS, result) << "PostEventToQueue";
305+
}
306+
}
307+
}
308+
309+
///////////////////////////////////////////////////////////////////////////////
310+
// MacCarbonAppSocketServer
311+
///////////////////////////////////////////////////////////////////////////////
312+
313+
MacCarbonAppSocketServer::MacCarbonAppSocketServer()
314+
: event_queue_(GetCurrentEventQueue()) {
315+
// Install event handler
316+
VERIFY(noErr == InstallApplicationEventHandler(
317+
NewEventHandlerUPP(WakeUpEventHandler), 1, kEventWakeUpSpec, this,
318+
&event_handler_));
319+
320+
// Install a timer and set it idle to begin with.
321+
VERIFY(noErr == InstallEventLoopTimer(GetMainEventLoop(),
322+
kEventDurationForever,
323+
kEventDurationForever,
324+
NewEventLoopTimerUPP(TimerHandler),
325+
this,
326+
&timer_));
327+
}
328+
329+
MacCarbonAppSocketServer::~MacCarbonAppSocketServer() {
330+
RemoveEventLoopTimer(timer_);
331+
RemoveEventHandler(event_handler_);
332+
}
333+
334+
OSStatus MacCarbonAppSocketServer::WakeUpEventHandler(
335+
EventHandlerCallRef next, EventRef event, void *data) {
336+
QuitApplicationEventLoop();
337+
return noErr;
338+
}
339+
340+
void MacCarbonAppSocketServer::TimerHandler(
341+
EventLoopTimerRef timer, void *data) {
342+
QuitApplicationEventLoop();
343+
}
344+
345+
bool MacCarbonAppSocketServer::Wait(int cms, bool process_io) {
346+
if (!process_io && cms == 0) {
347+
// No op.
348+
return true;
349+
}
350+
if (kForever != cms) {
351+
// Start a timer.
352+
OSStatus error =
353+
SetEventLoopTimerNextFireTime(timer_, cms / 1000.0);
354+
if (error != noErr) {
355+
LOG(LS_ERROR) << "Failed setting next fire time.";
356+
}
357+
}
358+
if (!process_io) {
359+
// No way to listen to common modes and not get socket events, unless
360+
// we disable each one's callbacks.
361+
EnableSocketCallbacks(false);
362+
}
363+
RunApplicationEventLoop();
364+
if (!process_io) {
365+
// Reenable them. Hopefully this won't cause spurious callbacks or
366+
// missing ones while they were disabled.
367+
EnableSocketCallbacks(true);
368+
}
369+
return true;
370+
}
371+
372+
void MacCarbonAppSocketServer::WakeUp() {
373+
// TODO: No-op if there's already a WakeUp in flight.
374+
EventRef wake_up;
375+
VERIFY(noErr == CreateEvent(NULL, kEventClassSocketServer, kEventWakeUp, 0,
376+
kEventAttributeUserEvent, &wake_up));
377+
OSStatus result = PostEventToQueue(event_queue_, wake_up,
378+
kEventPriorityStandard);
379+
if (noErr != result) {
380+
LOG_E(LS_ERROR, OS, result) << "PostEventToQueue";
381+
}
382+
ReleaseEvent(wake_up);
383+
}
384+
385+
#endif
215386
} // namespace rtc

webrtc/base/macsocketserver.h

+58-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
#define WEBRTC_BASE_MACSOCKETSERVER_H__
1212

1313
#include <set>
14-
#include <CoreFoundation/CoreFoundation.h>
14+
#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) // Invalid on IOS
15+
#include <Carbon/Carbon.h>
16+
#endif
1517
#include "webrtc/base/physicalsocketserver.h"
1618

1719
namespace rtc {
@@ -74,6 +76,61 @@ class MacCFSocketServer : public MacBaseSocketServer {
7476
CFRunLoopRef run_loop_;
7577
CFRunLoopSourceRef wake_up_;
7678
};
79+
80+
#ifndef CARBON_DEPRECATED
81+
82+
///////////////////////////////////////////////////////////////////////////////
83+
// MacCarbonSocketServer
84+
///////////////////////////////////////////////////////////////////////////////
85+
86+
// Interacts with the Carbon event queue. While idle it will block,
87+
// waiting for events. When the socket server has work to do, it will
88+
// post a 'wake up' event to the queue, causing the thread to exit the
89+
// event loop until the next call to Wait. Other events are dispatched
90+
// to their target. Supports Carbon and Cocoa UI interaction.
91+
class MacCarbonSocketServer : public MacBaseSocketServer {
92+
public:
93+
MacCarbonSocketServer();
94+
virtual ~MacCarbonSocketServer();
95+
96+
// SocketServer Interface
97+
virtual bool Wait(int cms, bool process_io);
98+
virtual void WakeUp();
99+
100+
private:
101+
EventQueueRef event_queue_;
102+
EventRef wake_up_;
103+
};
104+
105+
///////////////////////////////////////////////////////////////////////////////
106+
// MacCarbonAppSocketServer
107+
///////////////////////////////////////////////////////////////////////////////
108+
109+
// Runs the Carbon application event loop on the current thread while
110+
// idle. When the socket server has work to do, it will post an event
111+
// to the queue, causing the thread to exit the event loop until the
112+
// next call to Wait. Other events are automatically dispatched to
113+
// their target.
114+
class MacCarbonAppSocketServer : public MacBaseSocketServer {
115+
public:
116+
MacCarbonAppSocketServer();
117+
virtual ~MacCarbonAppSocketServer();
118+
119+
// SocketServer Interface
120+
virtual bool Wait(int cms, bool process_io);
121+
virtual void WakeUp();
122+
123+
private:
124+
static OSStatus WakeUpEventHandler(EventHandlerCallRef next, EventRef event,
125+
void *data);
126+
static void TimerHandler(EventLoopTimerRef timer, void *data);
127+
128+
EventQueueRef event_queue_;
129+
EventHandlerRef event_handler_;
130+
EventLoopTimerRef timer_;
131+
};
132+
133+
#endif
77134
} // namespace rtc
78135

79136
#endif // WEBRTC_BASE_MACSOCKETSERVER_H__

0 commit comments

Comments
 (0)