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 * Luke Moore 00008 * Side Effects Software Inc 00009 * 477 Richmond Street West 00010 * Toronto, Ontario 00011 * Canada M5V 3E7 00012 * 416-504-9876 00013 * 00014 * NAME: FS_ConnectedSocketListener.h ( FS Library, C++ ) 00015 * 00016 * COMMENTS: 00017 * This event generator listens for data that's sent to a connected 00018 * socket. When data is sent to this socket, a callback is called. 00019 * If the socket is closed, this event generator removes itself and 00020 * schedules the UI_Queue to delete it. You must create this event 00021 * generator with new and you should not keep a pointer to it. 00022 * 00023 * You probably don't want to use this class directly. Instead, you 00024 * probably want to use FS_ServerSocketListener. 00025 */ 00026 00027 #ifndef __FS_ConnectedSocketListener_h__ 00028 #define __FS_ConnectedSocketListener_h__ 00029 00030 #include "FS_API.h" 00031 #include <UT/UT_WorkBuffer.h> 00032 #include <UT/UT_String.h> 00033 #include "FS_EventGenerator.h" 00034 class UT_NetSocket; 00035 00036 class FS_API FS_ConnectedSocketListener : public FS_EventGenerator 00037 { 00038 public: 00039 typedef void (*Callback)(void *callback_data, const char *data, int length, 00040 UT_NetSocket &connection_socket); 00041 00042 // The callback is called when data has been read from the socket. The 00043 // socket is passed into the callback so it can write data out to the 00044 // socket. The ip mask restricts who is allowed to connect to this 00045 // socket. If the ip mask is null it defaults to +.+.+.+. 00046 FS_ConnectedSocketListener(UT_NetSocket &server_socket, Callback callback, 00047 void *callback_data = 0, 00048 const char *ip_mask = 0); 00049 virtual ~FS_ConnectedSocketListener(); 00050 00051 virtual const char *getClassName() const 00052 { return "FS_ConnectedSocketListener"; } 00053 bool getIsInstalled() const 00054 { return myConnectionSocket != NULL; } 00055 00056 protected: 00057 // This method returns true when there is data on the socket. 00058 virtual bool areEventsWaiting(); 00059 00060 // When there is data on the socket, this method is called. 00061 virtual int processEvents(); 00062 00063 // Return the file descriptor of the server socket. 00064 virtual int getFileDescriptor(); 00065 00066 private: 00067 void closeConnectionSocket(); 00068 00069 // Data: 00070 void *myCallbackData; 00071 Callback myCallback; 00072 UT_NetSocket *myConnectionSocket; 00073 UT_WorkBuffer myDataBuffer; 00074 bool myProcessingCallback; 00075 }; 00076 00077 #endif
1.5.9