DDS  ver. 2.0
ncf.h
Go to the documentation of this file.
1 // Copyright 2014 GSI, Inc. All rights reserved.
2 //
3 //
4 //
5 #ifndef NCF_H
6 #define NCF_H
7 //
8 // - - - - - = = = DDS NCF (nodes configuration file parcer) = = = - - - - -
9 //
10 // a configuration should be a comma-separated values (CSV) with
11 // the following records:
12 //
13 // id, login@host.fqdn, ssh params, remote working dir, number of workers,
15 // r1, anar@lxg0527.gsi.de, -p24, /tmp/test, 4
16 // r2, anar@lxi001.gsi.de,,/tmp/test,2
17 // 125, anar@lxg0055.gsi.de, -p22, /tmp/test,8
18 // ________________________________________________________
19 //
20 // it can be read from a stream.
21 // Fields are normally separated by commas. If you want to put a comma in a field,
22 // you need to put quotes around it. Also 3 escape sequences are supported.
23 //
24 //=============================================================================
25 // std
26 #include <sstream>
27 #include <vector>
28 // BOOST
29 #include <boost/shared_ptr.hpp>
30 // MiscCommon
31 #include "MiscUtils.h"
32 namespace dds
33 {
34  namespace ncf
35  {
36  //=============================================================================
39  {
41  : m_nWorkers(0)
42  {
43  }
44  template <class InputIterator>
45  int assignValues(const InputIterator& _begin, const InputIterator& _end)
46  {
47  InputIterator iter = _begin;
48  if (iter == _end)
49  return 1;
50  m_id = *iter;
51  MiscCommon::trim(&m_id, ' ');
52 
53  if (++iter == _end)
54  return 2;
55  m_addr = *iter;
56  MiscCommon::trim(&m_addr, ' ');
57 
58  if (++iter == _end)
59  return 3;
60  m_sshOptions = *iter;
62 
63  if (++iter == _end)
64  return 4;
65  m_wrkDir = *iter;
67 
68  if (++iter == _end)
69  return 5;
70  if (!iter->empty())
71  {
72  std::stringstream ss;
73  ss << *iter;
74  ss >> m_nWorkers;
75  }
76 
77  return 0;
78  }
79  bool operator==(const SConfigRecord& _rec) const
80  {
81  return (m_id == _rec.m_id && m_addr == _rec.m_addr && m_sshOptions == _rec.m_sshOptions &&
82  m_wrkDir == _rec.m_wrkDir && m_nWorkers == _rec.m_nWorkers);
83  }
84  std::string m_id;
85  std::string m_addr;
86  std::string m_sshOptions;
87  std::string m_wrkDir;
88  size_t m_nWorkers;
89  };
90  //=============================================================================
91  typedef boost::shared_ptr<SConfigRecord> configRecord_t;
92  typedef std::vector<configRecord_t> configRecords_t;
93  //=============================================================================
94  class CNcf
95  {
96  public:
97  void readFrom(std::istream& _stream, bool _readBashOnly = false);
98  configRecords_t getRecords();
99  std::string getBashEnvCmds()
100  {
101  return m_bashEnvCmds;
102  }
103 
104  private:
105  configRecords_t m_records;
106  std::string m_bashEnvCmds;
107  };
108  }
109 }
110 #endif
this class represents a single record of a dds-ssh configuration file
Definition: ncf.h:38
std::vector< configRecord_t > configRecords_t
Definition: ncf.h:92
int assignValues(const InputIterator &_begin, const InputIterator &_end)
Definition: ncf.h:45
std::string getBashEnvCmds()
Definition: ncf.h:99
bool operator==(const SConfigRecord &_rec) const
Definition: ncf.h:79
size_t m_nWorkers
Definition: ncf.h:88
Definition: dds-agent/src/AgentConnectionManager.h:18
Definition: ncf.h:94
SConfigRecord()
Definition: ncf.h:40
std::string m_id
Definition: ncf.h:84
_T & trim(_T *_pString, const typename _T::value_type &_chWhat)
trims trailing and leading characters from the string.
Definition: MiscUtils.h:169
std::string m_sshOptions
Definition: ncf.h:86
std::string m_wrkDir
Definition: ncf.h:87
boost::shared_ptr< SConfigRecord > configRecord_t
Definition: ncf.h:91
std::string m_addr
Definition: ncf.h:85