Swarm-NG  1.1
bdb_writer.cpp
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) 2011 by Saleh Dindar and the Swarm-NG Development Team *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 3 of the License. *
7  * *
8  * This program is distributed in the hope that it will be useful, *
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11  * GNU General Public License for more details. *
12  * *
13  * You should have received a copy of the GNU General Public License *
14  * along with this program; if not, write to the *
15  * Free Software Foundation, Inc., *
16  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
17  ************************************************************************/
18 
25 #include "../common.hpp"
26 
27 #include "../types/config.hpp"
28 #include "../plugin.hpp"
29 
30 #include "log.hpp"
31 #include "writer.h"
32 
33 #include "bdb_database.hpp"
34 
35 namespace swarm { namespace log {
36 
37 using namespace gpulog;
38 
57 class bdb_writer : public writer
58 {
59  // To do this, first we have to include the BDB in the CMake files
60  // in process, we should make a gpulog::ilogstream out of the data
61  // and read all the gpulog records and put them in the database
62  // now the problem is what are we going to use for the key. Maybe we
63  // can use a very simple key and later on we can do secondary databases
64  // to make the indexes based on time and system id.
65 
66  DbEnv* env;
67  bdb_database db;
69 public:
70  bdb_writer(const config& cfg)
71  :env(bdb_database::createDefaultEnv())
72  ,db(env)
73  {
74  std::string fileName = cfg.require("log_output_db",std::string());
75  db.createEmpty(fileName);
76  }
77 
79  virtual void process(const char *log_data, size_t length) {
80  ilogstream stream(log_data,length);
81  while(logrecord lr = stream.next()){
82  db.put(lr);
83  }
84  db.flush();
85  }
86 
89  db.close();
90  env->close(0);
91  }
92 };
93 
96  bdb_writer_plugin("bdb", "This is the Berkeley DB writer");
97 
98 } }