1 Debian patch touch this file
-
Changes done to source before version 0.6.1-2.1
- Author
- Petter Reinholdtsen <[email protected]>
- Bug
- https://bugs.debian.org/853376
- Forwarded
- no
| 1 | #ifndef _DMUCS_HOST_FILE_H_ |
| 2 | #define _DMUCS_HOST_FILE_H_ 1 |
| 3 | |
| 4 | /* |
| 5 | * dmucs_hosts_file.h: code to read the hosts-info configuration file. |
| 6 | * |
| 7 | * Copyright (C) 2005, 2006 Victor T. Norman |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License as published by the |
| 11 | * Free Software Foundation; either version 2 of the License, or (at your |
| 12 | * option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
| 17 | * Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <map> |
| 25 | #include <string> |
| 26 | |
| •27 | #ifdef SYSCONFDIR |
| 28 | const std::string HOSTS_INFO_FILE = std::string(SYSCONFDIR) + \ |
| 29 | std::string("/") + std::string("dmucs.conf"); |
| 30 | #else |
| •31 | const std::string HOSTS_INFO_FILE = "dmucs.conf"; |
| 32 | #endif |
| 33 | |
| 34 | |
| 35 | class DmucsHostsFile |
| 36 | { |
| 37 | public: |
| 38 | |
| 39 | static DmucsHostsFile *getInstance(const std::string &hostsInfoFile); |
| 40 | void getDataForHost(const struct in_addr &ipAddr, int *numCpus, |
| 41 | int *powerIndex) const; |
| 42 | |
| 43 | /* |
| 44 | * This class implements the singleton pattern, as only one instance of |
| 45 | * it needs to exist, and it should take care to re-read the hostsfile, |
| 46 | * etc., when necessary. |
| 47 | */ |
| 48 | |
| 49 | private: |
| 50 | // this is private so that it cannot be used (this is a Singleton). |
| 51 | DmucsHostsFile(const std::string &hostsInfoFile); |
| 52 | ~DmucsHostsFile(); |
| 53 | |
| 54 | struct info_t { |
| 55 | int numCpus_; |
| 56 | int powerIndex_; |
| 57 | info_t(int ncpus, int pindex) : |
| 58 | numCpus_(ncpus), powerIndex_(pindex) {}; |
| 59 | }; |
| 60 | |
| 61 | static DmucsHostsFile *instance_; |
| 62 | std::string hostsInfoFile_; |
| 63 | |
| 64 | /* |
| 65 | * This maps an IP address (in 32-bit format) to the pair of values: |
| 66 | * numCpus and powerIndex. |
| 67 | */ |
| 68 | typedef std::map<unsigned int, info_t> host_info_db_t; |
| 69 | typedef host_info_db_t::iterator host_info_db_iter_t; |
| 70 | |
| 71 | mutable host_info_db_t db_; |
| 72 | mutable time_t lastFileChangeTime_; |
| 73 | |
| 74 | void readFileIntoDb() const; |
| 75 | |
| 76 | /* If the file modification time has changed since the last time this |
| 77 | was called, then return true AND update lastFileChangeTime_ to the |
| 78 | new modification time. */ |
| 79 | bool hasFileChanged() const; |
| 80 | |
| 81 | }; |
| 82 | |
| 83 | #endif |
| 84 |