Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / src / net / net_displayer.cpp
blob9da664aaa58975a62fd02a1ed904066883f09a6f
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program 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 Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "stdnet.h"
19 #include "nel/net/net_displayer.h"
20 #include "nel/net/message.h"
21 #include "nel/net/naming_client.h"
24 using namespace std;
25 using namespace NLMISC;
27 namespace NLNET {
30 /* This index must correspond to the index for "LOG" in CallbackArray in the Logging Service
31 * (see CNetDisplayer::display())
33 const sint16 LOG_CBINDEX = 0;
37 * Constructor
39 CNetDisplayer::CNetDisplayer(bool autoConnect) :
40 _Server(NULL), _ServerAllocated (false) // disable logging otherwise an infinite recursion may occur
42 if (autoConnect) findAndConnect();
47 * Find the server (using the NS) and connect
49 void CNetDisplayer::findAndConnect()
51 if (_Server == NULL)
53 _Server = new CCallbackClient();
54 _ServerAllocated = true;
57 if ( CNamingClient::lookupAndConnect( "LOGS", *_Server ) )
59 nldebug( "Connected to logging service" );
64 * Sets logging server address
66 void CNetDisplayer::setLogServer (const CInetAddress& logServerAddr)
68 if (_Server != NULL && _Server->connected()) return;
70 _ServerAddr = logServerAddr;
72 if (_Server == NULL)
74 _Server = new CCallbackClient();
75 _ServerAllocated = true;
78 try
80 _Server->connect (_ServerAddr);
82 catch(const ESocket&)
84 // Silence
88 void CNetDisplayer::setLogServer (CCallbackClient *server)
90 if (_Server != NULL && _Server->connected()) return;
92 _Server = server;
97 * Destructor
99 CNetDisplayer::~CNetDisplayer ()
101 if (_ServerAllocated)
103 _Server->disconnect ();
104 delete _Server;
110 * Sends the string to the logging server
112 * Log format: "2000/01/15 12:05:30 <LogType> <ProcessName>: <Msg>"
114 void CNetDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *message)
118 if (_Server == NULL || !_Server->connected())
120 return;
123 bool needSpace = false;
124 //stringstream ss;
125 string str;
127 if (args.Date != 0)
129 str += dateToHumanString(args.Date);
130 needSpace = true;
133 if (args.LogType != CLog::LOG_NO)
135 if (needSpace) { str += " "; needSpace = false; }
136 str += logTypeToString(args.LogType);
137 needSpace = true;
140 if (!args.ProcessName.empty())
142 if (needSpace) { str += " "; needSpace = false; }
143 str += args.ProcessName;
144 needSpace = true;
147 if (needSpace) { str += ": "; needSpace = false; }
149 str += message;
151 CMessage msg("LOG" );
152 string s = str;
153 msg.serial( s );
154 _Server->send (msg, 0, false);
156 catch(const NLMISC::Exception& )
158 // Silence
163 } // NLNET