SocketThreadManagerImp.hGo to the documentation of this file.00001 /* 00002 * Copyright (c) 2000-2003 Barak Weichselbaum <barak@komodia.com> 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 00014 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 00015 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00016 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00017 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 00018 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00019 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00020 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00021 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00022 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00023 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00024 * SUCH DAMAGE. 00025 * 00026 * Contact info: 00027 * ------------- 00028 * 00029 * Site: http://www.komodia.com 00030 * Main contact: barak@komodia.com 00031 * For custom projects, 00032 * consulting, or other 00033 * paid services: sales@komodia.com 00034 */ 00035 00036 #if !defined(AFX_SOCKETTHREADMANAGERIMP_H__09027047_1304_48DF_9547_33344AE3D88C__INCLUDED_) 00037 #define AFX_SOCKETTHREADMANAGERIMP_H__09027047_1304_48DF_9547_33344AE3D88C__INCLUDED_ 00038 00039 #if _MSC_VER > 1000 00040 #pragma once 00041 #endif // _MSC_VER > 1000 00042 00043 #include "SocketThreadManager.h" 00044 00045 #include <map> 00046 00047 KOMODIA_NAMESPACE_START 00048 00049 class CAsyncSocket; 00050 00051 class CSocketThreadManagerImp : public CSocketThreadManager 00052 { 00053 public: 00054 //Get the most available window handle, and associate a socket with it 00055 HWND GetWindowHandle(CAsyncSocket* pSocket); 00056 00057 //Remove socket from list 00058 void RemoveSocket(CAsyncSocket* pSocket); 00059 00060 //Initialize the thread manager 00061 BOOL Initialize(unsigned long ulThreadCount); 00062 00063 //Ctor and Dtor 00064 CSocketThreadManagerImp(HINSTANCE hInstance); 00065 virtual ~CSocketThreadManagerImp(); 00066 protected: 00067 //Dispatch the message 00068 virtual void ParseDispatchMessage(const MSG& rMsg, 00069 ThreadData* pData); 00070 00071 //Overide to create the extended data 00072 virtual void CreateExtendedData(ThreadDataExtend& rData); 00073 00074 //Overide when extended data is deleted 00075 virtual void DeleteExtendedData(ThreadDataExtend& rData); 00076 private: 00077 //Our map of sockets 00078 typedef std::map<int,CAsyncSocket*> SocketMap; 00079 00080 //Our data extension 00081 typedef struct _ExtensionData 00082 { 00083 CGenericCriticalSection* pCSection; 00084 SocketMap aSocketsMap; 00085 } ExtensionData; 00086 private: 00087 //Static Ctor 00088 CSocketThreadManagerImp(); 00089 private: 00090 //No copy Ctor 00091 CSocketThreadManagerImp(const CSocketThreadManagerImp& rManager); 00092 00093 //No assigment opreator 00094 CSocketThreadManagerImp& operator=(const CSocketThreadManagerImp& rManager); 00095 00096 //Add socket to the list 00097 void AddSocketToList(CAsyncSocket* pSocket, 00098 HWND hHandle); 00099 00100 //Register our window 00101 static BOOL RegisterWindow(HINSTANCE hInstance); 00102 00103 //Check if it's a socket's message 00104 static BOOL IsSocketMessage(unsigned int uiMsg); 00105 00106 //Do we have a window handle 00107 static BOOL m_bWindow; 00108 00109 //Our instance 00110 static HINSTANCE m_hInstance; 00111 00112 //Our static version 00113 static CSocketThreadManagerImp m_sCleanUp; 00114 00115 //Local instance 00116 HINSTANCE m_hLocalInstance; 00117 00118 //Are we static 00119 BOOL m_bStatic; 00120 private: 00121 //Our window proc 00122 static LRESULT CALLBACK SocketMessageHandler(HWND hwnd, // handle to window 00123 UINT uMsg, // message identifier 00124 WPARAM wParam, // first message parameter 00125 LPARAM lParam); 00126 }; 00127 00128 KOMODIA_NAMESPACE_END 00129 00130 #endif // !defined(AFX_SOCKETTHREADMANAGERIMP_H__09027047_1304_48DF_9547_33344AE3D88C__INCLUDED_) |