Add infos into target window
[ryzomcore.git] / ryzom / server / src / pd_lib / pd_string_manager.cpp
blobbdd2e2c3792651027f623c34560967b62e510e26
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
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 #error "deprecated"
19 //#include "pd_string_manager.h"
20 //#include "pd_lib.h"
22 //#include <string.h>
24 //#include <nel/misc/file.h>
25 //#include <nel/misc/command.h>
26 //#include <nel/net/unified_network.h>
27 //#include <nel/net/service.h>
29 //#include "pd_lib.h"
30 //#include "timestamp.h"
32 //using namespace std;
33 //using namespace NLMISC;
34 //using namespace NLNET;
37 //namespace RY_PDS
38 //{
40 ////
41 ////
43 ////void cbStoreStringResult(CMessage& msgin, const string &serviceName, uint16 serviceId);
45 ////TUnifiedCallbackItem PDStringManagerCbArray[] =
46 ////{
47 //// { "STORE_STRING_RESULT", cbStoreStringResult },
48 ////};
50 ////void cbStoreStringResult(CMessage& msgin, const string &serviceName, uint16 serviceId)
51 ////{
52 //// if (CPDStringManager::_NbProcessingStoreStringRequests)
53 //// {
54 //// CPDStringManager::_NbProcessingStoreStringRequests--;
55 //// }
56 //// else
57 //// nlwarning("<cbStoreStringResult> received more STORE_STRING_RESULT messages than sent STORE_STRING requests");
58 ////
59 //// ucstring str;
60 //// uint32 stringId;
61 ////
62 //// msgin.serial(str);
63 //// msgin.serial(stringId);
64 ////
65 //// uint i;
66 //// for (i=0; i<CPDSLib::_Libs.size(); ++i)
67 //// {
68 //// CPDSLib* lib = CPDSLib::_Libs[i];
69 //// if (lib != NULL)
70 //// lib->getStringManager().setStringId(str, stringId);
71 //// }
72 ////}
75 //// Is net callback ready?
76 //bool CPDStringManager::_InitCb = false;
78 ///// Null String
79 //ucstring CPDStringManager::_NullStr;
81 ///// Number of store string requests that have not been processed by IOS yet
82 //uint CPDStringManager::_NbProcessingStoreStringRequests = 0;
85 ///*
86 // * Constructor
87 // */
88 //CPDStringManager::CPDStringManager()
89 //{
90 // _PDSLib = NULL;
91 // _Callback = NULL;
92 //}
95 ///*
96 // * Destructor
97 // */
98 //CPDStringManager::~CPDStringManager()
99 //{
103 ///*
104 // * Init
105 // */
106 //void CPDStringManager::init(CPDSLib* lib)
108 // //
109 // if (!_InitCb)
110 // {
111 // _InitCb = true;
112 // CUnifiedNetwork::getInstance()->addCallbackArray(PDStringManagerCbArray, sizeof(PDStringManagerCbArray)/sizeof(PDStringManagerCbArray[0]));
113 // }
115 // //
116 // _PDSLib = lib;
120 ///*
121 // * Get string entry (allocate a new entry if not yet in container)
122 // */
123 //CPDStringManager::TEntryId CPDStringManager::getEntryIdNonConst(const ucstring& str)
125 // THash hash = getHash(str);
126 // TEntryId entryId = InvalidEntryId;
128 // if (_HashTable.size() > hash)
129 // entryId = _HashTable[hash];
131 // while (entryId != InvalidEntryId)
132 // {
133 // const CStringEntry& entry = _StringEntries[entryId];
135 // if (entry.String == str)
136 // {
137 // // DONE BY NICO : this forces the lib to update the string id value of the entry. Thus, EGS callbacks are called.
138 // // The real problem is that entries are never removed from _StringEntries. So when we add a string that should have been previously removed, setStringId is never called... )
139 // setStringId(str, entry.StringId);
140 // return entryId;
141 // }
143 // entryId = entry.NextInHash;
144 // }
146 // // allocate new entry
147 // entryId = _StringEntries.size();
148 // _StringEntries.resize(entryId+1);
150 // // check hash table size
151 // if (_HashTable.size() <= hash)
152 // _HashTable.resize(PD_STRING_HASHTABLE_SIZE, InvalidEntryId);
154 // // fill new entry
155 // CStringEntry& entry = _StringEntries[entryId];
157 // entry.String = str;
158 // entry.Hash = hash;
159 // entry.NextInHash = _HashTable[hash];
161 // // link entry in hash table
162 // _HashTable[hash] = entryId;
164 // if (_PDSLib != NULL)
165 // {
166 // storeStringInIOS(str);
167 // }
169 // return entryId;
173 ///*
174 // * Compares 2 ucchar strings
175 // */
176 //bool CPDStringManager::compare(const ucchar* a, const ucchar* b)
178 // while (*a == *b && *a != 0)
179 // {
180 // ++a;
181 // ++b;
182 // }
183 // return *a == *b;
189 ///*
190 // * Explicitly add string to manager
191 // * \param eid is the associated entity id
192 // * \param string is the string to add
193 // * \return the persistant string id
194 // */
195 //void CPDStringManager::addString(NLMISC::CEntityId eid, const ucstring& str, bool addToLog)
197 // TEntryId entry = getEntryIdNonConst(str);
199 // if (_PDSLib != NULL)
200 // {
201 // // client mode, send mapping to PDS
202 // _PDSLib->addString(eid, str);
203 // }
205 // if ((_PDSLib == NULL && addToLog) || (_PDSLib != NULL && !_PDSLib->PDSUsed() && PDEnableStringLog))
206 // {
207 // // PDS mode, log mapping
208 // _Log.Actions.push_back(CLogAction());
209 // _Log.Actions.back().MapId = true;
210 // _Log.Actions.back().EntityId = eid;
211 // _Log.Actions.back().String = str;
212 // }
214 // mapEid(eid, entry);
217 ///*
218 // * Unmap EntityId
219 // */
220 //void CPDStringManager::unmap(NLMISC::CEntityId eid, bool addToLog)
222 // TEIdMap::iterator it = _EIdMap.find(eid);
223 // if (it == _EIdMap.end())
224 // return;
226 // if (_PDSLib != NULL)
227 // {
228 // // client mode, send unmapping to PDS
229 // _PDSLib->unmapString(eid);
230 // }
232 // if ((_PDSLib == NULL && addToLog) || (_PDSLib != NULL && !_PDSLib->PDSUsed() && PDEnableStringLog))
233 // {
234 // // PDS mode, log unmapping
235 // _Log.Actions.push_back(CLogAction());
236 // _Log.Actions.back().MapId = false;
237 // _Log.Actions.back().EntityId = eid;
238 // }
240 // CStringEntry& entry = _StringEntries[(*it).second];
242 // _EIdMap.erase(it);
244 // // remove from mapped eids
245 // std::vector<NLMISC::CEntityId>::iterator ite;
246 // for (ite=entry.MappedIds.begin(); ite!=entry.MappedIds.end(); )
247 // {
248 // if (*ite == eid)
249 // ite = entry.MappedIds.erase(ite);
250 // else
251 // ++ite;
252 // }
256 ///*
257 // * Set string callback
258 // * This callback is called when the string id is received from the IOS.
259 // * That is when string id is ready to be used
260 // */
261 //void CPDStringManager::setCallback(TStringCallback callback)
263 // _Callback = callback;
269 ///*
270 // * Display Manager content
271 // */
272 //void CPDStringManager::display(NLMISC::CLog* log) const
278 ///*
279 // * Serial String Manager
280 // */
281 //void CPDStringManager::serial(NLMISC::IStream& f)
283 // H_AUTO( PDSSM_SERIAL );
284 // f.serialCheck((uint32)'PDSM');
285 // uint version = f.serialVersion(0);
287 // {
288 // H_AUTO( PDSSM_SERIAL_ENTRIES );
289 // f.serialCont(_StringEntries);
290 // }
291 // {
292 // H_AUTO( PDSSM_SERIAL_EIDMAP );
293 // f.serialCont(_EIdMap);
294 // }
296 // if (f.isReading())
297 // {
298 // H_AUTO( PDSSM_SERIAL_BUILDVOLATILEDATA );
299 // buildVolatileData();
300 // }
304 ///*
305 // * Set String (PDS side)
306 // */
307 ///*
308 //bool CPDStringManager::setString(const NLMISC::CEntityId& eid, TEntryId id, const ucstring& str)
310 // bool success = true;
312 // if (id >= _StringEntries.size())
313 // {
314 // // alloc string entry
315 // _StringEntries.resize(id+1);
317 // // fill up entry
318 // CStringEntry& entry = _StringEntries[id];
320 // entry.Hash = getHash(str);
321 // entry.String = str;
323 // // link in hash table
324 // if (_HashTable.size() <= entry.Hash)
325 // _HashTable.resize(PD_STRING_HASHTABLE_SIZE, InvalidEntryId);
327 // entry.NextInHash = _HashTable[entry.Hash];
328 // }
329 // else if (_StringEntries[id].String != str)
330 // {
331 // // entry was alread filled !
332 // nlwarning("CPDStringManager::setString(): entry '%d' already set, entry is kept unchanged", id);
333 // success = false;
334 // }
336 // _EIdMap[eid] = id;
338 // return success;
340 //*/
344 ///*
345 // * Set string Id
346 // */
347 //void CPDStringManager::setStringId(const ucstring& str, TStringId id)
349 // THash hash = getHash(str);
350 // TEntryId entryId = InvalidEntryId;
352 // if (_HashTable.size() >= hash)
353 // {
354 // entryId = _HashTable[hash];
356 // while (entryId != InvalidEntryId)
357 // {
358 // CStringEntry& entry = _StringEntries[entryId];
360 // if (entry.String == str)
361 // {
362 // entry.StringId = id;
363 // _StringIdMap[id] = entryId;
364 // break;
365 // }
366 // entryId = entry.NextInHash;
367 // }
368 // }
370 // // callback
371 // if (_Callback != NULL)
372 // _Callback(str, id);
377 ///*
378 // * Build All String Associations
379 // */
380 //void CPDStringManager::buildStringAssociation()
382 // uint i;
383 // for (i=0; i<CPDSLib::_Libs.size(); ++i)
384 // {
385 // CPDSLib* lib = CPDSLib::_Libs[i];
386 // if (lib != NULL)
387 // lib->getStringManager().askAssociations();
388 // }
392 ///*
393 // * Ask Associations
394 // */
395 //void CPDStringManager::askAssociations()
397 // uint i;
398 // for (i=0; i<_StringEntries.size(); ++i)
399 // {
400 // storeStringInIOS(_StringEntries[i].String);
401 // }
407 ///*
408 // * Rebuild volatile data
409 // */
410 //void CPDStringManager::buildVolatileData()
412 // static bool alreadyBuilt = false;
414 ////#ifdef NL_DEBUG
415 //// if(alreadyBuilt)
416 //// nlstopex(("buildVolatileData() called 2 times, BEN, please fix me!!!"));
417 ////#else
418 // if(alreadyBuilt)
419 // nlwarning("buildVolatileData() called 2 times, BEN, please fix me!!!");
420 ////#endif
422 // _HashTable.clear();
424 // uint i;
425 // for (i=0; i<_StringEntries.size(); ++i)
426 // {
427 // CStringEntry& entry = _StringEntries[i];
429 // entry.Hash = getHash(entry.String);
431 // if (_HashTable.size() <= entry.Hash)
432 // _HashTable.resize(PD_STRING_HASHTABLE_SIZE, InvalidEntryId);
434 // entry.NextInHash = _HashTable[entry.Hash];
435 // _HashTable[entry.Hash] = i;
437 // entry.MappedIds.clear();
438 // }
440 // TEIdMap::const_iterator it;
441 // for (it=_EIdMap.begin(); it!=_EIdMap.end(); ++it)
442 // {
443 // CStringEntry& entry = _StringEntries[(*it).second];
444 // entry.MappedIds.push_back((*it).first);
445 // }
447 // alreadyBuilt = true;
451 ///*
452 // * Load String manager default file (to be used by client when PDS is not connected)
453 // */
454 //bool CPDStringManager::load()
456 // if (_PDSLib == NULL)
457 // return false;
459 // std::string logDir = _PDSLib->getLogDirectory();
461 // if (!CFile::isDirectory(logDir))
462 // {
463 // if (!CFile::createDirectoryTree(logDir))
464 // {
465 // nlwarning("Failed to create log root directory '%s'", logDir.c_str());
466 // }
468 // if (!CFile::setRWAccess(logDir))
469 // {
470 // nlwarning("Failed, can't set RW access to directory '%s'", logDir.c_str());
471 // }
472 // }
474 // return load(logDir);
477 ///*
478 // * Save String manager default file (to be used by client when PDS is not connected)
479 // */
480 //bool CPDStringManager::save()
482 // if (_PDSLib == NULL)
483 // return false;
485 // std::string logDir = _PDSLib->getLogDirectory();
487 // if (!CFile::isDirectory(logDir))
488 // {
489 // if (!CFile::createDirectoryTree(logDir))
490 // {
491 // nlwarning("Failed to create log root directory '%s'", logDir.c_str());
492 // }
494 // if (!CFile::setRWAccess(logDir))
495 // {
496 // nlwarning("Failed, can't set RW access to directory '%s'", logDir.c_str());
497 // }
498 // }
500 // return save(logDir);
503 ///*
504 // * Load String manager file
505 // */
506 //bool CPDStringManager::load(const std::string& path)
508 // std::string filename = getFile(path);
510 // if (!CFile::fileExists(filename))
511 // {
512 // nlinfo("CPDStringManager::load(): file '%s' doesn't exist, assumes string manager empty", filename.c_str());
513 // return true;
514 // }
516 // CIFile file;
517 // if (!file.open(filename))
518 // {
519 // nlwarning("CPDStringManager::load(): failed to load file '%s', string manager left as is", filename.c_str());
520 // return false;
521 // }
523 // try
524 // {
525 // serial(file);
526 // }
527 // catch (Exception& e)
528 // {
529 // nlwarning("CPDStringManager::load(): failed to load file '%s', exception in serial '%s'", filename.c_str(), e.what());
530 // return false;
531 // }
533 // return true;
536 ///*
537 // * Save String manager file
538 // */
539 //bool CPDStringManager::save(const std::string& path)
541 // std::string filename = getFile(path);
543 // COFile file;
544 // if (!file.open(filename))
545 // {
546 // nlwarning("CPDStringManager::save(): failed to save file '%s', string manager left as is", filename.c_str());
547 // return false;
548 // }
550 // try
551 // {
552 // serial(file);
553 // }
554 // catch (Exception& e)
555 // {
556 // nlwarning("CPDStringManager::save(): failed to save file '%s', exception in serial '%s'", filename.c_str(), e.what());
557 // return false;
558 // }
560 // return true;
563 ///*
564 // * Get String manager filename
565 // */
566 //std::string CPDStringManager::getFile(const std::string& path)
568 // return CPath::standardizePath(path) + "string_manager.bin";
572 ///*
573 // * Apply log
574 // */
575 //bool CPDStringManager::applyLog(NLMISC::IStream& s)
577 // try
578 // {
579 // s.serial(_Log);
580 // }
581 // catch (Exception &e)
582 // {
583 // nlwarning("CPDStringManager::applyLog(): failed to apply log from stream, exception in serial '%s'", e.what());
584 // return false;
585 // }
587 // uint i;
588 // for (i=0; i<_Log.Actions.size(); ++i)
589 // {
590 // CLogAction& action = _Log.Actions[i];
592 // if (action.MapId)
593 // {
594 // addString(action.EntityId, action.String, false);
595 // }
596 // else
597 // {
598 // unmap(action.EntityId, false);
599 // }
600 // }
602 // _Log.Actions.clear();
604 // return true;
607 ///*
608 // * Store log
609 // */
610 //bool CPDStringManager::storeLog(NLMISC::IStream& s)
612 // try
613 // {
614 // s.serial(_Log);
615 // }
616 // catch (Exception &e)
617 // {
618 // nlwarning("CPDStringManager::storeLog(): failed to store log to stream, exception in serial '%s'", e.what());
619 // return false;
620 // }
622 // _Log.Actions.clear();
624 // return true;
627 ///*
628 // * Is log file
629 // */
630 //bool CPDStringManager::isLogFileName(const std::string& filename, CTimestamp& timestamp)
632 // char buffer[32];
633 // if (NLMISC::CFile::getExtension(filename) != "xml" ||
634 // sscanf(NLMISC::CFile::getFilenameWithoutExtension(filename).c_str(), "string_%s", &buffer) != 1)
635 // return false;
636 // timestamp.fromString(buffer);
637 // return true;
640 ///*
641 // * Store string in IOS
642 // */
643 //void CPDStringManager::storeStringInIOS(const ucstring& str)
645 // CMessage msgios("STORE_STRING");
646 // msgios.serial( const_cast<ucstring&>(str) );
647 // CUnifiedNetwork::getInstance()->send("IOS", msgios);
649 // _NbProcessingStoreStringRequests++;
652 ///*
653 // * Returns true if IOS has not processed all store string requests
654 // */
655 //bool CPDStringManager::isWaitingIOSStoreStringResult()
657 // return (_NbProcessingStoreStringRequests != 0);