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 <QStringList>
9 #include <QMap>
10 
11 class BiopBinding;
12 
13 class DSMCCCacheFile;
14 class DSMCCCacheDir;
15 class DSMCCCache;
16 class Dsmcc;
17 
18 class DSMCCCacheKey: public QByteArray
19 {
20  public:
21  DSMCCCacheKey() = default;
22  DSMCCCacheKey(const char * data, int size):
23  QByteArray(data, size) {}
24  QString toString(void) const;
25  // Operator used in < for DSMCCCacheReference
26  friend bool operator < (const DSMCCCacheKey &key1,
27  const DSMCCCacheKey &key2);
28 };
29 
31 {
32  public:
33  DSMCCCacheReference() = default;
34 
35  DSMCCCacheReference(unsigned long car, unsigned short m,
36  unsigned short s, const DSMCCCacheKey &k) :
37  m_nCarouselId(car), m_nModuleId(m),
38  m_nStreamTag(s), m_Key(k) {}
39 
43 
45  {
49  m_Key = rhs.m_Key;
50  return *this;
51  }
52 
53  bool Equal(const DSMCCCacheReference &r) const;
54  bool Equal(const DSMCCCacheReference *p) const;
55 
56  QString toString(void) const;
57 
58  public:
59  unsigned long m_nCarouselId {0}; // Reference info for the module
60  unsigned short m_nModuleId {0};
61  unsigned short m_nStreamTag {0};
63 
64  // Operator required for QMap
65  friend bool operator < (const DSMCCCacheReference&,
66  const DSMCCCacheReference&);
67 };
68 
69 // A directory
71 {
72  public:
73  DSMCCCacheDir() = default;
75 
76  // These maps give the cache reference for each name
77  QMap<QString, DSMCCCacheReference> m_SubDirectories;
78  QMap<QString, DSMCCCacheReference> m_Files;
79 
81 };
82 
83 // The contents of a file.
85 {
86  public:
87  DSMCCCacheFile() = default;
89 
91  QByteArray m_Contents; // Contents of the file.
92 };
93 
95 {
96  public:
97  explicit DSMCCCache(Dsmcc *);
98  ~DSMCCCache();
99 
100  // Create a new gateway.
102  // Create a new directory.
104  // Add a file to the directory or gateway.
105  void AddFileInfo(DSMCCCacheDir *dir, const BiopBinding *);
106  // Add a directory to the directory or gateway.
107  void AddDirInfo(DSMCCCacheDir *dir, const BiopBinding *);
108 
109  // Add the contents of a file.
110  void CacheFileData(const DSMCCCacheReference &ref, const QByteArray &data);
111 
112  // Set the gateway reference from a DSI message.
113  void SetGateway(const DSMCCCacheReference &ref);
114 
115  // Return the contents.
116  int GetDSMObject(QStringList &objectPath, QByteArray &result);
117 
118  protected:
119  // Find File, Directory or Gateway by reference.
123 
124  DSMCCCacheReference m_GatewayRef; // Reference to the gateway
125 
126  // The set of directories, files and gateways.
127  QMap<DSMCCCacheReference, DSMCCCacheDir*> m_Directories;
128  QMap<DSMCCCacheReference, DSMCCCacheDir*> m_Gateways;
129  QMap<DSMCCCacheReference, DSMCCCacheFile*> m_Files;
130 
131  public:
132  Dsmcc *m_Dsmcc {nullptr};
133 };
134 
135 #endif
DSMCCCacheReference m_Reference
Definition: dsmcccache.h:80
bool Equal(const DSMCCCacheReference &r) const
Definition: dsmcccache.cpp:90
DSMCCCacheKey(const char *data, int size)
Definition: dsmcccache.h:22
QMap< QString, DSMCCCacheReference > m_Files
Definition: dsmcccache.h:78
Definition: dsmcc.h:75
Dsmcc * m_Dsmcc
Definition: dsmcccache.h:132
DSMCCCacheKey()=default
DSMCCCacheReference()=default
DSMCCCacheDir * Srg(const DSMCCCacheReference &ref)
Definition: dsmcccache.cpp:133
unsigned short m_nModuleId
Definition: dsmcccache.h:60
int GetDSMObject(QStringList &objectPath, QByteArray &result)
Definition: dsmcccache.cpp:281
DSMCCCacheReference m_Reference
Definition: dsmcccache.h:90
unsigned char r
Definition: ParseText.cpp:329
QByteArray m_Contents
Definition: dsmcccache.h:91
void CacheFileData(const DSMCCCacheReference &ref, const QByteArray &data)
Definition: dsmcccache.cpp:179
DSMCCCacheFile(const DSMCCCacheReference &r)
Definition: dsmcccache.h:88
QString toString(void) const
Definition: dsmcccache.cpp:53
DSMCCCache(Dsmcc *)
Definition: dsmcccache.cpp:31
QMap< DSMCCCacheReference, DSMCCCacheDir * > m_Gateways
Definition: dsmcccache.h:128
void SetGateway(const DSMCCCacheReference &ref)
Definition: dsmcccache.cpp:327
DSMCCCacheReference m_GatewayRef
Definition: dsmcccache.h:124
void AddFileInfo(DSMCCCacheDir *dir, const BiopBinding *)
Definition: dsmcccache.cpp:206
DSMCCCacheFile * FindFileData(DSMCCCacheReference &ref)
Definition: dsmcccache.cpp:240
DSMCCCacheDir(const DSMCCCacheReference &r)
Definition: dsmcccache.h:74
QMap< DSMCCCacheReference, DSMCCCacheDir * > m_Directories
Definition: dsmcccache.h:127
unsigned short m_nStreamTag
Definition: dsmcccache.h:61
DSMCCCacheReference & operator=(const DSMCCCacheReference &rhs)
Definition: dsmcccache.h:44
DSMCCCacheDir * FindGateway(DSMCCCacheReference &ref)
Definition: dsmcccache.cpp:264
DSMCCCacheFile()=default
DSMCCCacheDir * FindDir(DSMCCCacheReference &ref)
Definition: dsmcccache.cpp:252
QMap< QString, DSMCCCacheReference > m_SubDirectories
Definition: dsmcccache.h:77
friend bool operator<(const DSMCCCacheReference &, const DSMCCCacheReference &)
Definition: dsmcccache.cpp:111
void AddDirInfo(DSMCCCacheDir *dir, const BiopBinding *)
Definition: dsmcccache.cpp:223
DSMCCCacheDir()=default
DSMCCCacheDir * Directory(const DSMCCCacheReference &ref)
Definition: dsmcccache.cpp:156
The object carousel is transmitted as a directed graph.
Definition: dsmcccache.h:94
DSMCCCacheKey m_Key
Definition: dsmcccache.h:62
unsigned long m_nCarouselId
Definition: dsmcccache.h:59
DSMCCCacheReference(const DSMCCCacheReference &r)
Definition: dsmcccache.h:40
DSMCCCacheReference(unsigned long car, unsigned short m, unsigned short s, const DSMCCCacheKey &k)
Definition: dsmcccache.h:35
friend bool operator<(const DSMCCCacheKey &key1, const DSMCCCacheKey &key2)
Definition: dsmcccache.cpp:69
QString toString(void) const
Definition: dsmcccache.cpp:103
QMap< DSMCCCacheReference, DSMCCCacheFile * > m_Files
Definition: dsmcccache.h:129