DDS  ver. 3.4
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  {
42  }
43  template <class InputIterator>
44  int assignValues(const InputIterator& _begin, const InputIterator& _end)
45  {
46  InputIterator iter = _begin;
47  if (iter == _end)
48  return 1;
49  m_id = *iter;
50  MiscCommon::trim(&m_id, ' ');
51 
52  if (++iter == _end)
53  return 2;
54  m_addr = *iter;
55  MiscCommon::trim(&m_addr, ' ');
56 
57  if (++iter == _end)
58  return 3;
59  m_sshOptions = *iter;
61 
62  if (++iter == _end)
63  return 4;
64  m_wrkDir = *iter;
66 
67  if (++iter == _end)
68  return 5;
69  if (!iter->empty())
70  {
71  std::stringstream ss;
72  ss << *iter;
73  ss >> m_nSlots;
74  }
75 
76  return 0;
77  }
78  bool operator==(const SConfigRecord& _rec) const
79  {
80  return (m_id == _rec.m_id && m_addr == _rec.m_addr && m_sshOptions == _rec.m_sshOptions &&
81  m_wrkDir == _rec.m_wrkDir && m_nSlots == _rec.m_nSlots);
82  }
83  std::string m_id;
84  std::string m_addr;
85  std::string m_sshOptions;
86  std::string m_wrkDir;
87  size_t m_nSlots{ 1 };
88  };
89  //=============================================================================
90  typedef boost::shared_ptr<SConfigRecord> configRecord_t;
91  typedef std::vector<configRecord_t> configRecords_t;
92  //=============================================================================
93  class CNcf
94  {
95  public:
96  void readFrom(std::istream& _stream, bool _readBashOnly = false);
98  std::string getBashEnvCmds()
99  {
100  return m_bashEnvCmds;
101  }
102 
103  private:
104  configRecords_t m_records;
105  std::string m_bashEnvCmds;
106  };
107  } // namespace ncf
108 } // namespace dds
109 #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:91
int assignValues(const InputIterator &_begin, const InputIterator &_end)
Definition: ncf.h:44
std::string getBashEnvCmds()
Definition: ncf.h:98
bool operator==(const SConfigRecord &_rec) const
Definition: ncf.h:78
Definition: AgentConnectionManager.h:13
Definition: ncf.h:93
SConfigRecord()
Definition: ncf.h:40
std::string m_id
Definition: ncf.h:83
_T & trim(_T *_pString, const typename _T::value_type &_chWhat)
trims trailing and leading characters from the string.
Definition: MiscUtils.h:173
size_t m_nSlots
Definition: ncf.h:87
std::string m_sshOptions
Definition: ncf.h:85
std::string m_wrkDir
Definition: ncf.h:86
boost::shared_ptr< SConfigRecord > configRecord_t
Definition: ncf.h:90
std::string m_addr
Definition: ncf.h:84
void readFrom(std::istream &_stream, bool _readBashOnly=false)
Definition: ncf.cpp:28
configRecords_t getRecords()
Definition: ncf.cpp:110