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);
21 int getLength(const eServiceReference &ref) { return -1; }
24 DEFINE_REF(eStaticServiceFSInformation);
26 RESULT eStaticServiceFSInformation::getName(const eServiceReference &ref, std::string &name)
33 eServiceFactoryFS::eServiceFactoryFS()
35 ePtr<eServiceCenter> sc;
37 eServiceCenter::getInstance(sc);
39 sc->addServiceFactory(eServiceFactoryFS::id, this);
41 m_service_information = new eStaticServiceFSInformation();
44 eServiceFactoryFS::~eServiceFactoryFS()
46 ePtr<eServiceCenter> sc;
48 eServiceCenter::getInstance(sc);
50 sc->removeServiceFactory(eServiceFactoryFS::id);
53 DEFINE_REF(eServiceFactoryFS)
56 RESULT eServiceFactoryFS::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
62 RESULT eServiceFactoryFS::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
68 RESULT eServiceFactoryFS::list(const eServiceReference &ref, ePtr<iListableService> &ptr)
70 ptr = new eServiceFS(ref.path.c_str());
74 RESULT eServiceFactoryFS::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
76 ptr = m_service_information;
82 DEFINE_REF(eServiceFS);
84 eServiceFS::eServiceFS(const char *path): path(path)
89 eServiceFS::~eServiceFS()
93 RESULT eServiceFS::getContent(std::list<eServiceReference> &list)
95 DIR *d=opendir(path.c_str());
98 while (dirent *e=readdir(d))
100 if (!(strcmp(e->d_name, ".") && strcmp(e->d_name, "..")))
103 std::string filename;
106 filename += e->d_name;
109 if (::stat(filename.c_str(), &s) < 0)
112 if (S_ISDIR(s.st_mode))
115 if (S_ISDIR(s.st_mode))
117 eServiceReference service(eServiceFactoryFS::id,
118 eServiceReference::isDirectory|
119 eServiceReference::canDescent|eServiceReference::mustDescent|
120 eServiceReference::shouldSort|eServiceReference::sort1,
123 list.push_back(service);
127 if (filename.substr(filename.size()-3) == ".ts")
129 eServiceReference service(eServiceFactoryDVB::id,
133 list.push_back(service);
140 RESULT eServiceFS::getNext(eServiceReference &ptr)
145 int res = getContent(m_list);
153 ptr = m_list.front();
158 eAutoInitPtr<eServiceFactoryFS> init_eServiceFactoryFS(eAutoInitNumbers::service+1, "eServiceFactoryFS");