You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.2 KiB
80 lines
2.2 KiB
1 month ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Threading.Tasks;
|
||
|
|
||
|
namespace Sog
|
||
|
{
|
||
|
public class ServiceMgr : Singleton<ServiceMgr>
|
||
|
{
|
||
|
private uint m_serviceSeqID;
|
||
|
|
||
|
private IReloadableService[] m_serviceTable;
|
||
|
|
||
|
|
||
|
public ServiceMgr()
|
||
|
{
|
||
|
m_serviceTable = new IReloadableService[(int)ReloadableServiceType.MaxTypeID];
|
||
|
m_serviceSeqID = 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
public uint GenNextSeqID()
|
||
|
{
|
||
|
m_serviceSeqID++;
|
||
|
|
||
|
return m_serviceSeqID;
|
||
|
}
|
||
|
|
||
|
//注册
|
||
|
public void RegisterService(IReloadableService service)
|
||
|
{
|
||
|
int iServiceType = service.GetServiceType();
|
||
|
if(iServiceType > 0 && iServiceType < (int)ReloadableServiceType.MaxTypeID)
|
||
|
{
|
||
|
if(m_serviceTable[iServiceType] != null)
|
||
|
{
|
||
|
TraceLog.Assert("service {0} already registed when register type {1} !", iServiceType, service.GetType().FullName);
|
||
|
}
|
||
|
|
||
|
Type serviceType = service.GetType();
|
||
|
|
||
|
TraceLog.Debug("service {0} register type {1} success seqID {2}", iServiceType, serviceType.FullName, service.GetServiceSeqID());
|
||
|
|
||
|
m_serviceTable[iServiceType] = service;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
TraceLog.Assert("service {0} invalid id register type {1} !", iServiceType, service.GetType().FullName);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
//根据类型返回一个service
|
||
|
public static T GetService<T>(int iServiceType)
|
||
|
{
|
||
|
if (iServiceType > 0 && iServiceType < (int)ReloadableServiceType.MaxTypeID)
|
||
|
{
|
||
|
return (T)Instance.m_serviceTable[iServiceType];
|
||
|
}
|
||
|
|
||
|
return default(T);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
//删除所有引用,显示进行对象释放
|
||
|
public void DisposeAllService()
|
||
|
{
|
||
|
for(int i=0; i< m_serviceTable.Length; i++)
|
||
|
{
|
||
|
if(m_serviceTable[i] != null)
|
||
|
{
|
||
|
m_serviceTable[i].Dispose();
|
||
|
m_serviceTable[i] = null;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|