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

📄 ~channel_info.~h

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

#include "ip_alias.h"

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

/// 某主机图像通道信息
struct channel_info
{
private:
	// 这里的指针类型实际是video_channel*
	std::vector<void*> opened;
	
	ip_port		_ip;
	int			channels;	///< 主机端的通道总数
	int			priv;

public:
	friend bool operator==(const channel_info& si1, const channel_info& si2);

	channel_info() { channels=0; priv=0; }
	channel_info(ULONG ip, USHORT port, int chcnt, int p)
	{
		logged_as(ip_port(ip,port), chcnt, p);
	}
	channel_info(const ip_port& ip, int chcnt, int p) {logged_as(ip, chcnt, p);}
	channel_info(const channel_info& li) 
	{
		*this = li;
	}
	channel_info& operator=(const channel_info& li)
	{
		_ip = li._ip;
		channels = li.channels;
		opened = li.opened;
		priv = li.priv;
//		cb = li.cb;

		return *this;
	}
	operator ip_port()
	{
		return _ip;
	}
	CString str_ip(){return _ip.str_ip();}
	ip_port get_ip_port() const {return _ip;}
	ULONG get_ip() const {return _ip.get_ip();}
	ULONG get_channels() const {return channels;}
	USHORT look_port() const {return _ip.look_port();}
	USHORT link_port() const {return _ip.link_port();}
	int privilege() const {return priv;}
	// 登录成功
	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);
		}
	}

	// 视频通道打开
	void open(int channel, void* p)
	{
//		NOTIFY_BOOL(on_open_chnl(channel, opened[channel], p, *this), OPEN_OUT);
		opened[channel] = p;
//OPEN_OUT:
		return;
	}
	// 视频通道关闭
	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;
	}
	// 视频通道是否打开
	bool is_opened(int channel)
	{
		return who(channel) != NULL;
	}

	void* who(int channel)
	{
		return opened[channel];
	}

	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());
}

//////////////////////////////////////////////////////////////////////////
// 已登录服务器列表信息管理
class channel_mgr
{
	typedef std::vector<channel_info> channel_infos;
	channel_infos lst;

public:
	bool add(channel_info& li)
	{
		if( !exists(li) )
		{
			lst.push_back(li);
			return true;
		}

		return false;
	}
	bool remove(channel_info& x)
	{
		return remove(x.get_ip_port());
	}
	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;
	}
	
	void clear()
	{
		for( int i=0; i<lst.size(); i++ )
		{
			channel_info& ref = lst[i];
			ref.logout();
		}
		lst.clear(); 
	}
	int count() const {return lst.size();}

	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;
	}

	bool exists(const ip_port& ip)
	{
		return server(ip) != -1;
	}

	channel_info& operator[](int channel)
	{
		return lst[channel];
	}

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

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

	void opened(ULONG ip, USHORT port, int channel)
	{
	}

	void closed(ULONG ip, USHORT port, int channel)
	{
	}
};

#endif	// _LOGIN_INFO_H

⌨️ 快捷键说明

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