PluginServices.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <iostream>
00010 #include <sstream>
00011 #include "zypp/base/Logger.h"
00012 #include "zypp/base/Gettext.h"
00013 #include "zypp/base/String.h"
00014 #include "zypp/base/InputStream.h"
00015 #include "zypp/base/UserRequestException.h"
00016
00017 #include "zypp/repo/PluginServices.h"
00018 #include "zypp/ServiceInfo.h"
00019 #include "zypp/RepoInfo.h"
00020 #include "zypp/PathInfo.h"
00021
00022 using std::endl;
00023 using std::stringstream;
00024
00026 namespace zypp
00027 {
00028
00029 namespace repo
00030 {
00031
00032 class PluginServices::Impl
00033 {
00034 public:
00035 static void loadServices( const Pathname &path,
00036 const PluginServices::ProcessService &callback );
00037 };
00038
00039 void PluginServices::Impl::loadServices( const Pathname &path,
00040 const PluginServices::ProcessService & callback
00041 )
00042 {
00043 std::list<Pathname> entries;
00044 if (PathInfo(path).isExist())
00045 {
00046 if ( filesystem::readdir( entries, path, false ) != 0 )
00047 {
00048
00049 ZYPP_THROW(Exception(str::form(_("Failed to read directory '%s'"), path.c_str())));
00050 }
00051
00052
00053 for_(it, entries.begin(), entries.end() )
00054 {
00055 ServiceInfo service_info;
00056 service_info.setAlias((*it).basename());
00057 Url url;
00058 url.setPathName((*it).asString());
00059 url.setScheme("file");
00060 service_info.setUrl(url);
00061 service_info.setType(ServiceType::PLUGIN);
00062 service_info.setAutorefresh( true );
00063 DBG << "Plugin Service: " << service_info << endl;
00064 callback(service_info);
00065 }
00066
00067 }
00068 }
00069
00070 PluginServices::PluginServices( const Pathname &path,
00071 const ProcessService & callback
00072 )
00073 {
00074 Impl::loadServices(path, callback);
00075 }
00076
00077 PluginServices::~PluginServices()
00078 {}
00079
00080 std::ostream & operator<<( std::ostream & str, const PluginServices & obj )
00081 {
00082 return str;
00083 }
00084
00086 }
00089 }