using defines; nice debug status :-)
[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 extern "C"
13 {
14 #include <satsolver/solvable.h>
15 #include <satsolver/repo.h>
16 #include <satsolver/pool.h>
17 }
18
19 #include <iostream>
20 #include "zypp/base/Logger.h"
21 #include "zypp/base/Gettext.h"
22 #include "zypp/base/Exception.h"
23
24 #include "zypp/sat/detail/PoolImpl.h"
25
26 using std::endl;
27
28 // ///////////////////////////////////////////////////////////////////
29 namespace zypp
30 { /////////////////////////////////////////////////////////////////
31   ///////////////////////////////////////////////////////////////////
32   namespace sat
33   { /////////////////////////////////////////////////////////////////
34     ///////////////////////////////////////////////////////////////////
35     namespace detail
36     { /////////////////////////////////////////////////////////////////
37
38       void logSat( struct _Pool *, void *data, int type, const char *logString )
39       {
40           if ((type & (SAT_FATAL|SAT_ERROR)) == 0) {
41               _MIL("satsolver") << logString;
42           } else {
43               _DBG("satsolver") << logString;
44           }
45       }
46
47       ///////////////////////////////////////////////////////////////////
48       //
49       //        METHOD NAME : PoolMember::myPool
50       //        METHOD TYPE : PoolImpl
51       //
52       PoolImpl & PoolMember::myPool()
53       {
54         static PoolImpl _global;
55         return _global;
56       }
57
58       ///////////////////////////////////////////////////////////////////
59       //
60       //        METHOD NAME : PoolImpl::PoolImpl
61       //        METHOD TYPE : Ctor
62       //
63       PoolImpl::PoolImpl()
64       : _pool( ::pool_create() )
65       {
66         if ( ! _pool )
67         {
68           ZYPP_THROW( Exception( _("Can not create sat-pool.") ) );
69         }
70         // initialialize logging
71         bool verbose = ( getenv("ZYPP_FULLLOG") || getenv("ZYPP_LIBSAT_FULLLOG") );
72         ::pool_setdebuglevel (_pool, verbose ? SAT_DEBUG_SCHUBI : SAT_DEBUG_STATS); 
73         ::pool_setdebugcallback(_pool, logSat, NULL );
74       }
75
76       ///////////////////////////////////////////////////////////////////
77       //
78       //        METHOD NAME : PoolImpl::~PoolImpl
79       //        METHOD TYPE : Dtor
80       //
81       PoolImpl::~PoolImpl()
82       {
83         ::pool_free( _pool );
84       }
85
86       /////////////////////////////////////////////////////////////////
87     } // namespace detail
88     ///////////////////////////////////////////////////////////////////
89     /////////////////////////////////////////////////////////////////
90   } // namespace sat
91   ///////////////////////////////////////////////////////////////////
92   /////////////////////////////////////////////////////////////////
93 } // namespace zypp
94 ///////////////////////////////////////////////////////////////////