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

📄 channel_info.h

📁 实时监控
💻 H
字号:
#ifndef _LOGIN_INFO_H
#define _LOGIN_INFO_H

#include "ip_alias.h"

#include "../notif/notif_base.h"

/// 某主机图像通道信息
//##ModelId=3F90BABC024B
struct channel_info
{
private:
	// 这里的指针类型实际是video_channel*
	//##ModelId=3F90BABC026B
	std::vector<void*> opened;

	BOOL        loginok;
	BOOL		tcpudp_server;
	BOOL		udp_open;
	CString       _dvrname;	
	//##ModelId=3F90BABC027E
	ip_port		_ip;
	//##ModelId=3F90BABC0287
	int			channels;	///< 主机端的通道总数
	//##ModelId=3F90BABC029B
	int			priv;
	int         _window; //点播时候的旧版本的窗口号
	

public:
	//##ModelId=3F90BABC0364
	friend bool operator==(const channel_info& si1, const channel_info& si2);

	//##ModelId=3F90BABC02A5
	channel_info() { channels=0; priv=0; tcpudp_server = FALSE;udp_open = FALSE;}
     //##ModelId=3F90BABC02C3
	channel_info(CString dvrname,const ip_port& ip, int chcnt, int p,BOOL m_loginok,int window) 
	{
		logged_as(dvrname,ip, chcnt, p,m_loginok,window);
	}
	//##ModelId=3F90BABC02A6
	channel_info(ULONG ip, USHORT port, int chcnt, int p)
	{
		logged_as(ip_port(ip,port), chcnt, p);
	}
	channel_info(CString dvrname,ULONG ip, USHORT port, int chcnt, int p,BOOL m_loginok,int window)
	{
		logged_as(dvrname,ip_port(ip,port), chcnt, p,m_loginok,window);
	}
	
	
	//##ModelId=3F90BABC02D7
	channel_info(const channel_info& li) 
	{
		*this = li;
	}
	//##ModelId=3F90BABC02E1
	channel_info& operator=(const channel_info& li)
	{
		_dvrname=li._dvrname;
		_ip = li._ip;
		channels = li.channels;
		opened = li.opened;
		loginok=li.loginok;
		priv = li.priv;
		_window=li._window;
		tcpudp_server = li.tcpudp_server;
		udp_open = li.udp_open;

		return *this;
	}
	//##ModelId=3F90BABC02EB
	operator ip_port()
	{
		return _ip;
	}
	//##ModelId=3F90BABC02EC
	CString str_ip(){return _ip.str_ip();}
	CString  get_dvrname() {return _dvrname;}
	BOOL    logintrue() {return loginok;}
	int  get_window() {return _window;}
	//##ModelId=3F90BABC02ED
	ip_port get_ip_port() const {return _ip;}
	//##ModelId=3F90BABC02F6
	ULONG get_ip() const {return _ip.get_ip();}
	//##ModelId=3F90BABC0300
	ULONG get_channels() const {return channels;}
	//##ModelId=3F90BABC0309
	USHORT look_port() const {return _ip.look_port();}
	//##ModelId=3F90BABC030B
	USHORT link_port() const {return _ip.link_port();}
	//##ModelId=3F90BABC0314
	int privilege() const {return priv;}

	BOOL get_udp() const {return tcpudp_server;}

	BOOL get_opened_type() const {return udp_open;}

	void set_udp(BOOL tcp_udp) {tcpudp_server = tcp_udp;}

	void set_opened_type() 
	{
		udp_open = !udp_open;
	}
	// 登录成功
	//##ModelId=3F90BABC031D
	void logged_as(CString dvrname,const ip_port& ip, int chcnt, int p,BOOL m_loginok,int window)
	{
        _dvrname=dvrname;
		_ip = ip;
		channels = chcnt;
		priv = p;
		tcpudp_server = FALSE;
		udp_open = FALSE;
		opened.clear();
		for( int i=0; i<chcnt; i++ )
		{
			opened.push_back(NULL);
		}
		loginok=m_loginok;
		_window=window;
	}

	void logged_as(const ip_port& ip, int chcnt, int p)
	{
		_ip = ip;
		channels = chcnt;
		priv = p;
		opened.clear();
		for( int i=0; i<chcnt; i++ )
		{
			opened.push_back(NULL);
		}
	}

	// 视频通道打开
	//##ModelId=3F90BABC0331
	void open(int channel, void* p)
	{
//		NOTIFY_BOOL(on_open_chnl(channel, opened[channel], p, *this), OPEN_OUT);
		opened[channel] = p;
//OPEN_OUT:
		return;
	}
	// 视频通道关闭
	//##ModelId=3F90BABC033C
	void* close(int channel)
	{
		if( channel >= opened.size() )
			return NULL;
		
//		NOTIFY_BOOL(on_close_chnl(channel, *this), CLOSE_OUT);
		void* p = opened[channel];
		opened.size();
		opened[channel] = NULL;
//CLOSE_OUT:
		return p;
	}
	// 视频通道是否打开
	//##ModelId=3F90BABC0346
	bool is_opened(int channel)
	{
		return who(channel) != NULL;
	}

	//##ModelId=3F90BABC0359
	void* who(int channel)
	{
		return opened[channel];
	}

	//##ModelId=3F90BABC0363
	void logout()
	{
		for( int i=0; i<channels; i++ )
		{
			if( is_opened(i) )
				close(i);
		}
	}
};

inline bool operator==(const channel_info& li1, const channel_info& li2)
{
	return (li1.get_ip() == li2.get_ip()) && (li1.look_port() == li2.look_port());
}

//////////////////////////////////////////////////////////////////////////
// 已登录服务器列表信息管理
//##ModelId=3F90BABC0395
class channel_mgr
{
	//##ModelId=3F90BABD004E
	typedef std::vector<channel_info> channel_infos;
	//##ModelId=3F90BABC03A0
	channel_infos lst;

public:
	//##ModelId=3F90BABC03AA
	bool add(channel_info& li)
	{
		if( !exists(li) )
		{
			lst.push_back(li);
			return true;
		}

		return false;
	}
	//##ModelId=3F90BABC03B5
	bool remove(channel_info& x)
	{
		return remove(x.get_ip_port());
	}
	//##ModelId=3F90BABC03BF
	bool remove(const ip_port& ip)
	{
		int idx = server(ip);
		if( idx >= lst.size() )
			return false;

		if( idx != -1 )
		{
			channel_info ref = lst[idx];
			ref.logout();
			lst.erase(lst.begin()+idx);
			return true;
		}

		return false;
	}
	
	//##ModelId=3F90BABC03D2
	void clear()
	{
		for( int i=0; i<lst.size(); i++ )
		{
			channel_info& ref = lst[i];
			ref.logout();
		}
		lst.clear(); 
	}
	//##ModelId=3F90BABC03D3
	int count() const {return lst.size();}

	//##ModelId=3F90BABC03DD
	int server(const ip_port& ip)
	{
		for( int i=0; i<lst.size(); i++ )
		{
			channel_info& ref = lst[i];
			if( ref.get_ip() == ip.get_ip() &&
				ref.look_port() == ip.look_port() )
				return i;
		}
		return -1;
	}

	//##ModelId=3F90BABC03E7
	bool exists(const ip_port& ip)
	{
		return server(ip) != -1;
	}

	//##ModelId=3F90BABD0008
	channel_info& operator[](int channel)
	{
		return lst[channel];
	}

	//##ModelId=3F90BABD0013
	channel_info* find(LPCTSTR ipport)
	{
		ip_port ip(ipport);
		int idx = server(ip);
		if( idx == -1 )
			return NULL;

		return &(lst[server(ip)]);
	}
	//##ModelId=3F90BABD001C
	channel_info* find(ip_port ipport)
	{
		int idx = server(ipport);
		if( idx==-1 )
			return NULL;
		return &(lst[server(ipport)]);
	}

	//##ModelId=3F90BABD0026
	void opened(ULONG ip, USHORT port, int channel)
	{
	}

	//##ModelId=3F90BABD0032
	void closed(ULONG ip, USHORT port, int channel)
	{
	}
};

#endif	// _LOGIN_INFO_H

⌨️ 快捷键说明

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