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/base/init_num.h>
8 #include <lib/base/init.h>
10 #include <sys/types.h>
15 class eStaticServiceFSInformation: public iStaticServiceInformation
17 DECLARE_REF(eStaticServiceFSInformation);
19 RESULT getName(const eServiceReference &ref, std::string &name);
22 DEFINE_REF(eStaticServiceFSInformation);
24 RESULT eStaticServiceFSInformation::getName(const eServiceReference &ref, std::string &name)
31 eServiceFactoryFS::eServiceFactoryFS()
33 ePtr<eServiceCenter> sc;
35 eServiceCenter::getInstance(sc);
37 sc->addServiceFactory(eServiceFactoryFS::id, this);
39 m_service_information = new eStaticServiceFSInformation();
42 eServiceFactoryFS::~eServiceFactoryFS()
44 ePtr<eServiceCenter> sc;
46 eServiceCenter::getInstance(sc);
48 sc->removeServiceFactory(eServiceFactoryFS::id);
51 DEFINE_REF(eServiceFactoryFS)
54 RESULT eServiceFactoryFS::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
60 RESULT eServiceFactoryFS::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
66 RESULT eServiceFactoryFS::list(const eServiceReference &ref, ePtr<iListableService> &ptr)
68 ptr = new eServiceFS(ref.path.c_str());
72 RESULT eServiceFactoryFS::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
74 ptr = m_service_information;
80 DEFINE_REF(eServiceFS);
82 eServiceFS::eServiceFS(const char *path): path(path)
87 eServiceFS::~eServiceFS()
91 RESULT eServiceFS::getContent(std::list<eServiceReference> &list)
93 DIR *d=opendir(path.c_str());
96 while (dirent *e=readdir(d))
98 if (!(strcmp(e->d_name, ".") && strcmp(e->d_name, "..")))
101 std::string filename;
104 filename += e->d_name;
107 if (::stat(filename.c_str(), &s) < 0)
110 if (S_ISDIR(s.st_mode))
113 if (S_ISDIR(s.st_mode))
115 eServiceReference service(eServiceFactoryFS::id,
116 eServiceReference::isDirectory|
117 eServiceReference::canDescent|eServiceReference::mustDescent|
118 eServiceReference::shouldSort|eServiceReference::sort1,
121 list.push_back(service);
124 eServiceReference service(eServiceFactoryFS::id,
125 eServiceReference::isDirectory|
126 eServiceReference::canDescent|eServiceReference::mustDescent|
127 eServiceReference::shouldSort|eServiceReference::sort1,
130 list.push_back(service);
136 RESULT eServiceFS::getNext(eServiceReference &ptr)
141 int res = getContent(m_list);
149 ptr = m_list.front();
154 eAutoInitPtr<eServiceFactoryFS> init_eServiceFactoryFS(eAutoInitNumbers::service+1, "eServiceFactoryFS");