Ginga  0.13.6
 All Classes Namespaces Functions Variables
PrefetchManager.h
1 /******************************************************************************
2 Este arquivo eh parte da implementacao do ambiente declarativo do middleware
3 Ginga (Ginga-NCL).
4 
5 Direitos Autorais Reservados (c) 1989-2007 PUC-Rio/Laboratorio TeleMidia
6 
7 Este programa eh software livre; voce pode redistribui-lo e/ou modificah-lo sob
8 os termos da Licenca Publica Geral GNU versao 2 conforme publicada pela Free
9 Software Foundation.
10 
11 Este programa eh distribuido na expectativa de que seja util, porem, SEM
12 NENHUMA GARANTIA; nem mesmo a garantia implicita de COMERCIABILIDADE OU
13 ADEQUACAO A UMA FINALIDADE ESPECIFICA. Consulte a Licenca Publica Geral do
14 GNU versao 2 para mais detalhes.
15 
16 Voce deve ter recebido uma copia da Licenca Publica Geral do GNU versao 2 junto
17 com este programa; se nao, escreva para a Free Software Foundation, Inc., no
18 endereco 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
19 
20 Para maiores informacoes:
21 ncl @ telemidia.puc-rio.br
22 http://www.ncl.org.br
23 http://www.ginga.org.br
24 http://www.telemidia.puc-rio.br
25 ******************************************************************************
26 This file is part of the declarative environment of middleware Ginga (Ginga-NCL)
27 
28 Copyright: 1989-2007 PUC-RIO/LABORATORIO TELEMIDIA, All Rights Reserved.
29 
30 This program is free software; you can redistribute it and/or modify it under
31 the terms of the GNU General Public License version 2 as published by
32 the Free Software Foundation.
33 
34 This program is distributed in the hope that it will be useful, but WITHOUT ANY
35 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
36 PARTICULAR PURPOSE. See the GNU General Public License version 2 for more
37 details.
38 
39 You should have received a copy of the GNU General Public License version 2
40 along with this program; if not, write to the Free Software
41 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
42 
43 For further information contact:
44 ncl @ telemidia.puc-rio.br
45 http://www.ncl.org.br
46 http://www.ginga.org.br
47 http://www.telemidia.puc-rio.br
48 *******************************************************************************/
49 
50 #ifndef PrefecthManager_H_
51 #define PrefecthManager_H_
52 
53 #include "config.h"
54 
55 #include "IPrefetchManager.h"
56 
57 #include "system/compat/SystemCompat.h"
58 using namespace ::br::pucrio::telemidia::ginga::core::system::compat;
59 
60 #if HAVE_IC
61 #include "ic/IInteractiveChannelManager.h"
62 using namespace ::br::pucrio::telemidia::ginga::core::ic;
63 #endif
64 
65 #include <sys/stat.h>
66 #include <map>
67 
68 namespace br {
69 namespace pucrio {
70 namespace telemidia {
71 namespace ginga {
72 namespace ncl {
73 namespace prefetch {
74 #if HAVE_IC
75  class PrefetchManager : public IPrefetchManager,
76  public IInteractiveChannelListener {
77 #else
79 #endif
80 
81  private:
82  map<string, string>* localToRemoteUris;
83  map<string, string>* urisToLocalRoots;
84  set<string>* scheduledRemoteUris;
85  set<string>* scheduledLocalUris;
86 #if HAVE_IC
87  IInteractiveChannelManager* icm;
88 #else
89  void* icm;
90 #endif
91  string prefetchRoot;
92  bool synch;
93 
94  int kbytes;
95  int filesDown;
96  int filesSched;
97 
99  ~PrefetchManager();
100  static IPrefetchManager* _instance;
101 
102  public:
103  static IPrefetchManager* getInstance();
104 
105  private:
106  void createDirectory(string newDir);
107 
108  public:
109  void release();
110  void releaseContents();
111  string createDocumentPrefetcher(string remoteDocUri);
112  string createSourcePrefetcher(string localDocUri, string srcUri);
113  bool hasIChannel();
114  bool hasRemoteLocation(string localUri);
115  string getRemoteLocation(string localUri);
116  string getLocalRoot(string remoteUri);
117 
118  private:
119  void getContent(string remoteUri, string localUri);
120 
121  public:
122  void setSynchPrefetch(bool synch);
123 
124  private:
125  void scheduleContent(string remoteUri, string localUri);
126  void receiveCode(long respCode){};
127  void receiveDataStream(char* buffer, int size){};
128  void receiveDataPipe(FILE* fd, int size);
129  void downloadCompleted(const char* localUri){};
130 
131  public:
132  void getScheduledContent(string clientUri);
133  void getScheduledContents();
134  };
135 }
136 }
137 }
138 }
139 }
140 }
141 
142 #endif /*PrefetchManager_H_*/