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>
16 class eStaticServiceFSInformation: public iStaticServiceInformation
18 DECLARE_REF(eStaticServiceFSInformation);
20 RESULT getName(const eServiceReference &ref, std::string &name);
23 DEFINE_REF(eStaticServiceFSInformation);
25 RESULT eStaticServiceFSInformation::getName(const eServiceReference &ref, std::string &name)
32 eServiceFactoryFS::eServiceFactoryFS()
34 ePtr<eServiceCenter> sc;
36 eServiceCenter::getInstance(sc);
38 sc->addServiceFactory(eServiceFactoryFS::id, this);
40 m_service_information = new eStaticServiceFSInformation();
43 eServiceFactoryFS::~eServiceFactoryFS()
45 ePtr<eServiceCenter> sc;
47 eServiceCenter::getInstance(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;
81 DEFINE_REF(eServiceFS);
83 eServiceFS::eServiceFS(const char *path): path(path)
88 eServiceFS::~eServiceFS()
92 RESULT eServiceFS::getContent(std::list<eServiceReference> &list)
94 DIR *d=opendir(path.c_str());
97 while (dirent *e=readdir(d))
99 if (!(strcmp(e->d_name, ".") && strcmp(e->d_name, "..")))
102 std::string filename;
105 filename += e->d_name;
108 if (::stat(filename.c_str(), &s) < 0)
111 if (S_ISDIR(s.st_mode))
114 if (S_ISDIR(s.st_mode))
116 eServiceReference service(eServiceFactoryFS::id,
117 eServiceReference::isDirectory|
118 eServiceReference::canDescent|eServiceReference::mustDescent|
119 eServiceReference::shouldSort|eServiceReference::sort1,
122 list.push_back(service);
126 if (filename.substr(filename.size()-3) == ".ts")
128 eServiceReference service(eServiceFactoryDVB::id,
132 list.push_back(service);
139 RESULT eServiceFS::getNext(eServiceReference &ptr)
144 int res = getContent(m_list);
152 ptr = m_list.front();
157 eAutoInitPtr<eServiceFactoryFS> init_eServiceFactoryFS(eAutoInitNumbers::service+1, "eServiceFactoryFS");