Usermode/AxWin4 - Fixing ID lookups of windows and clients
[tpg/acess2.git] / Usermode / Applications / axwin4_src / Server / CClient.cpp
1 /*
2  * Acess2 GUI v4
3  * - By John Hodge (thePowersGang)
4  *
5  * CClient.cpp
6  * - IPC Client
7  */
8 #include <CClient.hpp>
9 #include <IIPCChannel.hpp>
10 #include <ipc.hpp>
11
12 namespace AxWin {
13
14 CClient::CClient(::AxWin::IIPCChannel& channel):
15         m_channel(channel),
16         m_id(0)
17 {
18         
19 }
20
21 CClient::~CClient()
22 {
23         ::AxWin::IPC::DeregisterClient(*this);
24 }
25
26 CWindow* CClient::GetWindow(int ID)
27 {
28         try {
29                 return m_windows.at(ID);
30         }
31         catch(const std::exception& e) {
32                 return NULL;
33         }
34 }
35
36 void CClient::SetWindow(int ID, CWindow* window)
37 {
38         _SysDebug("SetWindow(ID=%i,window=%p)", ID, window);
39         auto it = m_windows.find(ID);
40         if( it != m_windows.end() ) {
41                 _SysDebug("CLIENT BUG: Window ID %i is already used by %p", ID, it->second);
42         }
43         else {
44                 m_windows[ID] = window;
45         }
46 }
47
48 void CClient::HandleMessage(CDeserialiser& message)
49 {
50         try {
51                 IPC::HandleMessage(*this, message);
52                 if( !message.IsConsumed() )
53                 {
54                         _SysDebug("NOTICE - CClient::HandleMessage - Trailing data in message");
55                 }
56         }
57         catch( const ::std::exception& e )
58         {
59                 _SysDebug("ERROR - Exception while processing message from client: %s", e.what());
60         }
61         catch( ... )
62         {
63                 _SysDebug("ERROR - Unknown exception while processing message from client");
64         }
65 }
66
67 };      // namespace AxWin
68

UCC git Repository :: git.ucc.asn.au