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 &r) = default;
43  DSMCCCacheReference& operator=(const DSMCCCacheReference &rhs) = 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
static void AddFileInfo(DSMCCCacheDir *dir, const BiopBinding *pBB)
Definition: dsmcccache.cpp:206
DSMCCCacheReference m_reference
Definition: dsmcccache.h:72
bool Equal(const DSMCCCacheReference &r) const
Definition: dsmcccache.cpp:91
DSMCCCacheKey(const char *data, int size)
Definition: dsmcccache.h:25
Definition: dsmcc.h:75
DSMCCCacheKey()=default
DSMCCCacheReference()=default
DSMCCCacheDir * Srg(const DSMCCCacheReference &ref)
Definition: dsmcccache.cpp:134
unsigned short m_nModuleId
Definition: dsmcccache.h:52
int GetDSMObject(QStringList &objectPath, QByteArray &result)
Definition: dsmcccache.cpp:281
void CacheFileData(const DSMCCCacheReference &ref, const QByteArray &data)
Definition: dsmcccache.cpp:180
DSMCCCacheReference m_reference
Definition: dsmcccache.h:82
DSMCCCacheFile(const DSMCCCacheReference &r)
Definition: dsmcccache.h:80
QString toString(void) const
Definition: dsmcccache.cpp:53
DSMCCCacheKey m_key
Definition: dsmcccache.h:54
QMap< DSMCCCacheReference, DSMCCCacheFile * > m_files
Definition: dsmcccache.h:121
void SetGateway(const DSMCCCacheReference &ref)
Definition: dsmcccache.cpp:327
QMap< DSMCCCacheReference, DSMCCCacheDir * > m_gateways
Definition: dsmcccache.h:120
DSMCCCacheReference m_GatewayRef
Definition: dsmcccache.h:116
DSMCCCacheFile * FindFileData(DSMCCCacheReference &ref)
Definition: dsmcccache.cpp:240
DSMCCCacheDir(const DSMCCCacheReference &r)
Definition: dsmcccache.h:66
unsigned short m_nStreamTag
Definition: dsmcccache.h:53
DSMCCCacheDir * FindGateway(DSMCCCacheReference &ref)
Definition: dsmcccache.cpp:264
DSMCCCacheFile()=default
DSMCCCacheDir * FindDir(DSMCCCacheReference &ref)
Definition: dsmcccache.cpp:252
QByteArray m_contents
Definition: dsmcccache.h:83
QMap< DSMCCCacheReference, DSMCCCacheDir * > m_directories
Definition: dsmcccache.h:119
friend bool operator<(const DSMCCCacheReference &ref1, const DSMCCCacheReference &ref2)
Definition: dsmcccache.cpp:112
DSMCCCacheDir()=default
DSMCCCacheDir * Directory(const DSMCCCacheReference &ref)
Definition: dsmcccache.cpp:157
DSMCCCacheReference & operator=(const DSMCCCacheReference &rhs)=default
The object carousel is transmitted as a directed graph.
Definition: dsmcccache.h:86
DSMCCCache(Dsmcc *dsmcc)
Definition: dsmcccache.cpp:31
QMap< QString, DSMCCCacheReference > m_files
Definition: dsmcccache.h:70
unsigned long m_nCarouselId
Definition: dsmcccache.h:51
QMap< QString, DSMCCCacheReference > m_subDirectories
Definition: dsmcccache.h:69
friend bool operator<(const DSMCCCacheKey &key1, const DSMCCCacheKey &key2)
Definition: dsmcccache.cpp:69
static void AddDirInfo(DSMCCCacheDir *dir, const BiopBinding *pBB)
Definition: dsmcccache.cpp:223
QString toString(void) const
Definition: dsmcccache.cpp:104
Dsmcc * m_dsmcc
Definition: dsmcccache.h:124
DSMCCCacheReference(unsigned long car, unsigned short m, unsigned short s, DSMCCCacheKey k)
Definition: dsmcccache.h:37