33 lines
584 B
C++
33 lines
584 B
C++
#pragma once
|
|
|
|
#include "MSConn.h"
|
|
|
|
class MSConnMgr : public a8::Singleton<MSConnMgr>
|
|
{
|
|
private:
|
|
MSConnMgr() {};
|
|
friend class a8::Singleton<MSConnMgr>;
|
|
|
|
public:
|
|
|
|
void Init();
|
|
void UnInit();
|
|
|
|
template <typename T>
|
|
void SendMsg(T& msg, long long hash_code)
|
|
{
|
|
int instance_id = (hash_code % id_hash_.size()) + 1;
|
|
MSConn* conn = GetConnById(instance_id);
|
|
if (!conn) {
|
|
abort();
|
|
}
|
|
conn->SendMsg(msg);
|
|
}
|
|
|
|
private:
|
|
MSConn* GetConnById(int instance_id);
|
|
|
|
private:
|
|
std::map<int, MSConn*> id_hash_;
|
|
};
|