71 lines
1.1 KiB
C++
71 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include <algorithm>
|
|
#include <list>
|
|
|
|
#include "./Uitl/CriticalSection.h"
|
|
|
|
#include "ShopSession.h"
|
|
|
|
class CSessionList
|
|
{
|
|
public:
|
|
CSessionList(void) {};
|
|
~CSessionList(void) {};
|
|
|
|
int GetSize()
|
|
{
|
|
return m_list.size();
|
|
}
|
|
|
|
void Add(DWORD_PTR Session)
|
|
{
|
|
autolock(m_cs);
|
|
m_list.push_back(Session);
|
|
}
|
|
|
|
void Remove(DWORD_PTR SessionPtr)
|
|
{
|
|
autolock(m_cs);
|
|
SESSION_LIST::iterator session = find(m_list.begin() , m_list.end() , SessionPtr);
|
|
if(m_list.end() != session)
|
|
{
|
|
m_list.erase(session);
|
|
}
|
|
}
|
|
|
|
void SendData(void* buffer, DWORD size, char* szMsg)
|
|
{
|
|
autolock(m_cs);
|
|
|
|
SESSION_LIST::iterator session;
|
|
|
|
for(session= m_list.begin() ; session != m_list.end() ; session++)
|
|
{
|
|
DWORD_PTR ptr = (*session);
|
|
if(((CShopSession*)ptr)->SendData(buffer, size))
|
|
{
|
|
BILLING_LOG(WZPUBLIC::LEVEL_INFO, "Send Success (%s)", szMsg);
|
|
}
|
|
else
|
|
{
|
|
BILLING_LOG(WZPUBLIC::LEVEL_ERROR, "Send fail (%s)", szMsg);
|
|
}
|
|
}
|
|
}
|
|
|
|
void Clear()
|
|
{
|
|
autolock(m_cs);
|
|
m_list.clear();
|
|
}
|
|
|
|
private:
|
|
|
|
typedef std::list<DWORD_PTR> SESSION_LIST;
|
|
|
|
SESSION_LIST m_list;
|
|
|
|
WZPUBLIC::CriticalSection m_cs;
|
|
};
|