EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CachedObjectMgr Class Reference

#include "CachedObjectMgr.h"

Collaboration diagram for CachedObjectMgr:

Classes

class  CacheRecord
 

Public Member Functions

 ~CachedObjectMgr ()
 
bool HaveCached (const std::string &objectID) const
 
bool HaveCached (const PyRep *objectID) const
 
bool IsCacheUpToDate (const PyRep *objectID, uint32 version, int64 timestamp)
 
void InvalidateCache (const PyRep *objectID)
 
void UpdateCacheFromSS (const std::string &objectID, PySubStream **in_cached_data)
 
void UpdateCache (const std::string &objectID, PyRep **in_cached_data)
 
void UpdateCache (const PyRep *objectID, PyRep **in_cached_data)
 
PyObjectMakeCacheHint (const PyRep *objectID)
 
PyObjectMakeCacheHint (const std::string &objectID)
 
PyObjectGetCachedObject (const PyRep *objectID)
 
PyObjectGetCachedObject (const std::string &objectID)
 
PySubStreamLoadCachedFile (const char *obj_name)
 
PySubStreamLoadCachedFile (PyRep *key, const char *oname)
 
PySubStreamLoadCachedFile (const char *filename, const char *oname)
 
PyCachedObjectDecoderLoadCachedObject (const char *filename, const char *oname)
 
PyCachedCallLoadCachedCall (const char *filename, const char *oname)
 
bool LoadCachedFromFile (const std::string &cacheDir, const std::string &objectID)
 
bool LoadCachedFromFile (const std::string &cacheDir, const PyRep *objectID)
 
bool SaveCachedToFile (const std::string &cacheDir, const std::string &objectID) const
 
bool SaveCachedToFile (const std::string &cacheDir, const PyRep *objectID) const
 

Static Public Member Functions

static std::string OIDToString (const PyRep *objectID)
 

Protected Types

typedef std::map< std::string,
CacheRecord * > 
CachedObjMap
 
typedef CachedObjMap::iterator CachedObjMapItr
 
typedef
CachedObjMap::const_iterator 
CachedObjMapConstItr
 

Protected Member Functions

void GetCacheFileName (PyRep *key, std::string &into)
 
void _UpdateCache (const PyRep *objectID, PyBuffer **buffer)
 

Protected Attributes

CachedObjMap m_cachedObjects
 

Detailed Description

Definition at line 58 of file CachedObjectMgr.h.

Member Typedef Documentation

typedef std::map<std::string, CacheRecord *> CachedObjectMgr::CachedObjMap
protected

Definition at line 117 of file CachedObjectMgr.h.

typedef CachedObjMap::const_iterator CachedObjectMgr::CachedObjMapConstItr
protected

Definition at line 119 of file CachedObjectMgr.h.

typedef CachedObjMap::iterator CachedObjectMgr::CachedObjMapItr
protected

Definition at line 118 of file CachedObjectMgr.h.

Constructor & Destructor Documentation

CachedObjectMgr::~CachedObjectMgr ( )

Definition at line 91 of file CachedObjectMgr.cpp.

References m_cachedObjects, and SafeDelete().

92 {
93  CachedObjMapItr cur, end;
94  cur = m_cachedObjects.begin();
95  end = m_cachedObjects.end();
96 
97  for(; cur != end; cur++) {
98  SafeDelete( cur->second );
99  }
100 }
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
CachedObjMap m_cachedObjects
CachedObjMap::iterator CachedObjMapItr

Here is the call graph for this function:

Member Function Documentation

void CachedObjectMgr::_UpdateCache ( const PyRep objectID,
PyBuffer **  buffer 
)
protected

Definition at line 227 of file CachedObjectMgr.cpp.

References CachedObjectMgr::CacheRecord::cache, PyRep::Clone(), PyBuffer::content(), CRC32::Generate(), GetFileTimeNow(), m_cachedObjects, CachedObjectMgr::CacheRecord::objectID, OIDToString(), SafeDelete(), Buffer::size(), sLog, CachedObjectMgr::CacheRecord::timestamp, and CachedObjectMgr::CacheRecord::version.

Referenced by UpdateCache(), and UpdateCacheFromSS().

228 {
229  //this is the hard one..
230  CacheRecord *r = new CacheRecord();
231  r->timestamp = GetFileTimeNow();
232  r->objectID = objectID->Clone();
233 
234  // retake ownership
235  r->cache = *pbuf;
236  *pbuf = nullptr;
237 
238  r->version = CRC32::Generate( &r->cache->content()[0], r->cache->content().size() );
239 
240  const std::string str = OIDToString(objectID);
241 
242  //find and destroy any older version of this object.
243  CachedObjMapItr res = m_cachedObjects.find(str);
244 
245  if (res != m_cachedObjects.end()) {
246 
247  sLog.Debug("CachedObjMgr","Destroying old cached object with ID '%s' of length %u with checksum 0x%x", str.c_str(), res->second->cache->content().size(), res->second->version);
248  SafeDelete( res->second );
249  }
250 
251  sLog.Debug("CachedObjMgr","Registering new cached object with ID '%s' of length %u with checksum 0x%x", str.c_str(), r->cache->content().size(), r->version);
252 
253  m_cachedObjects[str] = r;
254 }
virtual PyRep * Clone() const =0
Clones object.
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
CachedObjMap m_cachedObjects
CachedObjMap::iterator CachedObjMapItr
static uint32 Generate(const uint8 *buf, size_t bufsize)
Definition: crc32.h:41
static std::string OIDToString(const PyRep *objectID)
double GetFileTimeNow()
Definition: utils_time.cpp:84

Here is the call graph for this function:

Here is the caller graph for this function:

PyObject * CachedObjectMgr::GetCachedObject ( const PyRep objectID)

Definition at line 285 of file CachedObjectMgr.cpp.

References PyCachedObject::cache, PyRep::Clone(), PyCachedObject::compressed, PyCachedObject::Encode(), HackCacheNodeID, m_cachedObjects, MarshalHeaderByte, PyCachedObject::nodeID, PyCachedObject::objectID, OIDToString(), PyCachedObject::shared, sLog, PyCachedObject::timestamp, and PyCachedObject::version.

Referenced by GetCachedObject().

286 {
287  const std::string str = OIDToString(objectID);
288 
289  CachedObjMapItr res = m_cachedObjects.find(str);
290  if (res == m_cachedObjects.end())
291  return nullptr;
292 
293  PyCachedObject co;
294  co.timestamp = res->second->timestamp;
295  co.version = res->second->version;
296  co.nodeID = HackCacheNodeID; //hack, doesn't matter until we have multi-node networks.
297  co.shared = true;
298  co.objectID = res->second->objectID->Clone();
299  co.cache = res->second->cache;
300 
301  if (res->second->cache->content().size() == 0 || res->second->cache->content()[0] == MarshalHeaderByte)
302  co.compressed = false;
303  else
304  co.compressed = true;
305 
306  sLog.Debug("CachedObjMgr","Returning cached object '%s' with checksum 0x%x", str.c_str(), co.version);
307 
308  PyObject* result = co.Encode();
309  co.cache = nullptr; //avoid a copy
310 
311  return result;
312 }
virtual PyRep * Clone() const =0
Clones object.
static const uint32 HackCacheNodeID
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
Python object.
Definition: PyRep.h:826
PyObject * Encode()
CachedObjMap m_cachedObjects
CachedObjMap::iterator CachedObjMapItr
static std::string OIDToString(const PyRep *objectID)
static const uint8 MarshalHeaderByte

Here is the call graph for this function:

Here is the caller graph for this function:

PyObject * CachedObjectMgr::GetCachedObject ( const std::string &  objectID)

Definition at line 276 of file CachedObjectMgr.cpp.

References GetCachedObject(), and PyDecRef.

277 {
278  //this is sub-optimal, but it keeps things more consistent (in case StringCollapseVisitor ever gets more complicated)
279  PyString* str = new PyString( objectID );
280  PyObject* obj(GetCachedObject(str));
281  PyDecRef(str);
282  return obj;
283 }
Python string.
Definition: PyRep.h:430
Python object.
Definition: PyRep.h:826
#define PyDecRef(op)
Definition: PyRep.h:57
PyObject * GetCachedObject(const PyRep *objectID)

Here is the call graph for this function:

void CachedObjectMgr::GetCacheFileName ( PyRep key,
std::string &  into 
)
protected

Definition at line 543 of file CachedObjectMgr.cpp.

References Base64::encode(), Marshal(), and Buffer::size().

Referenced by LoadCachedFile().

544 {
545  Buffer data;
546  Marshal( key, data );
547 
548  Base64::encode( &data[0], data.size(), into, false );
549 
550  std::string::size_type epos = into.find('=');
551  if (epos != std::string::npos)
552  into.resize(epos);
553 
554  into += ".cache";
555 }
bool Marshal(const PyRep *rep, Buffer &into)
Definition: EVEMarshal.cpp:36
Generic class for buffers.
Definition: Buffer.h:40
static void encode(FILE *, std::string &, bool add_crlf=true)
Definition: Base64.cpp:54
size_type size() const
Definition: Buffer.h:610

Here is the call graph for this function:

Here is the caller graph for this function:

bool CachedObjectMgr::HaveCached ( const std::string &  objectID) const

Definition at line 151 of file CachedObjectMgr.cpp.

References PyDecRef.

Referenced by ObjCacheService::_LoadCachableObject(), and ObjCacheService::IsCacheLoaded().

152 {
153  //this is very sub-optimal, but it keeps things more consistent (in case StringCollapseVisitor ever gets more complicated)
154  PyString *str = new PyString( objectID );
155  bool ret = HaveCached(str);
156  PyDecRef(str);
157  return ret;
158 }
bool HaveCached(const std::string &objectID) const
Python string.
Definition: PyRep.h:430
#define PyDecRef(op)
Definition: PyRep.h:57

Here is the caller graph for this function:

bool CachedObjectMgr::HaveCached ( const PyRep objectID) const

Definition at line 160 of file CachedObjectMgr.cpp.

References m_cachedObjects, OIDToString(), and PyIncRef.

161 {
162  PyIncRef(objectID);
163  const std::string str = OIDToString(objectID);
164 
165  return (m_cachedObjects.find(str) != m_cachedObjects.end());
166 }
CachedObjMap m_cachedObjects
#define PyIncRef(op)
Definition: PyRep.h:56
static std::string OIDToString(const PyRep *objectID)

Here is the call graph for this function:

void CachedObjectMgr::InvalidateCache ( const PyRep objectID)

Definition at line 168 of file CachedObjectMgr.cpp.

References m_cachedObjects, OIDToString(), PyIncRef, and SafeDelete().

Referenced by ObjCacheService::InvalidateCache().

169 {
170  PyIncRef(objectID);
171  const std::string str = OIDToString(objectID);
172  CachedObjMapItr res = m_cachedObjects.find(str);
173 
174  if (res != m_cachedObjects.end()) {
175  SafeDelete( res->second );
176  m_cachedObjects.erase(res);
177  }
178 }
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
CachedObjMap m_cachedObjects
CachedObjMap::iterator CachedObjMapItr
#define PyIncRef(op)
Definition: PyRep.h:56
static std::string OIDToString(const PyRep *objectID)

Here is the call graph for this function:

Here is the caller graph for this function:

bool CachedObjectMgr::IsCacheUpToDate ( const PyRep objectID,
uint32  version,
int64  timestamp 
)

Definition at line 314 of file CachedObjectMgr.cpp.

References m_cachedObjects, and OIDToString().

315 {
316  const std::string str = OIDToString(objectID);
317 
318  CachedObjMapItr res = m_cachedObjects.find(str);
319  if (res == m_cachedObjects.end())
320  return false;
321 
322  //for now, only support exact matches...
323  return ( res->second->version == version
324  && res->second->timestamp == timestamp);
325 }
CachedObjMap m_cachedObjects
CachedObjMap::iterator CachedObjMapItr
static std::string OIDToString(const PyRep *objectID)

Here is the call graph for this function:

PyCachedCall * CachedObjectMgr::LoadCachedCall ( const char *  filename,
const char *  oname 
)

Definition at line 526 of file CachedObjectMgr.cpp.

References PyCachedCall::Decode(), LoadCachedFile(), and SafeDelete().

527 {
528  PySubStream* ss = LoadCachedFile(filename, oname);
529  if ( ss == nullptr )
530  return nullptr;
531 
532  PyCachedCall *obj = new PyCachedCall();
533  if (!obj->Decode(&ss)) { //ss is consumed.
534  SafeDelete( obj );
535  return nullptr;
536  }
537 
538  return obj;
539 }
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
PySubStream * LoadCachedFile(const char *obj_name)
bool Decode(PySubStream **ss)

Here is the call graph for this function:

PySubStream * CachedObjectMgr::LoadCachedFile ( const char *  obj_name)

Definition at line 457 of file CachedObjectMgr.cpp.

References PyDecRef.

Referenced by ObjCacheService::_LoadCachableObject(), LoadCachedCall(), ObjCacheService::LoadCachedFile(), LoadCachedFile(), and LoadCachedObject().

458 {
459  PyString* str = new PyString(obj_name);
460  PySubStream* ret = LoadCachedFile(str, obj_name);
461  PyDecRef(str);
462  return ret;
463 }
Python string.
Definition: PyRep.h:430
PySubStream * LoadCachedFile(const char *obj_name)
#define PyDecRef(op)
Definition: PyRep.h:57

Here is the caller graph for this function:

PySubStream * CachedObjectMgr::LoadCachedFile ( PyRep key,
const char *  oname 
)

Definition at line 465 of file CachedObjectMgr.cpp.

References GetCacheFileName(), and LoadCachedFile().

466 {
467  std::string fname;
468  GetCacheFileName(key, fname);
469 
470  std::string abs_fname = "../data/cache/";
471  abs_fname += fname;
472 
473  return LoadCachedFile(abs_fname.c_str(), oname);
474 }
void GetCacheFileName(PyRep *key, std::string &into)
PySubStream * LoadCachedFile(const char *obj_name)

Here is the call graph for this function:

PySubStream * CachedObjectMgr::LoadCachedFile ( const char *  filename,
const char *  oname 
)
Todo:
Mem leak. new PyBuffer() never freed

Definition at line 476 of file CachedObjectMgr.cpp.

References filesize(), SafeDelete(), and sLog.

477 {
478  FILE* f = fopen( abs_fname, "rb" );
479 
480  if ( f == nullptr ) {
481  sLog.Error("CachedObjMgr","Unable to open cache file '%s' for oname '%s': %s", abs_fname, oname, strerror( errno ) );
482  return 0;
483  }
484 
485  int64 file_length = filesize( f );
486  if ( file_length == 0 )
487  {
488  sLog.Error("CachedObjMgr","Unable to stat cache file '%s' for oname '%s'", abs_fname, oname );
489  fclose( f );
490  return 0;
491  }
492 
493  Buffer* buf = new Buffer(static_cast<size_t>(file_length));
494 
495  if ( file_length != fread( &( *buf )[0], sizeof( uint8 ), static_cast<size_t>(file_length), f ) ) {
496  sLog.Error("CachedObjMgr","Unable to read cache file '%s' for oname '%s%': %s", abs_fname, oname, strerror( errno ) );
497  SafeDelete( buf );
498  fclose( f );
499  return 0;
500  }
501 
502  fclose( f );
503  sLog.Debug("CachedObjMgr","Loaded cache file for '%s': length %u", oname, file_length );
504 
506  PySubStream* res = new PySubStream( new PyBuffer( &buf ) );
507  SafeDelete( buf );
508  return res;
509 }
unsigned __int8 uint8
Definition: eve-compat.h:46
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
Generic class for buffers.
Definition: Buffer.h:40
signed __int64 int64
Definition: eve-compat.h:51
Python buffer.
Definition: PyRep.h:382
int64 filesize(const char *filename)
Obtains filesize.
Definition: misc.cpp:75

Here is the call graph for this function:

bool CachedObjectMgr::LoadCachedFromFile ( const std::string &  cacheDir,
const std::string &  objectID 
)

Definition at line 327 of file CachedObjectMgr.cpp.

References PyDecRef.

Referenced by ObjCacheService::_LoadCachableObject().

328 {
329  //this is sub-optimal, but it keeps things more consistent (in case StringCollapseVisitor ever gets more complicated)
330  PyString* str = new PyString(objectID);
331  bool ret = LoadCachedFromFile(cacheDir, str);
332  PyDecRef(str);
333  return ret;
334 }
Python string.
Definition: PyRep.h:430
#define PyDecRef(op)
Definition: PyRep.h:57
bool LoadCachedFromFile(const std::string &cacheDir, const std::string &objectID)

Here is the caller graph for this function:

bool CachedObjectMgr::LoadCachedFromFile ( const std::string &  cacheDir,
const PyRep objectID 
)

LoadCachedFromFile

Load a cached object from file.

Definition at line 341 of file CachedObjectMgr.cpp.

References CachedObjectMgr::CacheRecord::cache, CacheFileMagic, PyRep::Clone(), CacheFileHeader::length, m_cachedObjects, CacheFileHeader::magic, CachedObjectMgr::CacheRecord::objectID, OIDToString(), SafeDelete(), CacheFileHeader::timestamp, CachedObjectMgr::CacheRecord::timestamp, CacheFileHeader::version, and CachedObjectMgr::CacheRecord::version.

342 {
343  const std::string str = OIDToString(objectID);
344 
345  std::string filename(cacheDir);
346  filename += "/" + str + ".cache";
347 
348  FILE *f = fopen(filename.c_str(), "rb");
349 
350  if (f == nullptr)
351  return false;
352 
353  CacheFileHeader header;
354  if (fread(&header, sizeof(header), 1, f) != 1) {
355  fclose(f);
356  return false;
357  }
358 
359  /* check if its a valid cache file */
360  if (header.magic != CacheFileMagic) {
361  fclose(f);
362  return false;
363  }
364 
365  Buffer* buf = new Buffer( header.length );
366 
367  if ( fread( &(*buf)[0], sizeof( uint8 ), header.length, f ) != header.length ) {
368  SafeDelete( buf );
369  fclose( f );
370  return false;
371  }
372 
373  fclose( f );
374 
375  CachedObjMapItr res = m_cachedObjects.find( str );
376 
377  if ( res != m_cachedObjects.end() )
378  SafeDelete( res->second );
379 
380  CacheRecord* cache = m_cachedObjects[ str ] = new CacheRecord;
381  cache->objectID = objectID->Clone();
382  cache->cache = new PyBuffer( &buf );
383  cache->timestamp = header.timestamp;
384  cache->version = header.version;
385 
386  m_cachedObjects[ str ] = cache;
387 
388  SafeDelete( buf );
389  return true;
390 }
unsigned __int8 uint8
Definition: eve-compat.h:46
virtual PyRep * Clone() const =0
Clones object.
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
Generic class for buffers.
Definition: Buffer.h:40
const uint32 CacheFileMagic
CachedObjMap m_cachedObjects
CachedObjMap::iterator CachedObjMapItr
static std::string OIDToString(const PyRep *objectID)
Python buffer.
Definition: PyRep.h:382

Here is the call graph for this function:

PyCachedObjectDecoder * CachedObjectMgr::LoadCachedObject ( const char *  filename,
const char *  oname 
)

Definition at line 511 of file CachedObjectMgr.cpp.

References PyCachedObjectDecoder::Decode(), LoadCachedFile(), and SafeDelete().

Referenced by ObjectToSQL().

512 {
513  PySubStream* ss = LoadCachedFile(filename, oname);
514  if ( ss == nullptr )
515  return nullptr;
516 
518  if (!obj->Decode(&ss)) { //ss is consumed.
519  SafeDelete( obj );
520  return nullptr;
521  }
522 
523  return obj;
524 }
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
PySubStream * LoadCachedFile(const char *obj_name)
bool Decode(PySubStream **ss)

Here is the call graph for this function:

Here is the caller graph for this function:

PyObject * CachedObjectMgr::MakeCacheHint ( const PyRep objectID)

Definition at line 265 of file CachedObjectMgr.cpp.

References m_cachedObjects, and OIDToString().

Referenced by ObjCacheService::GetCacheHint(), MakeCacheHint(), ObjCacheService::MakeObjectCachedMethodCallResult(), and ObjCacheService::MakeObjectCachedSessionMethodCallResult().

266 {
267  const std::string str = OIDToString(objectID);
268 
269  CachedObjMapItr res = m_cachedObjects.find(str);
270  if (res == m_cachedObjects.end())
271  return nullptr;
272 
273  return res->second->EncodeHint();
274 }
CachedObjMap m_cachedObjects
CachedObjMap::iterator CachedObjMapItr
static std::string OIDToString(const PyRep *objectID)

Here is the call graph for this function:

Here is the caller graph for this function:

PyObject * CachedObjectMgr::MakeCacheHint ( const std::string &  objectID)

Definition at line 256 of file CachedObjectMgr.cpp.

References MakeCacheHint(), and PyDecRef.

257 {
258  //this is sub-optimal, but it keeps things more consistent (in case StringCollapseVisitor ever gets more complicated)
259  PyString* str = new PyString( objectID );
260  PyObject* obj(MakeCacheHint(str));
261  PyDecRef(str);
262  return obj;
263 }
Python string.
Definition: PyRep.h:430
PyObject * MakeCacheHint(const PyRep *objectID)
Python object.
Definition: PyRep.h:826
#define PyDecRef(op)
Definition: PyRep.h:57

Here is the call graph for this function:

std::string CachedObjectMgr::OIDToString ( const PyRep objectID)
static

Definition at line 139 of file CachedObjectMgr.cpp.

References PyRep::Dump(), StringCollapseVisitor::result, sLog, and PyRep::visit().

Referenced by ObjCacheService::_LoadCachableObject(), _UpdateCache(), GetCachedObject(), ObjCacheService::GetCacheHint(), HaveCached(), InvalidateCache(), IsCacheUpToDate(), LoadCachedFromFile(), MakeCacheHint(), and SaveCachedToFile().

140 {
142  if ( !objectID->visit( v ) ) {
143  sLog.Error("Cached Obj Mgr", "Failed to convert cache hind object ID into collapsed string:");
144  objectID->Dump(CACHE__DUMP, " ");
145  assert(false);
146  return "";
147  }
148  return v.result;
149 }
void Dump(FILE *into, const char *pfx) const
Dumps object to file.
Definition: PyRep.cpp:84
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
virtual bool visit(PyVisitor &v) const =0
Visits object.

Here is the call graph for this function:

Here is the caller graph for this function:

bool CachedObjectMgr::SaveCachedToFile ( const std::string &  cacheDir,
const std::string &  objectID 
) const

Definition at line 393 of file CachedObjectMgr.cpp.

References PyDecRef.

Referenced by ObjCacheService::_LoadCachableObject().

394 {
395  PyString* str = new PyString(objectID);
396  bool ret = SaveCachedToFile(cacheDir, str);
397  PyDecRef(str);
398  return ret;
399 }
Python string.
Definition: PyRep.h:430
bool SaveCachedToFile(const std::string &cacheDir, const std::string &objectID) const
#define PyDecRef(op)
Definition: PyRep.h:57

Here is the caller graph for this function:

bool CachedObjectMgr::SaveCachedToFile ( const std::string &  cacheDir,
const PyRep objectID 
) const

Definition at line 401 of file CachedObjectMgr.cpp.

References CacheFileMagic, CacheFileHeader::length, m_cachedObjects, CacheFileHeader::magic, OIDToString(), CacheFileHeader::timestamp, and CacheFileHeader::version.

402 {
403  const std::string str = OIDToString(objectID);
404  CachedObjMapConstItr res = m_cachedObjects.find(str);
405 
406  /* make sure we don't try to save a object we don't have */
407  if (res == m_cachedObjects.end())
408  return false;
409 
410  std::string filename(cacheDir);
411  filename += "/";
412  filename += str;
413  filename += ".cache";
414 
415  FILE *f = fopen(filename.c_str(), "wb");
416 
417  if (f == nullptr)
418  return false;
419 
420  CacheFileHeader header;
421  header.timestamp = res->second->timestamp;
422  header.version = res->second->version;
423  header.magic = CacheFileMagic;
424  header.length = res->second->cache->content().size();
425 
426  if (fwrite(&header, sizeof(header), 1, f) != 1) {
427  fclose(f);
428  return false;
429  }
430 
431  if (fwrite(&res->second->cache->content()[0], sizeof(uint8), header.length, f) != header.length) {
432  assert(false);
433  fclose(f);
434  return false;
435  }
436  fclose(f);
437  return true;
438 }
CachedObjMap::const_iterator CachedObjMapConstItr
unsigned __int8 uint8
Definition: eve-compat.h:46
const uint32 CacheFileMagic
CachedObjMap m_cachedObjects
static std::string OIDToString(const PyRep *objectID)

Here is the call graph for this function:

void CachedObjectMgr::UpdateCache ( const std::string &  objectID,
PyRep **  in_cached_data 
)

Definition at line 197 of file CachedObjectMgr.cpp.

References PyDecRef.

Referenced by ObjCacheService::_LoadCachableObject(), and ObjCacheService::GiveCache().

198 {
199  PyString *str = new PyString( objectID );
200  UpdateCache(str, in_cached_data);
201  PyDecRef(str);
202 }
Python string.
Definition: PyRep.h:430
void UpdateCache(const std::string &objectID, PyRep **in_cached_data)
#define PyDecRef(op)
Definition: PyRep.h:57

Here is the caller graph for this function:

void CachedObjectMgr::UpdateCache ( const PyRep objectID,
PyRep **  in_cached_data 
)

Definition at line 204 of file CachedObjectMgr.cpp.

References _UpdateCache(), MarshalDeflate(), SafeDelete(), and sLog.

205 {
206  PyRep* cached_data(*in_cached_data);
207  *in_cached_data = nullptr;
208 
209  //if (is_log_enabled(CACHE__DUMP)) {
210  // PyLogsysDump dumper(CACHE__DUMP, CACHE__DUMP, false, true);
211  //cached_data->visit(&dumper, 0);
212  //}
213 
214  Buffer* buf = new Buffer();
215  bool res = MarshalDeflate( cached_data, *buf );
216 
217  if ( res ) {
218  PyBuffer* pbuf = new PyBuffer( &buf );
219  _UpdateCache( objectID, &pbuf );
220  } else {
221  sLog.Error( "Cached Obj Mgr", "Failed to marshal or deflate new cache object." );
222  }
223 
224  SafeDelete( buf );
225 }
Base Python wire object.
Definition: PyRep.h:66
bool MarshalDeflate(const PyRep *rep, Buffer &into, const uint32 deflationLimit)
Definition: EVEMarshal.cpp:44
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
Generic class for buffers.
Definition: Buffer.h:40
void _UpdateCache(const PyRep *objectID, PyBuffer **buffer)
Python buffer.
Definition: PyRep.h:382

Here is the call graph for this function:

void CachedObjectMgr::UpdateCacheFromSS ( const std::string &  objectID,
PySubStream **  in_cached_data 
)

Definition at line 182 of file CachedObjectMgr.cpp.

References _UpdateCache(), PyCachedObjectDecoder::cache, PySubStream::data(), PyCachedObjectDecoder::Decode(), PyDecRef, and sLog.

Referenced by ObjCacheService::_LoadCachableObject().

183 {
184  PyCachedObjectDecoder cache;
185  if (!cache.Decode(in_cached_data)) {
186  sLog.Error("CachedObjMgr","Failed to decode stream");
187  return;
188  }
189 
190  PyString* str = new PyString( objectID );
191  PyBuffer* buf = cache.cache->data();
192  _UpdateCache(str, &buf);
193 
194  PyDecRef( str );
195 }
Python string.
Definition: PyRep.h:430
PyBuffer * data() const
Definition: PyRep.h:1047
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
#define PyDecRef(op)
Definition: PyRep.h:57
void _UpdateCache(const PyRep *objectID, PyBuffer **buffer)
bool Decode(PySubStream **ss)
Python buffer.
Definition: PyRep.h:382

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation


The documentation for this class was generated from the following files: