StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StHyperCacheManager.h
1 #ifndef __ST_HYPERCACHEMANAGER_H
2 #define __ST_HYPERCACHEMANAGER_H
3 
4 #include "StDbBuffer.h"
5 #include "StHyperCacheI.h"
6 #include <mysql.h>
7 #include "picojson.h"
8 
10 {
11 
12 public:
15 
16  bool init();
17 
18  const char* get(const std::string& group_key, const std::string& key, size_t& value_length);
19  bool set(const std::string& group_key, const std::string& key, const char* data, size_t dataLength, time_t expirationTime = 0);
20  bool set(const std::string& group_key, const std::string& key, MYSQL_RES* result, time_t expirationTime = 0);
21  bool replace(const std::string& group_key, const std::string& key, const char* data, size_t dataLength, time_t expirationTime = 0);
22  bool remove (const std::string& group_key, const std::string& key);
23  void clear();
24 
25  std::string getStat();
26  const std::string& getName() { return m_Name; };
27  const std::string& getVersion() { return m_Version; };
28  const std::string& getType() { return m_Type; };
29 
30  const std::string& getLastGroupKey() { return m_LastGroupKey; }
31  const std::string& getLastKey() { return m_LastKey; }
32 
33  size_t getNumRows() { return m_NumRows; }
34  size_t getNumFields() { return m_NumFields; }
35 
36  bool setParameter(const std::string& param, const std::string& value);
37 
38  bool isActive() { return m_Active; }
39  bool isValueFound() { return m_ValueFound; }
40 
41  bool processOutput(StDbBuffer* aBuff);
42 
43 protected:
44 
45  bool readParametersFromJsonFile(); // read JSON-encoded params from config file
46  std::string convertMysqlResultToJson(MYSQL_RES* result);
47  bool parseJsonBuffer(); // parse raw buffer into traversable JSON document
48  bool isJsonError(); // check json document to see if it contains db error conditions
49  void calculateRowsFields(); // scan json document, get number of rows and fields
50  char** DecodeStrArray(const char* strinput , int &aLen); // copied from MysqlDb.cc, used to break comma-separated string of numbers into char array
51 
52  std::string m_Name; // cache name - not critical for Manager, just part of interface
53  std::string m_Version; // cache version --||--
54  std::string m_Type; // cache type --||--
55 
56  bool m_ValueFound; // was value found in any cache from the list?
57 
58  bool m_Active; // if config was not found, manager is deactivated
59 
60  std::string m_PathToConfigFile; // configuration file location, from env.var
61 
62  char* m_JsonBuffer; // raw json buffer
63  size_t m_JsonBufferSize; // raw json buffer size
64  size_t m_NumRows; // number of rows in parsed json buffer
65  size_t m_NumFields; // number of fields in parsed json buffer
66  picojson::array m_JsonDocument; // parsed json document
67  picojson::array::const_iterator m_JsonDocumentIter; // json document iterator, pointing at current row
68 
69  std::string m_LastGroupKey;
70  std::string m_LastKey;
71 
72  std::vector<StHyperCacheI*> m_CacheImp;
73 
74 };
75 
76 #endif // __ST_HYPERCACHE_MANAGER_H