/* * MacGDBp * Copyright (c) 2007 - 2011, Blue Static * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU * General Public License as published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program; if not, * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ #import @class NetworkConnection; // This class is used for the CFNetwork callbacks. It is a private class and // the instance is owned by the NewtorkConnection instance. This class can be // considered an extension of NetworkConnection. class NetworkCallbackController { public: // This object should be constructed on the thread which the streams are // to be scheduled on. It will hold a weak reference to the run loop on that // thread. NetworkCallbackController(NetworkConnection* connection); // These static methods forward an invocation to the instance methods. The // last void pointer, named |self|, is the instance of this class. static void SocketAcceptCallback(CFSocketRef socket, CFSocketCallBackType callbackType, CFDataRef address, const void* data, void* self); static void ReadStreamCallback(CFReadStreamRef stream, CFStreamEventType eventType, void* self); static void WriteStreamCallback(CFWriteStreamRef stream, CFStreamEventType eventType, void* self); private: void OnSocketAccept(CFSocketRef socket, CFDataRef address, const void* data); void OnReadStreamEvent(CFReadStreamRef stream, CFStreamEventType eventType); void OnWriteStreamEvent(CFWriteStreamRef stream, CFStreamEventType eventType); // Removes the read or write stream from the run loop, closes the stream, // releases the reference. void UnscheduleReadStream(); void UnscheduleWriteStream(); // Messages the NetworkConnection's delegate and takes ownership of |error|. void ReportError(CFErrorRef error); NetworkConnection* connection_; // Weak, owns this. CFRunLoopRef runLoop_; // Weak. };