Belle II Software  release-08-01-10
DBInterface.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #include "daq/slc/database/DBInterface.h"
9 
10 #include <daq/slc/base/StringUtil.h>
11 #include <daq/slc/system/LockGuard.h>
12 #include <daq/slc/system/LogFile.h>
13 
14 #include <cstdarg>
15 #include <cstdio>
16 
17 using namespace Belle2;
18 
19 DBInterface::DBInterface(const std::string& host,
20  const std::string& database,
21  const std::string& user,
22  const std::string& password, int port)
23 {
24  init(host, database, user, password, port);
25 }
26 
27 DBInterface::~DBInterface()
28 {
29  delete [] m_buf;
30 }
31 
32 void DBInterface::init(const std::string& host,
33  const std::string& database,
34  const std::string& user,
35  const std::string& password, int port)
36 {
37  m_host = host;
38  m_database = database;
39  m_user = user;
40  m_password = password;
41  m_port = port;
42  m_buf = new char[m_buf_size];
43 }
44 
45 void DBInterface::execute(const char* text, ...)
46 {
47  StringList s;
48 
49  {
50  LockGuard lockGuard(m_mutex);
51 
52  va_list ap;
53  va_start(ap, text);
54  vsnprintf(m_buf, m_buf_size, text, ap);
55  va_end(ap);
56  //std::cout << m_buf << std::endl;
57  //execute_imp(m_buf);
58  s = StringUtil::split(m_buf, ';');
59  }
60 
61  for (size_t i = 0; i < s.size(); i++)
62  execute_imp(s[i].c_str());
63 }
64 
65 void DBInterface::execute(const std::string& text)
66 {
67  //std::cout << text << std::endl;
68  StringList s = StringUtil::split(text, ';');
69  for (size_t i = 0; i < s.size(); i++)
70  execute_imp(s[i].c_str());
71 }
72 
Lock Guard for a Mutex instance.
Definition: LockGuard.h:47
Abstract base class for different kinds of events.