123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- #include <algorithm>
- #include "ClientManager.h"
- ClientManager g_ClientManager;
- ClientManager::ClientManager()
- {
- }
- ClientManager::~ClientManager()
- {
- }
- bool ClientManager::RegistClient(UINT64 Addr)
- {
- std::cout << "ClientManager::RegistClient addr: " << Addr << endl;
- Thread_Lock();
- m_ClientMap[Addr] = (LogicClient*)Addr;
- Thread_UnLock();
- return true;
- }
- bool ClientManager::RegistClient(unsigned int proc, unsigned int addr, const char* pszKey, LogicClient* client)
- {
- //std::cout << "ClientManager::RegistClient proc" << proc << " org addr " << addr << " key " << pszKey << " LogicClient addr: " << (UINT64)client << endl;
- Thread_Lock();
- /*
- char szKeys[256];
- strcpy(szKeys, pszKey);
- char* pt = szKeys;
- while (*pt != 0)
- {
- if (*pt == '/' || *pt == '{' || *pt == '}')
- *pt = '_';
- pt++;
- }
- ccos_bus_client clt(proc, addr, szKeys);*/
- ccos_bus_client clt(proc, addr, pszKey);
-
- m_ClientOpenMap[clt] = client;
- //m_ClientMap[proc<<32 | addr] = client;
- Thread_UnLock();
- return true;
- }
- void ClientManager::UnRegistAll()
- {
- //框架需要做2件事情
- //作为Client需要发送Close命令给设备
- // 没必要,在CDI传递->Local失败的情况,有对应.
- //作为Device,需要发送Close通知给Client
- // 没必要,本地驱动卸载的时候,自动发送Close给Client.
- // 非本地本进程的Client,直接清除即可.
- //问题:Bus线程和DrvTree线程中监视ROOT驱动的Client端也会被干掉
- //方案:需要清除的Client应该是非本地本进程的Client.
- // 而本地本进程的Client将会在驱动卸载的时候收到CloseNotify.
- //所以,简单方案是,本地驱动全部卸载后,进行UnRegistAll就可以了.
- Thread_Lock();
- //NOT FINISHED YET
- //need to send close notify to current clients
- m_ClientMap.clear();
- Thread_UnLock();
- }
- bool ClientManager::UnRegistClient(UINT64 Addr)
- {
- bool ret = false;
- Thread_Lock();
- map<UINT64, LogicClient*>::iterator proc_iter = m_ClientMap.find(Addr);
- if (proc_iter != m_ClientMap.end())
- {
- m_ClientMap.erase(proc_iter);
- Thread_UnLock();
- ret = true;
- }
- else
- {
- Thread_UnLock();
- //printf("Driver Thread:%d,UnRegistClient Empty\n", GetCurrentThreadId());
- }
- return ret;
- }
- bool ClientManager::UnRegistClient(unsigned int proc, unsigned int addr)
- {
- bool ret = false;
- Thread_Lock();
- map<UINT64, LogicClient*>::iterator proc_iter = m_ClientMap.find(proc<<32|addr);
- if (proc_iter != m_ClientMap.end())
- {
- m_ClientMap.erase(proc_iter);
- Thread_UnLock();
- ret = true;
- }
- else
- {
- Thread_UnLock();
- //printf("Driver Thread:%d,UnRegistClient Empty\n", GetCurrentThreadId());
- }
- return ret;
- }
- bool ClientManager::FindClient(UINT64 Addr)
- {
- bool ret = false;
- std::cout << "try find client use addr " << Addr << endl;
- Thread_Lock();
- map<UINT64, LogicClient*>::iterator proc_iter = m_ClientMap.find(Addr);
- if (proc_iter != m_ClientMap.end())
- {
- ret = true;
- }
- Thread_UnLock();
- std::cout << "Find result : " << ret <<endl;
- return ret;
- }
- LogicClient* ClientManager::GetClient(unsigned int proc, unsigned int addr , const char* pszKey)
- {
- LogicClient *ret = nullptr;
- std::cout << "ClientManager::GetClient proc " << proc << " org addr " << addr << " key " << pszKey << endl;
- /*
- char szKeys[256];
- strcpy(szKeys, pszKey);
- char* pt = szKeys;
- while (*pt != 0)
- {
- if (*pt == '/' || *pt == '{' || *pt == '}')
- *pt = '_';
- pt++;
- }
- ccos_bus_client clt(proc, addr, szKeys);*/
- ccos_bus_client clt(proc, addr, pszKey);
- Thread_Lock();
- auto proc_iter = m_ClientOpenMap.find(clt);
- if (proc_iter != m_ClientOpenMap.end())
- {
- ret = proc_iter->second;
- }
- Thread_UnLock();
- std::cout << " Find Result LogicClient " << (UINT64)ret << endl;
- return ret;
- }
|