prepare namespace callback
[platform/upstream/libzypp.git] / zypp / sat / detail / PoolImpl.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/sat/detail/PoolImpl.cc
10  *
11 */
12 #include <iostream>
13 #include <boost/mpl/int.hpp>
14
15 #include "zypp/base/Logger.h"
16 #include "zypp/base/Gettext.h"
17 #include "zypp/base/Exception.h"
18
19 #include "zypp/ZConfig.h"
20
21 #include "zypp/sat/detail/PoolImpl.h"
22 #include "zypp/Capability.h"
23
24 using std::endl;
25
26 #undef  ZYPP_BASE_LOGGER_LOGGROUP
27 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::satpool"
28
29 // ///////////////////////////////////////////////////////////////////
30 namespace zypp
31 { /////////////////////////////////////////////////////////////////
32   ///////////////////////////////////////////////////////////////////
33   namespace sat
34   { /////////////////////////////////////////////////////////////////
35     ///////////////////////////////////////////////////////////////////
36     namespace detail
37     { /////////////////////////////////////////////////////////////////
38
39       // MPL checks for satlib constants we redefine to avoid
40       // includes and defines.
41       BOOST_MPL_ASSERT_RELATION( noId,                 ==, STRID_NULL );
42       BOOST_MPL_ASSERT_RELATION( emptyId,              ==, STRID_EMPTY );
43
44       BOOST_MPL_ASSERT_RELATION( solvablePrereqMarker, ==, SOLVABLE_PREREQMARKER );
45       BOOST_MPL_ASSERT_RELATION( solvableFileMarker,   ==, SOLVABLE_FILEMARKER );
46
47       BOOST_MPL_ASSERT_RELATION( CapDetail::CAP_AND,       ==, REL_AND );
48       BOOST_MPL_ASSERT_RELATION( CapDetail::CAP_OR,        ==, REL_OR );
49       BOOST_MPL_ASSERT_RELATION( CapDetail::CAP_WITH,      ==, REL_WITH );
50       BOOST_MPL_ASSERT_RELATION( CapDetail::CAP_NAMESPACE, ==, REL_NAMESPACE );
51
52      /////////////////////////////////////////////////////////////////
53
54       static void logSat( struct _Pool *, void *data, int type, const char *logString )
55       {
56           if ((type & (SAT_FATAL|SAT_ERROR))) {
57               _ERR("satsolver") << logString;
58           } else {
59               _MIL("satsolver") << logString;
60           }
61       }
62
63       static detail::IdType nsCallback( struct _Pool *, void *data, detail::IdType lhs, detail::IdType rhs )
64       {
65         //T << Cability( lhs ) << (const char *)data << Capability( rhs ) << endl;
66         return 0;
67       }
68
69       ///////////////////////////////////////////////////////////////////
70       //
71       //        METHOD NAME : PoolMember::myPool
72       //        METHOD TYPE : PoolImpl
73       //
74       PoolImpl & PoolMember::myPool()
75       {
76         static PoolImpl _global;
77         return _global;
78       }
79
80       ///////////////////////////////////////////////////////////////////
81       //
82       //        METHOD NAME : PoolImpl::PoolImpl
83       //        METHOD TYPE : Ctor
84       //
85       PoolImpl::PoolImpl()
86       : _pool( ::pool_create() )
87       {
88         if ( ! _pool )
89         {
90           ZYPP_THROW( Exception( _("Can not create sat-pool.") ) );
91         }
92         // initialialize logging
93         bool verbose = ( getenv("ZYPP_FULLLOG") || getenv("ZYPP_LIBSAT_FULLLOG") );
94         ::pool_setdebuglevel( _pool, verbose ? 5 : 2 );
95         ::pool_setdebugcallback( _pool, logSat, NULL );
96
97         // set pool architecture
98         ::pool_setarch( _pool,  ZConfig::instance().systemArchitecture().asString().c_str() );
99
100         // set namespace callback
101         _pool->nscallback = &nsCallback;
102         _pool->nscallbackdata = (void*)" NAMESPACE ";
103         SEC << _pool->nscallback << endl;
104       }
105
106       ///////////////////////////////////////////////////////////////////
107       //
108       //        METHOD NAME : PoolImpl::~PoolImpl
109       //        METHOD TYPE : Dtor
110       //
111       PoolImpl::~PoolImpl()
112       {
113         ::pool_free( _pool );
114       }
115
116       ///////////////////////////////////////////////////////////////////
117
118       void PoolImpl::setDirty( const char * a1, const char * a2, const char * a3 )
119       {
120         if ( a1 )
121         {
122           if      ( a3 ) DBG << a1 << " " << a2 << " " << a3 << endl;
123           else if ( a2 ) DBG << a1 << " " << a2 << endl;
124           else           DBG << a1 << endl;
125         }
126         _serial.setDirty();
127         ::pool_freewhatprovides( _pool );
128       }
129
130       void PoolImpl::prepare()
131       {
132         if ( _watcher.remember( _serial ) )
133         {
134            // sat solver claims to handle this on it's own:
135            ::pool_createwhatprovides( _pool );
136         }
137       }
138
139       /////////////////////////////////////////////////////////////////
140     } // namespace detail
141     ///////////////////////////////////////////////////////////////////
142     /////////////////////////////////////////////////////////////////
143   } // namespace sat
144   ///////////////////////////////////////////////////////////////////
145   /////////////////////////////////////////////////////////////////
146 } // namespace zypp
147 ///////////////////////////////////////////////////////////////////