Line data Source code
1 : /* Copyright (C) 2026 Wildfire Games. 2 : * This file is part of 0 A.D. 3 : * 4 : * 0 A.D. is free software: you can redistribute it and/or modify 5 : * it under the terms of the GNU General Public License as published by 6 : * the Free Software Foundation, either version 2 of the License, or 7 : * (at your option) any later version. 8 : * 9 : * 0 A.D. is distributed in the hope that it will be useful, 10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 : * GNU General Public License for more details. 13 : * 14 : * You should have received a copy of the GNU General Public License 15 : * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 : */ 17 : 18 : #include "precompiled.h" 19 : 20 : #include "MessagePasserImpl.h" 21 : 22 : #include "lib/debug.h" 23 : #include "lib/timer.h" 24 : #include "ps/CLogger.h" 25 : #include "tools/atlas/GameInterface/Handlers/MessageHandler.h" 26 : #include "tools/atlas/GameInterface/Messages.h" 27 : #include "tools/atlas/GameInterface/SharedMemory.h" 28 : 29 : #include <map> 30 : #include <string> 31 : #include <utility> 32 : 33 : using namespace AtlasMessage; 34 : 35 : double last_user_activity = 0.0; 36 : 37 0 : void MessagePasserImpl::Add(IMessage* msg) 38 : { 39 0 : ENSURE(msg); 40 0 : ENSURE(msg->GetType() == IMessage::Message); 41 : 42 0 : if (m_Trace) 43 0 : debug_printf("%8.3f add message: %s\n", timer_Time(), msg->GetName()); 44 : 45 0 : msgHandlers::const_iterator it = GetMsgHandlers().find(msg->GetName()); 46 0 : if (it != GetMsgHandlers().end()) 47 : { 48 0 : it->second(msg); 49 : } 50 : else 51 : { 52 0 : debug_warn(L"Unrecognized message"); 53 : // CLogger might not be initialised, but this error will be sent 54 : // to the debug output window anyway so people can still see it 55 0 : LOGERROR("Unrecognized message ({})", msg->GetName()); 56 : } 57 : // Delete the object - we took ownership of it. 58 0 : AtlasMessage::ShareableDelete(msg); 59 0 : } 60 : 61 0 : void MessagePasserImpl::Query(QueryMessage* msg, void(* /*timeoutCallback*/ )()) 62 : { 63 0 : ENSURE(msg); 64 0 : ENSURE(msg->GetType() == IMessage::Query); 65 : 66 0 : if (m_Trace) 67 0 : debug_printf("%8.3f add query: %s\n", timer_Time(), msg->GetName()); 68 : 69 0 : msgHandlers::const_iterator it = GetMsgHandlers().find(msg->GetName()); 70 0 : if (it != GetMsgHandlers().end()) 71 : { 72 0 : it->second(msg); 73 : } 74 : else 75 : { 76 0 : debug_warn(L"Unrecognized message"); 77 : // CLogger might not be initialised, but this error will be sent 78 : // to the debug output window anyway so people can still see it 79 0 : LOGERROR("Unrecognized message ({})", msg->GetName()); 80 : } 81 0 : } 82 : 83 0 : void MessagePasserImpl::SetTrace(bool t) 84 : { 85 0 : m_Trace = t; 86 0 : }