00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Ian Kerr 00008 * Side Effects Software Inc 00009 * 123 Front Street West, Suite 1401 00010 * Toronto, Ontario 00011 * Canada M5J 2M2 00012 * 416-504-9876 00013 * 00014 * NAME: TIL_DeepSocketListener.h ( TIL Library, C++) 00015 * 00016 * COMMENTS: This class uses TIL_DeepSocketHandler to read a deep 00017 * raster from a socket in a separate thread. All methods 00018 * must be called from the main thread. 00019 */ 00020 00021 #ifndef __TIL_DeepSocketListener__ 00022 #define __TIL_DeepSocketListener__ 00023 00024 #include "TIL_API.h" 00025 #include <UT/UT_Lock.h> 00026 00027 class TIL_DeepSocketHandler; 00028 class TIL_DeepRaster; 00029 class TIL_DeepRasterReader; 00030 class UT_Thread; 00031 00032 class TIL_API TIL_DeepSocketListener { 00033 public: 00034 /// Calls terminate(). 00035 ~TIL_DeepSocketListener(); 00036 00037 /// Create an instance of TIL_DeepSocketListener. 00038 /// socket - the socket over which the deep raster will be sent. 00039 /// This instance will delete the socket when it is 00040 /// finished with it. 00041 /// reader - the deep raster reader to use. This is allocated and 00042 /// freed by the caller. 00043 static 00044 TIL_DeepSocketListener *create(UT_NetSocket *socket, 00045 TIL_DeepRasterReader *reader); 00046 00047 void setMousePosition(int x, int y); 00048 00049 /// Start/stop listening on the socket provided to create(). 00050 /// start() returns false if the socket is shut down. Successive 00051 /// calls to either method have no effect. 00052 bool start(); 00053 void stop(); 00054 00055 /// Stop listening (calls stop()) and kill the socket connection. 00056 /// Consecutive calls have no effect. Once terminated, start() and 00057 /// stop() have no effect. 00058 void terminate(bool kill_proc = false); 00059 00060 /// Return true when the socket has been closed 00061 bool isComplete() const 00062 { return !myHandler->getSocket(); } 00063 00064 /// Since the deep socket listener will run in a separate thread, it's 00065 /// necessary to lock around operations that are accessing any shared 00066 /// data in a thread-unsafe fashion. 00067 UT_Lock &getLock() { return myLock; } 00068 00069 private: 00070 TIL_DeepSocketListener(UT_NetSocket *socket, pid_t pid, 00071 TIL_DeepRasterReader *reader); 00072 00073 static void *doListenThread(void *data); 00074 00075 UT_Thread *myThread; 00076 TIL_DeepRasterReader *myReader; 00077 TIL_DeepSocketHandler *myHandler; 00078 UT_Lock myLock; 00079 bool myListening; 00080 }; 00081 00082 #endif 00083
1.5.9