summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/Selector.h
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2015-03-20 18:18:03 +0100
committerBenoit Foucher <benoit@zeroc.com>2015-03-20 18:18:03 +0100
commitc6133370d229578697c157f94b297dcc593b4a5f (patch)
tree9bbc2e3083338315393109a511e7a65d09dc9ac6 /cpp/src/Ice/Selector.h
parentRemove src directory. (diff)
downloadice-c6133370d229578697c157f94b297dcc593b4a5f.tar.bz2
ice-c6133370d229578697c157f94b297dcc593b4a5f.tar.xz
ice-c6133370d229578697c157f94b297dcc593b4a5f.zip
Added iOS support for IceTouch
Diffstat (limited to 'cpp/src/Ice/Selector.h')
-rw-r--r--cpp/src/Ice/Selector.h129
1 files changed, 129 insertions, 0 deletions
diff --git a/cpp/src/Ice/Selector.h b/cpp/src/Ice/Selector.h
index 2e70648bb68..7ca36dee887 100644
--- a/cpp/src/Ice/Selector.h
+++ b/cpp/src/Ice/Selector.h
@@ -28,6 +28,21 @@
# include <sys/poll.h>
#endif
+#if defined(ICE_USE_CFSTREAM)
+# include <IceUtil/RecMutex.h>
+# include <IceUtil/Thread.h>
+# include <set>
+
+struct __CFRunLoop;
+typedef struct __CFRunLoop * CFRunLoopRef;
+
+struct __CFRunLoopSource;
+typedef struct __CFRunLoopSource * CFRunLoopSourceRef;
+
+struct __CFSocket;
+typedef struct __CFSocket * CFSocketRef;
+#endif
+
#if defined(ICE_OS_WINRT)
# include <deque>
#endif
@@ -161,6 +176,120 @@ private:
int _queueFd;
};
+#elif defined(ICE_USE_CFSTREAM)
+
+class Selector;
+
+class SelectorReadyCallback : public IceUtil::Shared
+{
+public:
+
+ virtual ~SelectorReadyCallback() { }
+ virtual void readyCallback(SocketOperation, int = 0) = 0;
+};
+
+class StreamNativeInfo : public NativeInfo
+{
+public:
+
+ StreamNativeInfo(SOCKET fd) : NativeInfo(fd), _connectError(0)
+ {
+ }
+
+ virtual void initStreams(SelectorReadyCallback*) = 0;
+ virtual SocketOperation registerWithRunLoop(SocketOperation) = 0;
+ virtual SocketOperation unregisterFromRunLoop(SocketOperation, bool) = 0;
+ virtual void closeStreams() = 0;
+
+ void setConnectError(int error)
+ {
+ _connectError = error;
+ }
+
+private:
+
+ int _connectError;
+};
+typedef IceUtil::Handle<StreamNativeInfo> StreamNativeInfoPtr;
+
+class EventHandlerWrapper : public SelectorReadyCallback
+{
+public:
+
+ EventHandlerWrapper(const EventHandlerPtr&, Selector&);
+ ~EventHandlerWrapper();
+
+ void updateRunLoop();
+
+ virtual void readyCallback(SocketOperation, int = 0);
+
+ void ready(SocketOperation, int);
+
+ SocketOperation readyOp();
+ void checkReady();
+
+ bool update(SocketOperation, SocketOperation);
+ void finish();
+
+ bool operator<(const EventHandlerWrapper& o)
+ {
+ return this < &o;
+ }
+
+private:
+
+ friend class Selector;
+
+ EventHandlerPtr _handler;
+ StreamNativeInfoPtr _nativeInfo;
+ Selector& _selector;
+ SocketOperation _ready;
+ bool _finish;
+ CFSocketRef _socket;
+ CFRunLoopSourceRef _source;
+};
+typedef IceUtil::Handle<EventHandlerWrapper> EventHandlerWrapperPtr;
+
+class Selector : IceUtil::Monitor<IceUtil::RecMutex>
+{
+
+public:
+
+ Selector(const InstancePtr&);
+ virtual ~Selector();
+
+ void destroy();
+
+ void initialize(EventHandler*);
+ void update(EventHandler*, SocketOperation, SocketOperation);
+ void enable(EventHandler*, SocketOperation);
+ void disable(EventHandler*, SocketOperation);
+ bool finish(EventHandler*, bool);
+
+ void startSelect() { }
+ void finishSelect() { }
+ void select(std::vector<std::pair<EventHandler*, SocketOperation> >&, int);
+
+ void processInterrupt();
+ void ready(EventHandlerWrapper*, SocketOperation, int = 0);
+ void addReadyHandler(EventHandlerWrapper*);
+ void run();
+
+private:
+
+ InstancePtr _instance;
+ IceUtil::ThreadPtr _thread;
+ CFRunLoopRef _runLoop;
+ CFRunLoopSourceRef _source;
+ bool _destroyed;
+
+ std::set<EventHandlerWrapperPtr> _changes;
+
+ std::vector<EventHandlerWrapperPtr> _readyHandlers;
+ std::vector<std::pair<EventHandlerWrapperPtr, SocketOperation> > _selectedHandlers;
+ std::map<EventHandler*, EventHandlerWrapperPtr> _wrappers;
+};
+
#elif defined(ICE_USE_SELECT) || defined(ICE_USE_POLL)
class Selector