EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ObjCacheService.h
Go to the documentation of this file.
1 /*
2  ------------------------------------------------------------------------------------
3  LICENSE:
4  ------------------------------------------------------------------------------------
5  This file is part of EVEmu: EVE Online Server Emulator
6  Copyright 2006 - 2021 The EVEmu Team
7  For the latest information visit https://evemu.dev
8  ------------------------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  http://www.gnu.org/copyleft/lesser.txt.
22  ------------------------------------------------------------------------------------
23  Author: Zhur
24 */
25 
26 
27 #ifndef __OBJCACHE_H_INCL__
28 #define __OBJCACHE_H_INCL__
29 
30 #include "cache/ObjCacheDB.h"
31 #include "PyService.h"
32 
33 class PyDict;
34 
35 //little helper class for repeated code and memory management
37 public:
38  ObjectCachedMethodID(const char *service, const char *method);
41 };
42 
43 //little helper class for repeated code and memory management
45 public:
46  ObjectCachedSessionMethodID(const char *service, const char *method, int32 sessionValue);
49 };
50 
51 class ObjCacheService : public PyService {
52 public:
53  ObjCacheService(PyServiceMgr *mgr, const char *cacheDir);
54  virtual ~ObjCacheService();
55 
56  void PrimeCache();
57 
58  //function provided to other services:
59  typedef enum {
64  } hintSet;
65  void InsertCacheHints(hintSet hset, PyDict *into);
66 
67  PyRep *GetCacheHint(const PyRep* objectID);
68 
69  PySubStream* LoadCachedFile(const char *filename, const char *oname);
70 
71  //handlers for simple cached method calls.
72  bool IsCacheLoaded(const PyRep *objectID) const;
73  bool IsCacheLoaded(const ObjectCachedMethodID &m) const { return(IsCacheLoaded(m.objectID)); }
74  bool IsCacheLoaded(const ObjectCachedSessionMethodID &m) const { return(IsCacheLoaded(m.objectID)); }
75 
76  void InvalidateCache(const PyRep *objectID);
78 
79  void GiveCache(const PyRep *objectID, PyRep **contents);
80  void GiveCache(const ObjectCachedMethodID &m, PyRep **contents) { GiveCache(m.objectID, contents); }
81  void GiveCache(const ObjectCachedSessionMethodID &m, PyRep **contents) { GiveCache(m.objectID, contents); }
82 
83  PyObject *MakeObjectCachedMethodCallResult(const PyRep *objectID, const char *versionCheck="run");
84  PyObject *MakeObjectCachedMethodCallResult(const ObjectCachedMethodID &m, const char *versionCheck="run") { return(MakeObjectCachedMethodCallResult(m.objectID, versionCheck)); }
85 
86  PyObject *MakeObjectCachedSessionMethodCallResult(const PyRep *objectID, const char *sessionInfoName, const char *clientWhen="always");
87  PyObject *MakeObjectCachedSessionMethodCallResult(const ObjectCachedSessionMethodID &m, const char *sessionInfoName, const char *clientWhen="always") { return(MakeObjectCachedSessionMethodCallResult(m.objectID, sessionInfoName, clientWhen)); }
88 
89 protected:
90 
91  static const char *const LoginCachableObjects[];
93  static const char *const CharCreateCachableObjects[];
95  static const char *const AppearanceCachableObjects[];
97  static const char *const CharCreateNewExtraCachableObjects[];
99 
100  class Dispatcher;
101  Dispatcher *const m_dispatch;
102 
104 
105  std::string m_cacheDir;
107 
108  bool _LoadCachableObject(const PyRep *objectID);
109 
110  typedef std::map<std::string, std::string> CacheKeysMap;
111  typedef CacheKeysMap::iterator CacheKeysMapItr;
112  typedef CacheKeysMap::const_iterator CacheKeysMapConstItr;
113 
114  CacheKeysMap m_cacheKeys;
115 
116  PyCallable_DECL_CALL(GetCachableObject)
117 };
118 
119 #endif
Base Python wire object.
Definition: PyRep.h:66
std::string m_cacheDir
void InsertCacheHints(hintSet hset, PyDict *into)
std::map< std::string, std::string > CacheKeysMap
Python's dictionary.
Definition: PyRep.h:719
static const uint32 CharCreateNewExtraCachableObjectCount
ObjCacheService(PyServiceMgr *mgr, const char *cacheDir)
bool IsCacheLoaded(const ObjectCachedSessionMethodID &m) const
bool _LoadCachableObject(const PyRep *objectID)
void GiveCache(const ObjectCachedMethodID &m, PyRep **contents)
PyRep * GetCacheHint(const PyRep *objectID)
PySubStream * LoadCachedFile(const char *filename, const char *oname)
bool IsCacheLoaded(const ObjectCachedMethodID &m) const
signed __int32 int32
Definition: eve-compat.h:49
Python object.
Definition: PyRep.h:826
static const char *const AppearanceCachableObjects[]
static const uint32 AppearanceCachableObjectCount
CachedObjectMgr m_cache
static const uint32 CharCreateCachableObjectCount
virtual ~ObjCacheService()
static const uint32 LoginCachableObjectCount
static const char *const LoginCachableObjects[]
unsigned __int32 uint32
Definition: eve-compat.h:50
static const char *const CharCreateCachableObjects[]
void InvalidateCache(const PyRep *objectID)
void GiveCache(const ObjectCachedSessionMethodID &m, PyRep **contents)
CacheKeysMap::const_iterator CacheKeysMapConstItr
void GiveCache(const PyRep *objectID, PyRep **contents)
void InvalidateCache(const ObjectCachedMethodID &m)
static const char *const CharCreateNewExtraCachableObjects[]
PyObject * MakeObjectCachedSessionMethodCallResult(const ObjectCachedSessionMethodID &m, const char *sessionInfoName, const char *clientWhen="always")
#define PyCallable_DECL_CALL(n)
Definition: PyService.h:44
CacheKeysMap::iterator CacheKeysMapItr
PyObject * MakeObjectCachedMethodCallResult(const ObjectCachedMethodID &m, const char *versionCheck="run")
ObjectCachedSessionMethodID(const char *service, const char *method, int32 sessionValue)
Dispatcher *const m_dispatch
PyObject * MakeObjectCachedSessionMethodCallResult(const PyRep *objectID, const char *sessionInfoName, const char *clientWhen="always")
CacheKeysMap m_cacheKeys
PyObject * MakeObjectCachedMethodCallResult(const PyRep *objectID, const char *versionCheck="run")
ObjectCachedMethodID(const char *service, const char *method)
bool IsCacheLoaded(const PyRep *objectID) const