MythTV  master
dsmcccache.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) David C.J. Matthews 2005, 2006
3  * Derived from dsmcc by Richard Palmer
4  */
5 #ifndef DSMCC_CACHE_H
6 #define DSMCC_CACHE_H
7 
8 #include <utility>
9 
10 // Qt headers
11 #include <QMap>
12 #include <QStringList>
13 
14 class BiopBinding;
15 
16 class DSMCCCacheFile;
17 class DSMCCCacheDir;
18 class DSMCCCache;
19 class Dsmcc;
20 
21 class DSMCCCacheKey: public QByteArray
22 {
23  public:
24  DSMCCCacheKey() = default;
25  DSMCCCacheKey(const char * data, int size):
26  QByteArray(data, size) {}
27  QString toString(void) const;
28  // Operator used in < for DSMCCCacheReference
29  friend bool operator < (const DSMCCCacheKey &key1,
30  const DSMCCCacheKey &key2);
31 };
32 
34 {
35  public:
36  DSMCCCacheReference() = default;
37  DSMCCCacheReference(unsigned long car, unsigned short m,
38  unsigned short s, DSMCCCacheKey k) :
39  m_nCarouselId(car), m_nModuleId(m),
40  m_nStreamTag(s), m_key(std::move(k)) {}
41 
42  DSMCCCacheReference(const DSMCCCacheReference&) = default;
44 
45  bool Equal(const DSMCCCacheReference &r) const;
46  bool Equal(const DSMCCCacheReference *p) const;
47 
48  QString toString(void) const;
49 
50  public:
51  unsigned long m_nCarouselId {0}; // Reference info for the module
52  unsigned short m_nModuleId {0};
53  unsigned short m_nStreamTag {0};
55 
56  // Operator required for QMap
57  friend bool operator < (const DSMCCCacheReference &ref1,
58  const DSMCCCacheReference &ref2);
59 };
60 
61 // A directory
63 {
64  public:
65  DSMCCCacheDir() = default;
66  explicit DSMCCCacheDir(const DSMCCCacheReference &r) : m_reference(r) {}
67 
68  // These maps give the cache reference for each name
69  QMap<QString, DSMCCCacheReference> m_subDirectories;
70  QMap<QString, DSMCCCacheReference> m_files;
71 
73 };
74 
75 // The contents of a file.
77 {
78  public:
79  DSMCCCacheFile() = default;
80  explicit DSMCCCacheFile(const DSMCCCacheReference &r) : m_reference(r) {}
81 
83  QByteArray m_contents; // Contents of the file.
84 };
85 
87 {
88  public:
89  explicit DSMCCCache(Dsmcc *dsmcc);
90  ~DSMCCCache();
91 
92  // Create a new gateway.
94  // Create a new directory.
96  // Add a file to the directory or gateway.
97  static void AddFileInfo(DSMCCCacheDir *dir, const BiopBinding *pBB);
98  // Add a directory to the directory or gateway.
99  static void AddDirInfo(DSMCCCacheDir *dir, const BiopBinding *pBB);
100 
101  // Add the contents of a file.
102  void CacheFileData(const DSMCCCacheReference &ref, const QByteArray &data);
103 
104  // Set the gateway reference from a DSI message.
105  void SetGateway(const DSMCCCacheReference &ref);
106 
107  // Return the contents.
108  int GetDSMObject(QStringList &objectPath, QByteArray &result);
109 
110  protected:
111  // Find File, Directory or Gateway by reference.
115 
116  DSMCCCacheReference m_gatewayRef; // Reference to the gateway
117 
118  // The set of directories, files and gateways.
119  QMap<DSMCCCacheReference, DSMCCCacheDir*> m_directories;
120  QMap<DSMCCCacheReference, DSMCCCacheDir*> m_gateways;
121  QMap<DSMCCCacheReference, DSMCCCacheFile*> m_files;
122 
123  public:
124  Dsmcc *m_dsmcc {nullptr};
125 };
126 
127 #endif
DSMCCCache::GetDSMObject
int GetDSMObject(QStringList &objectPath, QByteArray &result)
Definition: dsmcccache.cpp:274
DSMCCCacheReference::toString
QString toString(void) const
Definition: dsmcccache.cpp:97
DSMCCCacheReference::DSMCCCacheReference
DSMCCCacheReference()=default
DSMCCCacheFile::m_contents
QByteArray m_contents
Definition: dsmcccache.h:83
DSMCCCache::SetGateway
void SetGateway(const DSMCCCacheReference &ref)
Definition: dsmcccache.cpp:320
DSMCCCache::m_gatewayRef
DSMCCCacheReference m_gatewayRef
Definition: dsmcccache.h:116
DSMCCCache::m_dsmcc
Dsmcc * m_dsmcc
Definition: dsmcccache.h:124
DSMCCCache::FindGateway
DSMCCCacheDir * FindGateway(const DSMCCCacheReference &ref)
Definition: dsmcccache.cpp:257
DSMCCCacheDir::DSMCCCacheDir
DSMCCCacheDir(const DSMCCCacheReference &r)
Definition: dsmcccache.h:66
DSMCCCacheReference::m_nCarouselId
unsigned long m_nCarouselId
Definition: dsmcccache.h:51
DSMCCCache::AddFileInfo
static void AddFileInfo(DSMCCCacheDir *dir, const BiopBinding *pBB)
Definition: dsmcccache.cpp:199
DSMCCCache::AddDirInfo
static void AddDirInfo(DSMCCCacheDir *dir, const BiopBinding *pBB)
Definition: dsmcccache.cpp:216
DSMCCCache
Definition: dsmcccache.h:86
DSMCCCache::FindDir
DSMCCCacheDir * FindDir(const DSMCCCacheReference &ref)
Definition: dsmcccache.cpp:245
DSMCCCacheReference::m_key
DSMCCCacheKey m_key
Definition: dsmcccache.h:54
DSMCCCache::m_files
QMap< DSMCCCacheReference, DSMCCCacheFile * > m_files
Definition: dsmcccache.h:121
DSMCCCache::Directory
DSMCCCacheDir * Directory(const DSMCCCacheReference &ref)
Definition: dsmcccache.cpp:150
DSMCCCacheReference::operator=
DSMCCCacheReference & operator=(const DSMCCCacheReference &)=default
DSMCCCacheFile::DSMCCCacheFile
DSMCCCacheFile()=default
DSMCCCache::FindFileData
DSMCCCacheFile * FindFileData(const DSMCCCacheReference &ref)
Definition: dsmcccache.cpp:233
DSMCCCacheReference::m_nStreamTag
unsigned short m_nStreamTag
Definition: dsmcccache.h:53
DSMCCCacheDir::m_reference
DSMCCCacheReference m_reference
Definition: dsmcccache.h:72
DSMCCCacheFile
Definition: dsmcccache.h:76
DSMCCCacheDir
Definition: dsmcccache.h:62
DSMCCCacheFile::DSMCCCacheFile
DSMCCCacheFile(const DSMCCCacheReference &r)
Definition: dsmcccache.h:80
hardwareprofile.config.p
p
Definition: config.py:33
BiopBinding
Definition: dsmccbiop.h:151
DSMCCCache::Srg
DSMCCCacheDir * Srg(const DSMCCCacheReference &ref)
Definition: dsmcccache.cpp:127
DSMCCCacheFile::m_reference
DSMCCCacheReference m_reference
Definition: dsmcccache.h:82
DSMCCCacheReference::DSMCCCacheReference
DSMCCCacheReference(unsigned long car, unsigned short m, unsigned short s, DSMCCCacheKey k)
Definition: dsmcccache.h:37
DSMCCCacheReference::operator<
friend bool operator<(const DSMCCCacheReference &ref1, const DSMCCCacheReference &ref2)
Definition: dsmcccache.cpp:105
DSMCCCache::~DSMCCCache
~DSMCCCache()
Definition: dsmcccache.cpp:37
DSMCCCacheKey::DSMCCCacheKey
DSMCCCacheKey(const char *data, int size)
Definition: dsmcccache.h:25
DSMCCCacheDir::DSMCCCacheDir
DSMCCCacheDir()=default
Dsmcc
Definition: dsmcc.h:77
DSMCCCacheKey
Definition: dsmcccache.h:21
DSMCCCacheDir::m_subDirectories
QMap< QString, DSMCCCacheReference > m_subDirectories
Definition: dsmcccache.h:69
DSMCCCacheReference::m_nModuleId
unsigned short m_nModuleId
Definition: dsmcccache.h:52
DSMCCCache::CacheFileData
void CacheFileData(const DSMCCCacheReference &ref, const QByteArray &data)
Definition: dsmcccache.cpp:173
DSMCCCacheReference::Equal
bool Equal(const DSMCCCacheReference &r) const
Definition: dsmcccache.cpp:84
DSMCCCacheKey::operator<
friend bool operator<(const DSMCCCacheKey &key1, const DSMCCCacheKey &key2)
Definition: dsmcccache.cpp:62
DSMCCCacheKey::DSMCCCacheKey
DSMCCCacheKey()=default
DSMCCCache::DSMCCCache
DSMCCCache(Dsmcc *dsmcc)
Definition: dsmcccache.cpp:31
DSMCCCache::m_gateways
QMap< DSMCCCacheReference, DSMCCCacheDir * > m_gateways
Definition: dsmcccache.h:120
DSMCCCacheKey::toString
QString toString(void) const
Definition: dsmcccache.cpp:53
DSMCCCache::m_directories
QMap< DSMCCCacheReference, DSMCCCacheDir * > m_directories
Definition: dsmcccache.h:119
DSMCCCacheReference
Definition: dsmcccache.h:33
DSMCCCacheDir::m_files
QMap< QString, DSMCCCacheReference > m_files
Definition: dsmcccache.h:70