// NetSDKDemo.h : PROJECT_NAME 应用程序的主头文件
//

#pragma once

#ifndef __AFXWIN_H__
	#error "在包含此文件之前包含“stdafx.h”以生成 PCH 文件"
#endif

#include "resource.h"		// 主符号


// CNetSDKDemoApp:
// 有关此类的实现，请参阅 NetSDKDemo.cpp
//
#include <map>
using namespace std;

#include "DevInfo.h"

class CSDKEvent
{
public:
	CSDKEvent(long user, long nCode, char *pRes)
	{	
		lUser = user;
		nStateCode = nCode;
		pResponse = strdup(pRes);
	};

	~CSDKEvent()
	{
		lUser = 0;
		nStateCode = 0;
		SAFE_FREE(pResponse);
	};

	LONG lUser; 
	LONG nStateCode;
	char *pResponse;
};

class SDKMSGList
{
public:
	
	SDKMSGList();
	~SDKMSGList();

	void Event_AddTail(CSDKEvent *pEvent);
	CSDKEvent* Event_RemoveHead();
	void Event_Clear();

private:

	CRITICAL_SECTION m_cs;

	CList<CSDKEvent *> m_MSGList;
};

class CNetSDKDemoApp : public CWinApp
{
public:
	CNetSDKDemoApp();
	virtual ~CNetSDKDemoApp();
// 重写
	public:
	virtual BOOL InitInstance();

// 实现

	DECLARE_MESSAGE_MAP()
public:
	void ClearMap();
	CRITICAL_SECTION m_csCMap;
	CMap <CString, LPCTSTR, CDevInfo*, CDevInfo *> m_DevList;

	SDKMSGList m_MSGDevList;
	SDKMSGList m_MSGVoice;
	SDKMSGList m_MSGConfig;

	class OnlyOneAction{
	public:
		OnlyOneAction()
		{
			mstrWho = "";
			miWhat = 0;
			miUserID = 0;
			mstrMSG = "";
		};	
		~OnlyOneAction()
		{
			mstrWho = "";
			miWhat = 0;
			miUserID = 0;
			mstrMSG = "";
		};
		CString mstrWho; // 谁干的
		int miWhat; // 干什么	0 -- 空闲,  1 -- 上传配置文件，2 -- 下载配置文件， 3 -- 固件升级， 4 -- 下载录像文件
		int miUserID;
		CString mstrMSG; // 提示信息
	}m_OnlyOneAction; // 同一时刻只能有一个在做的动作，
};

extern CNetSDKDemoApp theApp;

class CMapAutoLock
{
public:
	CMapAutoLock()
	{
		EnterCriticalSection(&theApp.m_csCMap);
	};
	~CMapAutoLock()
	{
		LeaveCriticalSection(&theApp.m_csCMap);
	};
};
