- Service -> ServiceInfo derived from RepoInfoBase
authorJan Kupec <jkupec@suse.cz>
Wed, 30 Jul 2008 10:42:02 +0000 (10:42 +0000)
committerJan Kupec <jkupec@suse.cz>
Wed, 30 Jul 2008 10:42:02 +0000 (10:42 +0000)
14 files changed:
tests/zypp/RepoManager_test.cc
zypp/CMakeLists.txt
zypp/RepoManager.cc
zypp/RepoManager.h
zypp/Service.cc [deleted file]
zypp/Service.h [deleted file]
zypp/ServiceInfo.cc [new file with mode: 0644]
zypp/ServiceInfo.h [new file with mode: 0644]
zypp/parser/RepoindexFileReader.cc
zypp/parser/ServiceFileReader.cc
zypp/parser/ServiceFileReader.h
zypp/repo/RepoInfoBase.cc
zypp/repo/RepoInfoBase.h
zypp/repo/RepoInfoBaseImpl.h

index 4afd7b6..dc44561 100644 (file)
@@ -10,7 +10,7 @@
 #include "zypp/PublicKey.h"
 #include "zypp/TmpPath.h"
 #include "zypp/PathInfo.h"
-#include "zypp/Service.h"
+#include "zypp/ServiceInfo.h"
 
 #include "zypp/RepoManager.h"
 
@@ -40,7 +40,8 @@ BOOST_AUTO_TEST_CASE(repomanager_test)
 
   RepoManager manager(opts);
 
-  list<RepoInfo> repos = manager.knownRepositories();
+  list<RepoInfo> repos;
+  repos.insert(repos.end(), manager.repoBegin(), manager.repoEnd());
   BOOST_CHECK_EQUAL(repos.size(), (unsigned) 4);
 
   // now add a .repo file with 2 repositories in it
@@ -54,7 +55,8 @@ BOOST_AUTO_TEST_CASE(repomanager_test)
   BOOST_CHECK( PathInfo(opts.knownReposPath + "/proprietary.repo_1").isExist() );
 
   // now there should be 6 repos
-  repos = manager.knownRepositories();
+  repos.clear();
+  repos.insert(repos.end(), manager.repoBegin(), manager.repoEnd());
   BOOST_CHECK_EQUAL(repos.size(), (unsigned) 6);
 
   RepoInfo office_dup;
@@ -66,7 +68,8 @@ BOOST_AUTO_TEST_CASE(repomanager_test)
   office.setAlias("office");
   manager.removeRepository(office);
   // now there should be 5 repos
-  repos = manager.knownRepositories();
+  repos.clear();
+  repos.insert(repos.end(), manager.repoBegin(), manager.repoEnd());
   BOOST_CHECK_EQUAL(repos.size(), (unsigned) 5);
   // the file still contained one repo, so it should still exists
   BOOST_CHECK( PathInfo(opts.knownReposPath + "/proprietary.repo_1").isExist() );
@@ -80,15 +83,17 @@ BOOST_AUTO_TEST_CASE(repomanager_test)
   BOOST_CHECK( ! PathInfo(opts.knownReposPath + "/proprietary.repo_1").isExist() );
 
   //test service
+
   Url urlS;
   urlS.setPathName(DATADIR.asString());
   urlS.setScheme("dir");
-  Service service("test",urlS);
+
+  ServiceInfo service("test", urlS);
   service.setEnabled(true);
 
   manager.addService(service);
   manager.refreshServices();
-  BOOST_CHECK_EQUAL(manager.repoSize(), (unsigned) 7); //+3 from repoindex
+  BOOST_CHECK_EQUAL(manager.repoSize(), (unsigned) 7); // +3 from repoindex
 
   //simulate change of repoindex.xml
   urlS.setPathName((DATADIR+"second").asString());
@@ -98,12 +103,12 @@ BOOST_AUTO_TEST_CASE(repomanager_test)
 
   manager.modifyService(service.alias(), service);
   manager.refreshServices();
-  BOOST_CHECK_EQUAL(manager.repoSize(), (unsigned) 6); //-1 from new repoindex
+  BOOST_CHECK_EQUAL(manager.repoSize(), (unsigned) 6); // -1 from new repoindex
 
   std::list<RepoInfo> infos;
   manager.getRepositoriesInService("test",
     insert_iterator<std::list<RepoInfo> >(infos,infos.begin()));
-  BOOST_CHECK_EQUAL(infos.size(), 2); //2 from new repoindex
+  BOOST_CHECK_EQUAL(infos.size(), 2); // 2 from new repoindex
 
 
   // let test cache creation
index 840c414..206c9bf 100644 (file)
@@ -58,7 +58,7 @@ SET( zypp_SRCS
   ResPool.cc
   ResPoolProxy.cc
   ResStatus.cc
-  Service.cc
+  ServiceInfo.cc
   Signature.cc
   SrcPackage.cc
   SysContent.cc
@@ -150,7 +150,7 @@ SET( zypp_HEADERS
   ResPoolProxy.h
   ResStatus.h
   ResTraits.h
-  Service.h
+  ServiceInfo.h
   Signature.h
   SrcPackage.h
   SysContent.h
index 63fcf03..a44ef84 100644 (file)
@@ -24,7 +24,7 @@
 #include "zypp/base/Regex.h"
 #include "zypp/PathInfo.h"
 #include "zypp/TmpPath.h"
-#include "zypp/Service.h"
+#include "zypp/ServiceInfo.h"
 
 #include "zypp/repo/RepoException.h"
 #include "zypp/RepoManager.h"
@@ -261,19 +261,19 @@ namespace zypp
       return _nullimpl;
     }
 
-    void saveService( const Service& service ) const;
+    void saveService( const ServiceInfo & service ) const;
 
     Pathname generateNonExistingName( const Pathname &dir,
                                       const std::string &basefilename ) const;
 
-    std::string generateFilename( const RepoInfo &info ) const;
-    std::string generateFilename( const Service &info ) const;
+    std::string generateFilename( const RepoInfo & info ) const;
+    std::string generateFilename( const ServiceInfo & info ) const;
 
     struct ServiceCollector
     {
       ServiceCollector(ServiceSet & services_) : services(services_) {}
 
-      bool collect(Service service) { services.insert(service); return true; }
+      bool collect(ServiceInfo service) { services.insert(service); return true; }
 
     private:
       ServiceSet & services;
@@ -1017,7 +1017,7 @@ namespace zypp
     return filename;
   }
 
-  std::string RepoManager::Impl::generateFilename( const Service &info ) const
+  std::string RepoManager::Impl::generateFilename( const ServiceInfo & info ) const
   {
     std::string filename = info.alias();
     // replace slashes with underscores
@@ -1309,17 +1309,19 @@ namespace zypp
 
   void RepoManager::addService( const std::string & alias, const Url & url )
   {
-    addService( Service(alias, url) );
+    addService( ServiceInfo(alias, url) );
   }
 
-  void RepoManager::addService( const Service & service )
+  void RepoManager::addService( const ServiceInfo & service )
   {
-    //check if service isn't already exist
-    if( _pimpl->services.find(service)!= _pimpl->services.end() )
+    // check if service already exists
+    if( _pimpl->services.find(service) != _pimpl->services.end() )
       return; //FIXME ZYPP_THROW(RepoAlreadyExistsException(service.name()));
 
     //this is need to save location to correct service
-    const Service& savedService = *(_pimpl->services.insert( service )).first;
+    const ServiceInfo & savedService = *(_pimpl->services.insert( service )).first;
+
+    cout << "adde service " << savedService.alias() << endl;
 
     _pimpl->saveService( savedService );
   }
@@ -1328,9 +1330,9 @@ namespace zypp
   {
     MIL << "Going to delete repo " << alias << endl;
 
-    const Service & service = getService( alias );
+    const ServiceInfo & service = getService( alias );
 
-    Pathname location = service.location();
+    Pathname location = service.filepath();
     if( location.empty() )
     {
       ZYPP_THROW(RepoException("Can't figure where the service is stored"));
@@ -1362,7 +1364,7 @@ namespace zypp
       for_(it, tmpSet.begin(), tmpSet.end())
       {
         if( it->alias() != alias )
-          it->dumpServiceOn(file);
+          it->dumpAsIniOn(file);
       }
 
       MIL << alias << " sucessfully deleted from file " << location <<  endl;
@@ -1379,11 +1381,11 @@ namespace zypp
   }
 
 
-  void RepoManager::removeService( const Service & service )
+  void RepoManager::removeService( const ServiceInfo & service )
   { removeService(service.alias()); }
 
 
-  void RepoManager::Impl::saveService( const Service & service ) const
+  void RepoManager::Impl::saveService( const ServiceInfo & service ) const
   {
     filesystem::assert_dir( options.knownServicesPath );
 
@@ -1397,18 +1399,18 @@ namespace zypp
       ZYPP_THROW (Exception( "Can't open " + servfile.asString() ) );
     }
 
-    service.dumpServiceOn( file );
+    service.dumpAsIniOn( file );
 
-    const_cast<Service&>(service).setLocation( servfile );
+    const_cast<ServiceInfo&>(service).setFilepath( servfile );
     MIL << "done" << endl;
   }
 
-  Service RepoManager::getService( const std::string & alias ) const
+  ServiceInfo RepoManager::getService( const std::string & alias ) const
   {
     for_ (it, serviceBegin(), serviceEnd())
       if ( it->alias() == alias )
         return *it;
-    return Service::noService;
+    return ServiceInfo::noService;
   }
 
   bool RepoManager::serviceEmpty() const { return _pimpl->services.empty(); }
@@ -1431,7 +1433,7 @@ namespace zypp
   void RepoManager::refreshServices()
   {
     //cannot user for_, because it uses const version
-    for (std::set<Service>::iterator it = _pimpl->services.begin();
+    for (std::set<ServiceInfo>::iterator it = _pimpl->services.begin();
       it != _pimpl->services.end(); ++it)
     {
       if ( !it->enabled() )
@@ -1442,7 +1444,7 @@ namespace zypp
     }
   }
 
-  void RepoManager::refreshService( const Service & service )
+  void RepoManager::refreshService( const ServiceInfo & service )
   {
     //! \todo add callbacks for apps (start, end, repo removed, repo added, repo changed)
     
@@ -1470,13 +1472,11 @@ namespace zypp
       it->setService( service.alias() );
     }
 
-    // compare old and new repositories (hope not to much, if it change
+    // compare old and new repositories (hope not too much, if it change
     // then construct set and use set operation on it)
-
     std::list<RepoInfo> oldRepos;
     getRepositoriesInService(service.alias(),
-        insert_iterator<std::list<RepoInfo> >
-        (oldRepos,oldRepos.begin()));
+        insert_iterator<std::list<RepoInfo> > (oldRepos, oldRepos.begin()));
 
     // find old to remove
     for_( it, oldRepos.begin(), oldRepos.end() )
@@ -1511,13 +1511,13 @@ namespace zypp
     }
   }
 
-  void RepoManager::modifyService(const std::string & oldAlias, const Service & service)
+  void RepoManager::modifyService(const std::string & oldAlias, const ServiceInfo & service)
   {
     MIL << "Going to modify service " << oldAlias << endl;
 
-    const Service& oldService = getService(oldAlias);
+    const ServiceInfo & oldService = getService(oldAlias);
 
-    Pathname location = oldService.location();
+    Pathname location = oldService.filepath();
     if( location.empty() )
     {
       ZYPP_THROW(RepoException(
@@ -1537,10 +1537,10 @@ namespace zypp
     for_(it, tmpSet.begin(), tmpSet.end())
     {
       if( *it != oldAlias )
-        it->dumpServiceOn(file);
+        it->dumpAsIniOn(file);
     }
 
-    service.dumpServiceOn(file);
+    service.dumpAsIniOn(file);
 
     file.close();
 
index ee0dc3c..e21c79d 100644 (file)
@@ -29,7 +29,7 @@
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
-  class Service; //predef
+  class ServiceInfo; //predef
 
    /**
     * Parses \a repo_file and returns a list of \ref RepoInfo objects
@@ -98,7 +98,7 @@ namespace zypp
     class Impl;
 
     /** service typedefs */
-    typedef std::set<Service> ServiceSet;
+    typedef std::set<ServiceInfo> ServiceSet;
     typedef ServiceSet::const_iterator ServiceConstIterator;
     typedef ServiceSet::size_type ServiceSizeType;
 
@@ -462,24 +462,24 @@ namespace zypp
      *
      * \throws FIXME RepoAlreadyExistException and as reponame is service name
      */
-    void addService( const Service & service );
+    void addService( const ServiceInfo & service );
 
     /**
      * Removes service specified by its name
      *
      * \param alias unique indientifier of the service to remove
      *
-     * \throws RepoException if service is not found or file with Service cannot be deleted
+     * \throws RepoException if service is not found or file with ServiceInfo cannot be deleted
      * \throws Exception if file contain more services and rewrite file failed
      */
     void removeService( const std::string & alias );
 
-    void removeService( const Service & service );
+    void removeService( const ServiceInfo & service );
 
     /**
      * Gets true if no service is in RepoManager (so no one in specified location)
      *
-     * \return true if any Service is in RepoManager
+     * \return true if any ServiceInfo is in RepoManager
      */
     bool serviceEmpty() const;
 
@@ -492,7 +492,7 @@ namespace zypp
 
     /**
      * Iterator to first service in internal storage.
-     * \note Iterator is immutable, so you cannot change pointed Service
+     * \note Iterator is immutable, so you cannot change pointed ServiceInfo
      * \return Iterator to first service
      */
     ServiceConstIterator serviceBegin() const;
@@ -504,17 +504,17 @@ namespace zypp
     ServiceConstIterator serviceEnd() const;
 
     /**
-     * Finds Service by alias or return noService
+     * Finds ServiceInfo by alias or return noService
      *
      * \param alias unique identifier of service
-     * \return information about Service
+     * \return information about service
      */
-    Service getService( const std::string & alias ) const;
+    ServiceInfo getService( const std::string & alias ) const;
 
     /**
      * Refreshes all enabled services.
      * 
-     * \see refreshService(Service)
+     * \see refreshService(ServiceInfo)
      */
     void refreshServices();
 
@@ -524,7 +524,7 @@ namespace zypp
      * \param name service structure
      * \throws MediaException If there's a problem downloading the repo index file.
      */
-    void refreshService( const Service & service );
+    void refreshService( const ServiceInfo & service );
 
     /**
      * Modifies service file (rewrites it with new values) and underlying
@@ -532,17 +532,17 @@ namespace zypp
      * 
      * Modifications of a service can lead to rewrite of all .repo files of
      * contained repositories. Particularily, disabling a service (changing
-     * Service::enabled() from true to false) will disable all contained
+     * ServiceInfo::enabled() from true to false) will disable all contained
      * repositories. Renaming of a service will modify the "service" key
      * of all contained repositories.
      *
      * \param oldAlias Old alias of the service
-     * \param service Service object containing new data
+     * \param service ServiceInfo object containing new data
      *
      * \throws RepoException if sservice with oldAlias is not known
      * \throws Exception if have problems with files
      */
-    void modifyService(const std::string & oldAlias, const Service & service);
+    void modifyService(const std::string & oldAlias, const ServiceInfo & service);
 
   private:
     /**
diff --git a/zypp/Service.cc b/zypp/Service.cc
deleted file mode 100644 (file)
index 6852103..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-/*---------------------------------------------------------------------\
-|                          ____ _   __ __ ___                          |
-|                         |__  / \ / / . \ . \                         |
-|                           / / \ V /|  _/  _/                         |
-|                          / /__ | | | | | |                           |
-|                         /_____||_| |_| |_|                           |
-|                                                                      |
-\---------------------------------------------------------------------*/
-/** \file       zypp/Service.cc
- *
- */
-#include "zypp/Service.h"
-
-#include <ostream>
-
-#include "zypp/base/DefaultIntegral.h"
-#include "zypp/Url.h"
-#include "zypp/RepoInfo.h"
-#include "zypp/media/MediaManager.h"
-#include "zypp/parser/RepoindexFileReader.h"
-
-using namespace std;
-
-///////////////////////////////////////////////////////////////////////////////
-namespace zypp 
-{//////////////////////////////////////////////////////////////////////////////
-
-
-  struct RepoInfoCollector
-  {
-    vector<RepoInfo> repos;
-    bool collect(const RepoInfo& info)
-    {
-      repos.push_back(info);
-      return true;
-    }
-  };
-
-
-  class Service::Impl
-  {
-  public:
-    string alias;
-    string name;
-    Url url;
-    DefaultIntegral<bool,false> enabled;
-    Pathname loc;
-
-    Impl() {}
-    Impl(const string & alias_) : alias(alias_) {}
-    Impl(const string & alias_, const Url& url_) : alias(alias_), url(url_) {}
-
-  private:
-    friend Impl * rwcowClone<Impl>( const Impl * rhs );
-
-    /** clone for RWCOW_pointer */
-    Impl * clone() const
-    { return new Impl( *this ); }
-  };
-
-
-  const Service Service::noService;
-
-  Service::Service() : _pimpl( new Impl() ) {}
-
-  Service::Service(const string & alias) : _pimpl( new Impl(alias) ) {}
-  Service::Service(const string & alias, const Url & url)
-    : _pimpl( new Impl(alias, url) ) {}
-
-
-  string Service::alias() const { return _pimpl->alias; }
-  void Service::setAlias( const std::string & alias ) { _pimpl->alias = alias; }
-
-  string Service::name() const
-  { if (_pimpl->name.empty()) return _pimpl->alias; return _pimpl->name; }
-  void Service::setName( const std::string& name ) { _pimpl->name = name; }
-
-  Url Service::url() const { return _pimpl->url; }
-  void Service::setUrl( const Url& url ) { _pimpl->url = url; }
-
-  bool Service::enabled() const { return _pimpl->enabled; }
-  void Service::setEnabled( const bool enabled ) { _pimpl->enabled = enabled; }  
-
-  void Service::dumpServiceOn( std::ostream& str ) const
-  {
-    str << "[" << alias() << "]" << endl;
-    str << "name = " << name() << endl;
-    str << "url = " << url() << endl;
-    str << "enabled = " << ( enabled() ? "1" : "0") << endl;
-  }
-
-  Pathname Service::location() const
-  {
-    return _pimpl->loc;
-  }
-
-  void Service::setLocation( const Pathname& location )
-  {
-    _pimpl->loc = location;
-  }
-
-  std::ostream & operator<<( std::ostream& str, const Service &obj )
-  {
-    obj.dumpServiceOn(str);
-    return str;
-  }
-
-
-///////////////////////////////////////////////////////////////////////////////
-} //namespace zypp
-///////////////////////////////////////////////////////////////////////////////
diff --git a/zypp/Service.h b/zypp/Service.h
deleted file mode 100644 (file)
index c979953..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-/*---------------------------------------------------------------------\
-|                          ____ _   __ __ ___                          |
-|                         |__  / \ / / . \ . \                         |
-|                           / / \ V /|  _/  _/                         |
-|                          / /__ | | | | | |                           |
-|                         /_____||_| |_| |_|                           |
-|                                                                      |
-\---------------------------------------------------------------------*/
-/** \file      zypp/Service.h
- *
-*/
-#ifndef ZYPP_SERVICE_H
-#define ZYPP_SERVICE_H
-
-#include <string>
-
-#include "zypp/Url.h"
-#include "zypp/Pathname.h"
-
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
-
-    ///////////////////////////////////////////////////////////////////
-    //
-    // CLASS NAME : Service
-    //
-    /** */
-    class Service
-    {
-    public:
-        /** Default ctor creates \ref noService.*/
-        Service();
-
-        /**
-         *  Service with this name.
-         *
-         * \param name unique name of service
-         */
-        Service( const std::string& name );
-
-        /**
-         * Service with name and its URL
-         *
-         * \param name unique name of service
-         * \param url url to service
-         */
-        Service( const std::string& name, const Url& url );
-
-    public:
-        /** Represents no \ref Service. */
-        static const Service noService;
-
-    public:
-      /**
-       * Gets unique alias.
-       *
-       * \return alias as string
-       */
-      std::string alias() const;
-
-        /**
-         * Gets unique name
-         *
-         * \return name of service
-         */
-        std::string name() const;
-
-        /**
-         * Gets url to service
-         *
-         * \return url to service
-         */
-        Url url() const;
-
-        /**
-         * Returns 'enabled' flag of the services.
-         * 
-         * Disabled services imply disabled repositories of these services
-         * and they won't be refreshed by \ref RepoManager::refreshServices().
-         * 
-         * Enabled services will be refreshed by \ref RepoManager::refreshServices().
-         */
-        bool enabled() const;
-
-        /**
-         * Gets from which file is this service loaded or saved.
-         *
-         * \note this is empty for newly created file until it is saved
-         * \return path to file storing this service
-         */
-        Pathname location() const;
-
-    public:
-
-      /**
-       * Sets alias for this service
-       *
-       * \param alias new alias of this service
-       */
-      void setAlias( const std::string & alias );
-
-        /**
-         * Sets file where this service is stored.
-         *
-         * \warning don't use this function, only parses and serializer can
-         *          use it
-         * \param location path where service is stored
-         */
-        void setLocation( const Pathname& location );
-
-        /**
-         * Sets url for this service
-         *
-         * \param url url to this service
-         */
-        void setUrl( const Url& url );
-
-        /**
-         * Sets name for this service
-         *
-         * \param name new name of this service
-         */
-        void setName( const std::string& name );
-
-        /**
-         * Sets enabled status of the services.
-         * \param enabled The desired status.
-         */
-        void setEnabled( const bool enabled );
-
-   public:
-        /**
-         * Writes Service to stream in ".service" format
-         *
-         * \param str stream where serialized version service is written
-         */
-        void dumpServiceOn( std::ostream & str ) const;
-
-        class Impl;
-
-    private:
-        RWCOW_pointer<Impl> _pimpl;
-    };
-    ///////////////////////////////////////////////////////////////////
-
-    /** \relates Service Stream output */
-    std::ostream & operator<<( std::ostream & str, const Service & obj );
-
-    /** \relates Service */
-    inline bool operator==( const Service & lhs, const Service & rhs )
-    { return lhs.name() == rhs.name(); }
-
-    /** \relates Service */
-    inline bool operator!=( const Service & lhs, const Service & rhs )
-    { return lhs.name() != rhs.name(); }
-
-    /** \relates Service */
-    inline bool operator<( const Service & lhs, const Service & rhs )
-    { return lhs.name() < rhs.name(); }
-
-    /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
-#endif // ZYPP_SAT_REPOSITORY_H
diff --git a/zypp/ServiceInfo.cc b/zypp/ServiceInfo.cc
new file mode 100644 (file)
index 0000000..e995370
--- /dev/null
@@ -0,0 +1,97 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file       zypp/ServiceInfo.cc
+ *
+ */
+#include <ostream>
+#include <iostream>
+
+#include "zypp/RepoInfo.h"
+#include "zypp/parser/RepoindexFileReader.h"
+#include "zypp/repo/RepoInfoBaseImpl.h"
+
+#include "zypp/ServiceInfo.h"
+
+using namespace std;
+
+///////////////////////////////////////////////////////////////////////////////
+namespace zypp 
+{//////////////////////////////////////////////////////////////////////////////
+
+
+  struct RepoInfoCollector
+  {
+    vector<RepoInfo> repos;
+    bool collect(const RepoInfo & info)
+    {
+      repos.push_back(info);
+      return true;
+    }
+  };
+
+  ///////////////////////////////////////////////////////////////////
+  //
+  //  CLASS NAME : ServiceInfo::Impl
+  //
+  struct ServiceInfo::Impl : public repo::RepoInfoBase::Impl
+  {
+  public:
+    Url url;
+
+  public:
+    Impl() : repo::RepoInfoBase::Impl() {}
+
+    Impl(const Url & url_) : url(url_) {}
+
+  private:
+    friend Impl * rwcowClone<Impl>( const Impl * rhs );
+
+    /** clone for RWCOW_pointer */
+    Impl * clone() const
+    { return new Impl( *this ); }
+  };
+  ///////////////////////////////////////////////////////////////////
+
+
+  ///////////////////////////////////////////////////////////////////
+  //
+  //  CLASS NAME : ServiceInfo::Impl
+  //
+  ///////////////////////////////////////////////////////////////////
+
+  const ServiceInfo ServiceInfo::noService;
+  
+  ServiceInfo::ServiceInfo() : _pimpl( new Impl() ) {}
+
+  ServiceInfo::ServiceInfo(const string & alias)
+    : repo::RepoInfoBase(alias), _pimpl( new Impl() )
+  {}
+
+  ServiceInfo::ServiceInfo(const string & alias, const Url & url)
+    : repo::RepoInfoBase(alias), _pimpl( new Impl(url) )
+  {}
+
+  Url ServiceInfo::url() const { return _pimpl->url; }
+  void ServiceInfo::setUrl( const Url& url ) { _pimpl->url = url; }
+
+
+  std::ostream & ServiceInfo::dumpAsIniOn( std::ostream & str ) const
+  {
+    return RepoInfoBase::dumpAsIniOn(str) << "url = " << url() << endl;
+  }
+
+  std::ostream & operator<<( std::ostream& str, const ServiceInfo &obj )
+  {
+    return obj.dumpAsIniOn(str);
+  }
+
+
+///////////////////////////////////////////////////////////////////////////////
+} //namespace zypp
+///////////////////////////////////////////////////////////////////////////////
diff --git a/zypp/ServiceInfo.h b/zypp/ServiceInfo.h
new file mode 100644 (file)
index 0000000..3ba2040
--- /dev/null
@@ -0,0 +1,107 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/ServiceInfo.h
+ *
+ */
+#ifndef ZYPP_SERVICE_H
+#define ZYPP_SERVICE_H
+
+#include <string>
+
+#include "zypp/Url.h"
+
+#include "zypp/repo/RepoInfoBase.h"
+
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+
+    ///////////////////////////////////////////////////////////////////
+    //
+    // CLASS NAME : ServiceInfo
+    //
+    /** */
+    class ServiceInfo : public repo::RepoInfoBase
+    {
+    public:
+        /** Default ctor creates \ref noService.*/
+        ServiceInfo();
+
+        /**
+         *  Creates ServiceInfo with specified alias.
+         *
+         * \param alias unique short name of service
+         */
+        ServiceInfo( const std::string & alias );
+
+        /**
+         * ServiceInfo with alias and its URL
+         *
+         * \param alias unique shortname of service
+         * \param url url to service
+         */
+        ServiceInfo( const std::string & alias, const Url& url );
+
+    public:
+        /** Represents an empty service. */
+        static const ServiceInfo noService;
+
+    public:
+
+        /**
+         * Gets url to service
+         *
+         * \return url to service
+         */
+        Url url() const;
+
+    public:
+
+        /**
+         * Sets url for this service
+         *
+         * \param url url to this service
+         */
+        void setUrl( const Url& url );
+
+   public:
+        /**
+         * Writes ServiceInfo to stream in ".service" format
+         *
+         * \param str stream where serialized version service is written
+         */
+        virtual std::ostream & dumpAsIniOn( std::ostream & str ) const;
+
+        class Impl;
+
+    private:
+        RWCOW_pointer<Impl> _pimpl;
+    };
+    ///////////////////////////////////////////////////////////////////
+
+    /** \relates ServiceInfo Stream output */
+    std::ostream & operator<<( std::ostream & str, const ServiceInfo & obj );
+
+    /** \relates ServiceInfo */
+    inline bool operator==( const ServiceInfo & lhs, const ServiceInfo & rhs )
+    { return lhs.alias() == rhs.alias(); }
+
+    /** \relates ServiceInfo */
+    inline bool operator!=( const ServiceInfo & lhs, const ServiceInfo & rhs )
+    { return lhs.alias() != rhs.alias(); }
+
+    /** \relates ServiceInfo */
+    inline bool operator<( const ServiceInfo & lhs, const ServiceInfo & rhs )
+    { return lhs.alias() < rhs.alias(); }
+
+    /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_SAT_REPOSITORY_H
index 11ea3ad..27073d4 100644 (file)
@@ -100,9 +100,9 @@ namespace zypp
         info.setAlias(reader_r->getAttribute("alias").asString());
         info.setType(repo::RepoType::RPMMD_e); //TODO hardwired rpmmd???
         XmlString s = reader_r->getAttribute("name");
-        if (s.get()) //name setted so also set it
+        if (s.get()) // name available so store it
           info.setName(s.asString());
-        //ignore rest
+        // ignore the rest
         _callback(info);
         return true;
       }
index 2c4468a..f198a25 100644 (file)
@@ -17,7 +17,7 @@
 
 #include "zypp/parser/IniDict.h"
 #include "zypp/parser/ServiceFileReader.h"
-#include "zypp/Service.h"
+#include "zypp/ServiceInfo.h"
 
 using std::endl;
 using zypp::parser::IniDict;
@@ -36,8 +36,8 @@ namespace zypp
           const ServiceFileReader::ProcessService & callback );
     };
 
-    void ServiceFileReader::Impl::parseServices( const Pathname &file,
-                                  const ServiceFileReader::ProcessService &callback/*,
+    void ServiceFileReader::Impl::parseServices( const Pathname & file,
+                                  const ServiceFileReader::ProcessService & callback/*,
                                   const ProgressData::ReceiverFnc &progress*/ )
     {
       InputStream is(file);
@@ -53,7 +53,7 @@ namespace zypp
       {
         MIL << (*its) << endl;
 
-        Service service(*its);
+        ServiceInfo service(*its);
 
         for ( IniDict::entry_const_iterator it = dict.entriesBegin(*its);
               it != dict.entriesEnd(*its);
@@ -66,12 +66,14 @@ namespace zypp
             service.setUrl( Url (it->second) );
           else if ( it->first == "enabled" )
             service.setEnabled( str::strToTrue( it->second ) );
+          else if ( it->first == "autorefresh" )
+            service.setAutorefresh( str::strToTrue( it->second ) );
           else
             ERR << "Unknown attribute " << it->second << " ignored" << endl;
         }
 
-        MIL << "Linking Service with file " << file << endl;
-        service.setLocation(file);
+        MIL << "Linking ServiceInfo with file " << file << endl;
+        service.setFilepath(file);
 
         // add it to the list.
         if ( !callback(service) )
index b9ddb3c..85bbc1c 100644 (file)
@@ -22,7 +22,7 @@
 namespace zypp
 { /////////////////////////////////////////////////////////////////
 
-  class Service;
+  class ServiceInfo;
   ///////////////////////////////////////////////////////////////////
   namespace parser
   { /////////////////////////////////////////////////////////////////
@@ -30,7 +30,7 @@ namespace zypp
     /**
      * \short Read service data from a .service file
      *
-     * After each service is read, a \ref Service is prepared and \ref _callback
+     * After each service is read, a \ref ServiceInfo is prepared and \ref _callback
      * is called with the object passed in.
      *
      * The \ref _callback is provided on construction.
@@ -47,12 +47,12 @@ namespace zypp
       
      /**
       * Callback definition.
-      * First parameter is a \ref Service object with the resource.
+      * First parameter is a \ref ServiceInfo object with the resource.
       *
       * Return false from the callback to get a \ref AbortRequestException
       * to be thrown and the processing to be cancelled.
       */
-      typedef function< bool( const Service & )> ProcessService;
+      typedef function< bool( const ServiceInfo & )> ProcessService;
       
       /** Implementation  */
       class Impl;
index 82eb993..48f12da 100644 (file)
@@ -25,6 +25,11 @@ namespace zypp
   namespace repo
   { /////////////////////////////////////////////////////////////////
 
+  ///////////////////////////////////////////////////////////////////
+  //
+  //    CLASS NAME : RepoInfoBase::Impl
+  //
+  ///////////////////////////////////////////////////////////////////
 
   /** \relates RepoInfo::Impl Stream output */
   inline std::ostream & operator<<( std::ostream & str, const RepoInfoBase::Impl & obj )
@@ -32,6 +37,22 @@ namespace zypp
     return str << "RepoInfo::Impl";
   }
 
+  void RepoInfoBase::Impl::setAlias(const string & alias_)
+  {
+    this->alias = alias_;
+    // replace slashes with underscores
+    std::string fnd="/";
+    std::string rep="_";
+    std::string escaped_alias = alias_;
+    size_t pos = escaped_alias.find(fnd);
+    while (pos != string::npos)
+    {
+      escaped_alias.replace(pos, fnd.length(), rep);
+      pos = escaped_alias.find(fnd, pos+rep.length());
+    }
+    this->escaped_alias = escaped_alias;
+  }
+
   ///////////////////////////////////////////////////////////////////
   //
   //    CLASS NAME : RepoInfoBase
@@ -40,11 +61,20 @@ namespace zypp
 
   ///////////////////////////////////////////////////////////////////
   //
-  //    METHOD NAME : RepoInfo::RepoInfo
+  //    METHOD NAME : RepoInfoBase::RepoInfoBase
   //    METHOD TYPE : Ctor
   //
   RepoInfoBase::RepoInfoBase()
-  : _pimpl( new Impl() )
+    : _pimpl( new Impl() )
+  {}
+
+  ///////////////////////////////////////////////////////////////////
+  //
+  //    METHOD NAME : RepoInfoBase::RepoInfoBase
+  //    METHOD TYPE : Ctor
+  //
+  RepoInfoBase::RepoInfoBase(const string & alias)
+    : _pimpl( new Impl(alias) )
   {}
 
   ///////////////////////////////////////////////////////////////////
@@ -69,18 +99,7 @@ namespace zypp
 
   RepoInfoBase & RepoInfoBase::setAlias( const std::string &alias )
   {
-    _pimpl->alias = alias;
-    // replace slashes with underscores
-    std::string fnd="/";
-    std::string rep="_";
-    std::string escaped_alias = alias;
-    size_t pos = escaped_alias.find(fnd);
-    while(pos!=string::npos)
-    {
-      escaped_alias.replace(pos,fnd.length(),rep);
-      pos = escaped_alias.find(fnd,pos+rep.length());
-    }
-    _pimpl->escaped_alias = escaped_alias;
+    _pimpl->setAlias(alias);
     return *this;
   }
 
@@ -151,6 +170,7 @@ namespace zypp
   {
     return obj.dumpOn(str);
   }
+  ///////////////////////////////////////////////////////////////////
 
     /////////////////////////////////////////////////////////////////
   } // namespace repo
index d6738ea..3198645 100644 (file)
@@ -40,6 +40,7 @@ namespace zypp
 
     public:
       RepoInfoBase();
+      RepoInfoBase(const std::string & alias);
       ~RepoInfoBase();
 
       /**
index 28ff662..7d0592e 100644 (file)
@@ -35,6 +35,11 @@ namespace zypp
       , autorefresh (indeterminate)
     {}
 
+    Impl(const std::string & alias_)
+      : enabled(indeterminate)
+      , autorefresh(indeterminate)
+    { setAlias(alias_); }
+
     ~Impl()
     {}
 
@@ -47,6 +52,8 @@ namespace zypp
     Pathname filepath;
   public:
 
+    void setAlias(const std::string & alias_);
+
   private:
     friend Impl * rwcowClone<Impl>( const Impl * rhs );
     /** clone for RWCOW_pointer */