// CWHPaccess.h
#pragma once
#include "WPFCaller.h"

namespace Ooganizer
{
	//////////////////////////////////////////////////////////////////////
	//******************************************************************** 
	// DS access Class - Created to easily enforce critical sections and
	//					 share the statically created DS
	//******************************************************************** 
	//////////////////////////////////////////////////////////////////////
	class CWHPaccess
	{
	public:
		////
		// All these statics are put into the DS and shared accross all DLL instances
		// ~Use accessor functions below to modify these
		////
		static HINSTANCE hModule;
		static HHOOK hHook;
		static HookWndItem HList[MAX_PATH];		
		static UINT HListI;
		
		static wchar_t ALLOWED_PROCESS_NAMES[MAX_PATH][MAX_PATH];
		static UINT NUMBER_OF_ALLOWED_PROCESS_NAMES;

		static wchar_t ALLOWED_WINDOW_TITLES[MAX_PATH][MAX_PATH];
		static UINT NUMBER_OF_ALLOWED_WINDOW_TITLES;

		static wchar_t ALLOWED_WINDOW_CLASSES[MAX_PATH][MAX_PATH];
		static UINT NUMBER_OF_ALLOWED_WINDOW_CLASSES;

		static UINT nLoggingDetail;
		static wchar_t LoggingPath[MAX_PATH];

		// Hook Handle
		void set_hHook(HHOOK);
		HHOOK get_hHook();	
			
		// Clears all Shared DS segment's Hook List data 
		// (imp, when releasing the hook)
		void ClearHookSData();	

		// Allows a Caller to get a copy of all hooked Window Handles
		// and size of the hooked window list
		void GetHookedWindowListNSize(int* nbuf, int* nsize);

		////
		// Find,Insert,Deletion of HookWnd
		////
		BOOL InsertHookedWndItem(HookWndItem& Item);												
		BOOL FindHookedWnd(HWND hWnd);				
		HookWndItem GetHookedWndItem(HWND hWnd);
		BOOL SetHookedWndItem(HWND hWnd, HookWndItem& Item);
		BOOL DeleteHookedWnd(HWND hWnd);
		
		////
		// Allowed ProcessNames & WindowTitles & Classes WhiteList
		////
		void AddAllowedProcessName(wchar_t* strProcessNameInUpperCase);		
		BOOL IsAllowedProcessName(wchar_t* strProcessNameInUpperCase);	
		void AddAllowedWindowsTitle(wchar_t* strWindowsTitleInUpperCase);		
		BOOL IsAllowedWindowsTitle(wchar_t* strWindowsTitleInUpperCase);		
		void AddAllowedWindowsClass(wchar_t* strWindowsClassInUpperCase);
		BOOL IsAllowedWindowsClass(wchar_t* strWindowsClassInUpperCase);

		////
		// Get/Set and use Logging Detail Levels 
		////
		void SetLoggingDetail(LoggingDetail nLoggingDetailSetting);
		LoggingDetail GetLoggingDetail();
		wchar_t* GetLogPath();
		void SetLogPath(wchar_t* buf);

		// CRITICAL_SECTION
		void EnterCS();
		void LeaveCS();

		CWHPaccess();
		~CWHPaccess();

	private:		
		////
		// Private functions to keep track of iteration
		////		
		void deltaListTopI(int);		

		////
		// Private Helper Functions
		////
		void ClearHookItem(UINT nItem);

		//Many threads could update the DS. 
		CRITICAL_SECTION cs;
	};
}