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)
86 eServiceFS::~eServiceFS()
90 RESULT eServiceFS::getContent(std::list<eServiceReference> &list)
92 DIR *d=opendir(path.c_str());
95 while (dirent *e=readdir(d))
97 if (!(strcmp(e->d_name, ".") && strcmp(e->d_name, "..")))
100 std::string filename;
103 filename += e->d_name;
106 if (::stat(filename.c_str(), &s) < 0)
109 if (S_ISDIR(s.st_mode))
112 if (S_ISDIR(s.st_mode))
114 eServiceReference service(eServiceFactoryFS::id,
115 eServiceReference::isDirectory|
116 eServiceReference::canDescent|eServiceReference::mustDescent|
117 eServiceReference::shouldSort|eServiceReference::sort1,
120 list.push_back(service);
123 eServiceReference service(eServiceFactoryFS::id,
124 eServiceReference::isDirectory|
125 eServiceReference::canDescent|eServiceReference::mustDescent|
126 eServiceReference::shouldSort|eServiceReference::sort1,
129 list.push_back(service);
135 eAutoInitPtr<eServiceFactoryFS> init_eServiceFactoryFS(eAutoInitNumbers::service+1, "eServiceFactoryFS");