00001 /* 00002 * Copyright 2009 DreamLab Onet.pl Sp. z o.o. 00003 * Licensed under the Apache License, Version 2.0 (the "License"); 00004 * you may not use this file except in compliance with the License. 00005 * You may obtain a copy of the License at 00006 * 00007 * http://www.apache.org/licenses/LICENSE-2.0 00008 * 00009 * Unless required by applicable law or agreed to in writing, software 00010 * distributed under the License is distributed on an "AS IS" BASIS, 00011 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00012 * See the License for the specific language governing permissions and 00013 * limitations under the License. 00014 * 00015 * Authors: 00016 * Michal Szklarzewicz <michal(x)szklarzewicz(y)gmail(x)com> 00017 * Grzegorz Jablonski <jablonski(x)grzegorz(y)gmail(x)com> 00018 * (use dot instead of x, and @ instead of y) 00019 */ 00020 00021 #ifndef __CONFIG_STORE_HPP__ 00022 #define __CONFIG_STORE_HPP__ 00023 #include "types.hpp" 00024 #include "LocalDB.hpp" 00025 #include "hashtable.hpp" 00026 #include "dst_config.hpp" 00027 #include <db_cxx.h> 00028 #include <string.h> 00029 00030 struct dest_config; 00031 struct t_uid_const 00032 { 00033 uint32_t length; 00034 char data[255]; 00035 t_uid_const(const char * dest){ 00036 length = strlen(dest); 00037 memcpy(data, dest, length); 00038 } 00039 t_uid_const(const t_uid &ref){ 00040 length = ref.length; 00041 memcpy(data, ref.data, length); 00042 } 00043 }; 00044 00045 class configStore { 00046 t_uid dest_; 00047 dest_config* conf_; 00048 LocalDB &localDB_; 00049 Db db_; 00050 std::string dbFileName_; 00051 u_int32_t cFlags_; 00052 //close nicely berkeley db 00056 void close(); 00057 char* size_; 00058 int size_len_; 00059 char* traffic_; 00060 int traffic_len_; 00061 00062 public: 00066 configStore(dest_config* conf, LocalDB &ref, t_uid dest, std::string &path, std::string &dbName); 00070 ~configStore() { 00071 close(); 00072 } 00076 inline Db &getDb() { 00077 return db_; 00078 } 00082 void flush() { 00083 db_.sync(0); 00084 } 00088 void save(); 00092 void save_diff(); 00096 void init(); 00100 void save_size(); 00104 long long read_size(); 00108 void remove_size(); 00112 void save_transfer(); 00116 void remove_ransfer(); 00120 void read_transfer(); 00127 std::pair<bool, t_traffic> get_traffic_by_uid(const t_uid &ref); 00128 }; 00129 00130 #endif