1 #include <lib/base/eerror.h>
2 #include <lib/base/object.h>
5 #include <lib/service/servicefs.h>
6 #include <lib/service/service.h>
7 #include <lib/service/servicedvb.h>
8 #include <lib/base/init_num.h>
9 #include <lib/base/init.h>
11 #include <sys/types.h>
15 class eStaticServiceFSInformation: public iStaticServiceInformation
17 DECLARE_REF(eStaticServiceFSInformation);
19 RESULT getName(const eServiceReference &ref, std::string &name);
20 int getLength(const eServiceReference &ref) { return -1; }
23 DEFINE_REF(eStaticServiceFSInformation);
25 RESULT eStaticServiceFSInformation::getName(const eServiceReference &ref, std::string &name)
32 eServiceFactoryFS::eServiceFactoryFS()
34 ePtr<eServiceCenter> sc;
36 eServiceCenter::getPrivInstance(sc);
38 sc->addServiceFactory(eServiceFactoryFS::id, this);
40 m_service_information = new eStaticServiceFSInformation();
43 eServiceFactoryFS::~eServiceFactoryFS()
45 ePtr<eServiceCenter> sc;
47 eServiceCenter::getPrivInstance(sc);
49 sc->removeServiceFactory(eServiceFactoryFS::id);
52 DEFINE_REF(eServiceFactoryFS)
55 RESULT eServiceFactoryFS::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
61 RESULT eServiceFactoryFS::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
67 RESULT eServiceFactoryFS::list(const eServiceReference &ref, ePtr<iListableService> &ptr)
69 ptr = new eServiceFS(ref.path.c_str());
73 RESULT eServiceFactoryFS::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
75 ptr = m_service_information;
79 RESULT eServiceFactoryFS::offlineOperations(const eServiceReference &, ePtr<iServiceOfflineOperations> &ptr)
87 DEFINE_REF(eServiceFS);
89 eServiceFS::eServiceFS(const char *path): path(path)
94 eServiceFS::~eServiceFS()
98 RESULT eServiceFS::getContent(std::list<eServiceReference> &list)
100 DIR *d=opendir(path.c_str());
103 while (dirent *e=readdir(d))
105 if (!(strcmp(e->d_name, ".") && strcmp(e->d_name, "..")))
108 std::string filename;
111 filename += e->d_name;
114 if (::stat(filename.c_str(), &s) < 0)
117 if (S_ISDIR(s.st_mode))
120 if (S_ISDIR(s.st_mode))
122 eServiceReference service(eServiceFactoryFS::id,
123 eServiceReference::isDirectory|
124 eServiceReference::canDescent|eServiceReference::mustDescent|
125 eServiceReference::shouldSort|eServiceReference::sort1,
128 list.push_back(service);
132 if (filename.substr(filename.size()-3) == ".ts")
134 eServiceReference service(eServiceFactoryDVB::id,
138 list.push_back(service);
146 RESULT eServiceFS::getNext(eServiceReference &ptr)
151 int res = getContent(m_list);
158 ptr = eServiceReference();
162 ptr = m_list.front();
167 int eServiceFS::compareLessEqual(const eServiceReference &a, const eServiceReference &b)
169 /* directories first */
170 if ((a.flags & ~b.flags) & eServiceReference::isDirectory)
172 else if ((~a.flags & b.flags) & eServiceReference::isDirectory)
174 /* sort by filename */
176 return a.path < b.path;
179 RESULT eServiceFS::startEdit(ePtr<iMutableServiceList> &res)
185 eAutoInitPtr<eServiceFactoryFS> init_eServiceFactoryFS(eAutoInitNumbers::service+1, "eServiceFactoryFS");