#ifndef __LWCORE_H__ #define __LWCORE_H__ /************************************ REVISION LOG ENTRY Revision By: Jayanta Konjengbam Written By: Jayanta Konjengbam Revised on 12.06.2003 11:46:06 Comments: The core files for iLAP development. BT Engine also uses the core file for critical sections. Important class for the iLAP application would be the link list and the node class. For your specific needs and application, you must override or subclass the CNode class to represent a meaningful node element. ************************************/ // Define some constants for use // #define THREAD_MAX_LIFETIME_NO_AUTO_DEL 5000 #define THREAD_MAX_LIFETIME_WITH_AUTO_DEL 1000 namespace LwCoreLib { ////////////////////////////////////////////////////////////////////// // Critical Section wrapper class class CCriticalSection { public: // Constructor and Destructor CCriticalSection(); ~CCriticalSection(); // Public Operations void Lock(); void Unlock(); private: CRITICAL_SECTION m_criticalSection; }; // ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// // Win32 Thread wrapper class class CUserThread { public: friend CUserThread* CreateThreadEx( LPTHREAD_START_ROUTINE lpThreadFunc, LPVOID lpParam, LPSECURITY_ATTRIBUTES lpThreadAttributes = NULL, DWORD dwStackSize = 0L, DWORD dwCreationFlags = 0L); // Destructor virtual ~CUserThread(); // Public methods BOOL ResumeThread(); BOOL SuspendThread(); BOOL SetPriority( int nPriorityLevel ); int GetPriority(); void ExitThread(); // Incorporates clean exit too, if Wait = TRUE // Public Attributes public: DWORD m_dwThreadID; HANDLE m_hThread; BOOL m_bAutoDelete; // When object dies, thread will also be destroyed if set to TRUE BOOL m_bWait; // If set to TRUE, then a clean exit of the thread is guaranteed. protected: CUserThread(); // No implementation // Following methods are strictly forbidden private: CUserThread( const CUserThread& userThread ); // No implementation CUserThread& operator= ( const CUserThread& rUserThread ); // No implementation const bool operator== ( const CUserThread& rUserThread ); // No implementation }; // ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// // Overridable node class for link list class CNode { public: CNode() : pNext (NULL) {} virtual ~CNode() {} CNode* pNext; // To store next node private: // Forbidden functions CNode( const CNode& rNode ); CNode& operator= (const CNode& rValue ); }; // ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// // Link list class implementation class CLinkList { public: CLinkList(); // Constructor does nothing virtual ~CLinkList(); // Removes all elements in the list implicitly // Public Operations public: int Add( CNode* pNode ); // Adds a node to the list int Remove( int nIndex ); // Removes a node from the list associated with the index void RemoveAll(); // Removes all nodes and clears link list CNode* Get( int nIndex ) const; // Zero-based indexed method returning a node from given index int Size() const; // Returns size of the link-list (no. of nodes) protected: CRITICAL_SECTION m_cs; private: static CNode* m_pListBegin; // Beginning node stored here static CNode* m_pLinkList; // Link-list that contains all nodes added static int m_nRefCount; // Reference count of the nodes added. Count decrease for every remove }; // ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// // Multibyte and Wide-char conversion implementations class CStringConversion { public: static int UnicodeFromAnsi( const char* lpszStrA, wchar_t* lpStrW ); static int AnsiFromUnicode( const wchar_t* lpszStrW, char* lpStrA ); }; }; #endif //__LWCORE_H__