[280] | 1 | /* rcacheactor.h |
---|
| 2 | * |
---|
| 3 | * Copyright (c) 2000-2003 Conectiva S/A |
---|
| 4 | * 2002 Michael Vogt <mvo@debian.org> |
---|
| 5 | * |
---|
| 6 | * Author: Alfredo K. Kojima <kojima@conectiva.com.br> |
---|
| 7 | * Michael Vogt <mvo@debian.org> |
---|
| 8 | * |
---|
| 9 | * This program is free software; you can redistribute it and/or |
---|
| 10 | * modify it under the terms of the GNU General Public License as |
---|
| 11 | * published by the Free Software Foundation; either version 2 of the |
---|
| 12 | * License, or (at your option) any later version. |
---|
| 13 | * |
---|
| 14 | * This program is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this program; if not, write to the Free Software |
---|
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
---|
| 22 | * USA |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #ifndef RCACHEACTOR_H |
---|
| 26 | #define RCACHEACTOR_H |
---|
| 27 | |
---|
| 28 | #include "rpackagelister.h" |
---|
| 29 | #include <regex.h> |
---|
| 30 | |
---|
| 31 | class RCacheActor:public RCacheObserver { |
---|
| 32 | public: |
---|
| 33 | |
---|
| 34 | enum Action { |
---|
| 35 | ACTION_KEEP, |
---|
| 36 | ACTION_INSTALL, |
---|
| 37 | ACTION_REINSTALL, |
---|
| 38 | ACTION_REMOVE |
---|
| 39 | }; |
---|
| 40 | |
---|
| 41 | protected: |
---|
| 42 | |
---|
| 43 | RPackageLister *_lister; |
---|
| 44 | RPackageLister::pkgState *_laststate; |
---|
| 45 | |
---|
| 46 | public: |
---|
| 47 | |
---|
| 48 | virtual void run(vector<RPackage *> &List, int Action) = 0; |
---|
| 49 | |
---|
| 50 | virtual void notifyCachePreChange() { |
---|
| 51 | updateState(); |
---|
| 52 | }; |
---|
| 53 | |
---|
| 54 | virtual void notifyCachePostChange(); |
---|
| 55 | |
---|
| 56 | virtual void notifyCacheOpen() { |
---|
| 57 | }; |
---|
| 58 | |
---|
| 59 | virtual void updateState() { |
---|
| 60 | delete _laststate; |
---|
| 61 | _laststate = new RPackageLister::pkgState; |
---|
| 62 | _lister->saveState(*_laststate); |
---|
| 63 | }; |
---|
| 64 | |
---|
| 65 | RCacheActor(RPackageLister *lister) |
---|
| 66 | : _lister(lister), _laststate(0) { |
---|
| 67 | _lister->registerCacheObserver(this); |
---|
| 68 | }; |
---|
| 69 | |
---|
| 70 | virtual ~ RCacheActor() { |
---|
| 71 | _lister->unregisterCacheObserver(this); |
---|
| 72 | }; |
---|
| 73 | }; |
---|
| 74 | |
---|
| 75 | class RCacheActorRecommends:public RCacheActor { |
---|
| 76 | protected: |
---|
| 77 | |
---|
| 78 | typedef vector<string> ListType; |
---|
| 79 | typedef map<string, ListType> MapType; |
---|
| 80 | typedef map<regex_t *, ListType> RegexMapType; |
---|
| 81 | |
---|
| 82 | MapType _map; |
---|
| 83 | MapType _map_wildcard; |
---|
| 84 | RegexMapType _map_regex; |
---|
| 85 | |
---|
| 86 | string _langLast; |
---|
| 87 | ListType _langCache; |
---|
| 88 | |
---|
| 89 | void setLanguageCache(); |
---|
| 90 | |
---|
| 91 | inline bool actOnPkg(string name, int Action) { |
---|
| 92 | RPackage *Pkg = _lister->getPackage(name); |
---|
| 93 | if (Pkg != NULL) { |
---|
| 94 | switch (Action) { |
---|
| 95 | case ACTION_KEEP: |
---|
| 96 | Pkg->setKeep(); |
---|
| 97 | break; |
---|
| 98 | case ACTION_INSTALL: |
---|
| 99 | Pkg->setInstall(); |
---|
| 100 | break; |
---|
| 101 | case ACTION_REMOVE: |
---|
| 102 | Pkg->setRemove(); |
---|
| 103 | break; |
---|
| 104 | } |
---|
| 105 | return true; |
---|
| 106 | } |
---|
| 107 | return false; |
---|
| 108 | }; |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | public: |
---|
| 112 | |
---|
| 113 | virtual void run(vector<RPackage *> &List, int Action); |
---|
| 114 | |
---|
| 115 | virtual void notifyCachePostChange(); |
---|
| 116 | |
---|
| 117 | RCacheActorRecommends(RPackageLister *lister, string FileName); |
---|
| 118 | virtual ~RCacheActorRecommends(); |
---|
| 119 | }; |
---|
| 120 | |
---|
| 121 | #endif |
---|
| 122 | |
---|
| 123 | // vim:sts=3:sw=3 |
---|