1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
/*
* vdr-vodcatcher - A plugin for the Linux Video Disk Recorder
* Copyright (c) 2007 - 2009 Tobias Grimm <vdr@e-tobi.net>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "ServiceLocatorImpl.h"
#include "FeedsConfigFile.h"
#include "IConfiguration.h"
#include "RssFeedParser.h"
#include "VdrThread.h"
#include "VdrSleeper.h"
#include "VdrCriticalSection.h"
#include "DownloadQueue.h"
#include "ThreadsafeDownloadPool.h"
#include "SynchedDownloadPool.h"
#include "LocalFileCache.h"
#include "CurlDownloader.h"
#include "FeedUpdaterImpl.h"
#include "DownloadAction.h"
#include "OsdListMenu.h"
#include "FeedMenuController.h"
#include "ItemMenuPresenter.h"
#include "OsdItemView.h"
#include "ItemViewPresenter.h"
#include "SyslogErrorLogger.h"
#include "OsdSetupMenu.h"
#include "MplayerPlugin.h"
#include "XineliboutputPlayer.h"
#include "FeedRepository.h"
#include "IMenuFactory.h"
#include "VdrInterface.h"
using namespace std;
ServiceLocatorImpl::ServiceLocatorImpl(IConfiguration& configuration) :
configuration(configuration)
{
}
IFeedSources* ServiceLocatorImpl::GetFeedSources()
{
if (!feedSources.get())
{
feedSources = RefPtr<IFeedSources>(new FeedsConfigFile(configuration.GetSourcesFileName()));
}
return feedSources.get();
}
IFeedParser* ServiceLocatorImpl::GetFeedParser()
{
if (!feedParser.get())
{
feedParser = RefPtr<IFeedParser>(new RssFeedParser(*GetDownloadCache()));
}
return feedParser.get();
}
IDownloadPool* ServiceLocatorImpl::GetDownloadPool()
{
if (!downloadPool.get())
{
RefPtr<ISleeper> downloadSleeper(new VdrSleeper());
RefPtr<ICriticalSection> criticalSection(new VdrCriticalSection());
// Download pool decorated with thread safety and thread synchronization
RefPtr<IDownloadPool> pool(new DownloadQueue());
RefPtr<IDownloadPool> threadSafePool(new ThreadSafeDownloadPool(pool,
criticalSection));
RefPtr<IDownloadPool> synchedPool(new SynchedDownloadPool(
threadSafePool, downloadSleeper));
downloadPool = RefPtr<IDownloadPool>(synchedPool);
}
return downloadPool.get();
}
IDownloadCache* ServiceLocatorImpl::GetDownloadCache()
{
if (!downloadCache.get())
{
downloadCache = RefPtr<IDownloadCache>(new LocalFileCache(configuration.GetCacheDirName()));
}
return downloadCache.get();
}
IDownloader* ServiceLocatorImpl::GetDownloader()
{
if (!downloader.get())
{
downloader = RefPtr<IDownloader>(new CurlDownloader(*GetDownloadCache()));
}
return downloader.get();
}
IThread* ServiceLocatorImpl::GetDownloadThread()
{
if (!downloadThread.get())
{
downloadThread = RefPtr<IThread>(new VdrThread(CreateDownloadAction()));
}
return downloadThread.get();
}
IFeedUpdater* ServiceLocatorImpl::GetFeedUpdater()
{
if (!feedUpdater.get())
{
feedUpdater = RefPtr<IFeedUpdater>(new FeedUpdaterImpl(*GetFeedSources(), *GetDownloadPool(),
*GetDownloadCache()));
}
return feedUpdater.get();
}
RefPtr<IThreadAction> ServiceLocatorImpl::CreateDownloadAction()
{
return RefPtr<IThreadAction>(new DownloadAction(*GetDownloadPool(),
*GetDownloader()));
}
IMenuFactory* ServiceLocatorImpl::GetMenuFactory()
{
return this;
}
cOsdMenu* ServiceLocatorImpl::CreateFeedMenu()
{
return new OsdListMenu(
RefPtr<IListMenuPresenter>(new FeedMenuController(*GetMenuFactory(), *CreateFeedRepository())));
}
RefPtr<IFeedRepository> ServiceLocatorImpl::CreateFeedRepository()
{
RefPtr<IFeedRepository> feedRepository(new FeedRepository(*GetDownloadCache(), *GetDownloadPool(), *GetDownloader(), *GetFeedParser(), *GetFeedSources()));
return feedRepository;
}
cOsdMenu* ServiceLocatorImpl::CreateItemMenu(const Feed& feed)
{
RefPtr<IMediaPlayer> mplayerPlugin;
switch(configuration.GetMediaPlayerType())
{
case Mplayer:
mplayerPlugin = new MplayerPlugin(*GetErrorLogger());
break;
default:
mplayerPlugin = new XineliboutputPlayer(*GetErrorLogger());
break;
}
RefPtr<IVdrInterface> vdrInterface(new VdrInterface());
return new OsdListMenu(
RefPtr<IListMenuPresenter>(new ItemMenuPresenter(*this, feed, CreateFeedRepository(), configuration, mplayerPlugin, vdrInterface)), 9);
}
cOsdMenu* ServiceLocatorImpl::CreateItemView(Feed feed, Item item)
{
RefPtr<ItemViewPresenter> itemViewPresenter(new ItemViewPresenter(feed.GetTitle(), item, configuration));
return new OsdItemView(itemViewPresenter);
}
IErrorLogger* ServiceLocatorImpl::GetErrorLogger()
{
if (!errorLogger.get())
{
errorLogger = RefPtr<IErrorLogger>(new SyslogErrorLogger());
}
return errorLogger.get();
}
cMenuSetupPage* ServiceLocatorImpl::CreateSetupMenu()
{
return new OsdSetupMenu(configuration);
}
|