⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 outdevicemanage.h

📁 学习java的经典教程源代码
💻 H
字号:

// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the OUTDEVICEMANAGE_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see 
// OUTDEVICEMANAGE_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#include <boost/thread/condition.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/recursive_mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/xtime.hpp>
#include <boost/bind.hpp>
#include <boost/thread/tss.hpp>
#include <boost/thread/once.hpp>
#include <stdio.h>
#include <list.h>
#include <map>

#include "mysocket.h"
#include "DeviceControlCommand.h"
#include "../swMediaPlay/sw_videoPlayServer.h" //yjl add
#include <windows.h>
using namespace std;

#ifdef OUTDEVICEMANAGE_EXPORTS
#define OUTDEVICEMANAGE_API __declspec(dllexport)
#else
#define OUTDEVICEMANAGE_API __declspec(dllimport)
#endif
    
struct SELDSFN_ITEM
{
	int realdsid;//实际dsid
	std::map<int, int> fnlist;//选择的fnid--实际fnid
};

class COutDeviceManage;
class ConnectOutDevice    //外接设备通信类
{
	typedef boost::mutex::scoped_lock lock;
private:
	bool				m_bExit;
	char				m_nportip[20];					//nport ip地址
	unsigned int		m_portnum;						//连接端口
	unsigned int		m_bh;							//编号
	int		            m_commlen;						//命令长度	
	boost::condition	m_cond;
	boost::mutex		m_mutex;
	COutDeviceManage*   m_PManage;						//设备管理指针
	DeviceControlCommand          m_ControlCommand;	    //控制命令对象
	DWORD               m_HeartTime;                     //接收心跳计时
	DWORD               m_HeartSendTime;                 //发送心跳计时
	void Wait(int ms)
	{
		boost::xtime xt1;
		boost::xtime_get(&xt1, boost::TIME_UTC);
			
		xt1.sec +=ms/1000;
		xt1.nsec+=1000*1000*(ms%1000);
		boost::mutex::scoped_lock lock(m_mutex);
		m_cond.timed_wait(lock,xt1);
	}
	void    LoginServer(CMySocket& socket);	//连接Nport
	void    MakeOnePack(unsigned char* pdata, int* nhaverecvlen);
public:	
	void    Stop();										//停止接收线程														
	void    Start();									//启动接收线程
	void    Run();										//线程函数
public:
	ConnectOutDevice(unsigned int id,  char* pnportip, unsigned int port,
					 COutDeviceManage* pmanage)
	{
		m_bh = id;
		m_portnum = port;
		m_commlen = m_ControlCommand.GetCommandLen();
		m_PManage = pmanage; 
		strcpy((char*)m_nportip, pnportip);
		m_bExit = false;
		Start();
		
	}
	~ConnectOutDevice(){}
};
///////////////////////////////////////////////////////////////////////////

class ManageOneDev
{
	typedef boost::mutex::scoped_lock lock;
public:
	OUDEV_CUR_STAT       m_curstat;                              //当前状态	
	int                  m_bh;									 //设备编号
	std::list<COMMAND>   m_commandlist;                          //命令列表

	
	int                  m_temid;                                //记录数字值
	char				 m_jmqip[20];					         //解码器ip
	int                  m_jmqport;                              //解码器开放端口
	DWORD                m_BeginTime;
	DeviceControlCommand m_concmd;
	std::map<int, SELDSFN_ITEM> m_seldsfnlist;                   //选择的ds编号 --ds fn编号列表
	HWND                m_hwnd;
	boost::mutex		m_mutex;
public:
	int                  m_temdsid;                              //临时dsid
	int                  m_temfnid;                              //临时fnid
	int                  m_curDsId;                              //当前dsid                              
	int                  m_curFnId;                              //当前fnid
	int                  m_polltimegap;							 //轮训时间间隔	
public:
	void    WriteRunLog(char* pinfo);
	void    MakeDsId(int nSubDsId);
	void    MakeFnId(int nSubFnId);
	void    ReadDsFnList();
	void    GetRealDsFnId(int nSelDsId, int nSelFnid, int* pRealDsid, int* pRealFnid);
	bool    SendControlCommand(FN_CONTROL_TYPE cmdtype);//yjl add
	void    FnPoll();									//监控点轮训
	void    CloseOneFn();
	void    WriteCurStateToIni(int dsid, int fnid);//切换图像后将dsid,fnid写入配置
public:
	void	OpenOneFn();
	void    GetBhOfRealId(int dsid, int fnid, int*temdsid, int* temfnid);//查找ds fn 编号
	void    SetCurState(OUDEV_CUR_STAT state);
	void    MakeOnePack(unsigned char* pdata, int* nhaverecvlen);
	void	PushCommand(COMMAND* pcommand)
	{
		//lock a(m_mutex);
		m_commandlist.push_back(*pcommand);
	}
	//根据当前状态,解析
	//void    Parse();
	void Parse(COMMAND tcmd);
	void    ParseSub(COMMAND cmd);
	
	ManageOneDev(int bh, char* cjmqip, int nLastDs, int nLastFn,HWND hwnd, int ijmqport):m_bh(bh),m_hwnd(hwnd)
	{
		ReadDsFnList();
		m_temdsid = -1;
		m_temfnid = -1;
		m_curDsId = nLastDs;//实际dsid
		m_curFnId = nLastFn;//实际fnid
		m_curstat = init;//当前状态
		strcpy(m_jmqip, cjmqip);//解码器ip
		m_hwnd = hwnd;
		m_jmqport = ijmqport;
		m_temid = 0;		
		m_polltimegap = GetPrivateProfileInt("POLL","POLLTIMEGAP",0,m_concmd.m_DCINIPath);
		m_BeginTime = GetTickCount();
	}
	~ManageOneDev(){}

};
//////////////////////////////////////////////////////////////////////////////////////
// This class is exported from the OutDeviceManage.dll
class OUTDEVICEMANAGE_API COutDeviceManage 
{
	typedef boost::mutex::scoped_lock lock;
private:
	bool	m_bExit;
	boost::mutex				  m_readwrite_mutex;	//读写锁	
	std::map<int, ManageOneDev*>  m_outdevlist;			//设备列表
		
	std::map<int, ConnectOutDevice*> m_ConnectList;		//连接列表
	int					m_DevCount;						//设备个数
	boost::condition	m_cond;
	boost::mutex		m_mutex;
	void Wait(int ms)
	{
		boost::xtime xt1;
		boost::xtime_get(&xt1, boost::TIME_UTC);
			
		xt1.sec +=ms/1000;
		xt1.nsec+=1000*1000*(ms%1000);
		boost::mutex::scoped_lock lock(m_mutex);
		m_cond.timed_wait(lock,xt1);
	}
private:
	
	void	Init();//读取配置文件,生成ConnectOutDevice,ManageOneDev
public:
	HWND    m_MainHwnd;
	//将命令加入ManageOneDev,调用ManageOneDev解析
	void	Dispatch(unsigned int id, COMMAND* pcommand);
	void    Stop();										//停止线程														
	void    Start();									//启动线程
	void    Run();										//线程函数,调用m_outdevlist中的ManageOneDev.Parse
	void    ReplayFn(unsigned int dsid, unsigned int fnid);//fn掉线重新上线后恢复解码器的图像
	COutDeviceManage(HWND hWndMain)
	{
		m_MainHwnd = hWndMain;
		m_bExit = false;
		Init();
	}	
	COutDeviceManage();
	~COutDeviceManage();
	
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -