DDS  ver. 2.0
dds_env_prop.h
Go to the documentation of this file.
1 // Copyright 2015 GSI, Inc. All rights reserved.
2 //
3 //
4 //
5 #ifndef DDSENVPROP_H_
6 #define DDSENVPROP_H_
7 
8 // STD
9 #include <cstdlib>
10 #include <string>
11 
12 namespace dds
13 {
15  enum EEnvProp
16  {
27  };
28 
37  template <EEnvProp T>
38  inline typename std::enable_if<T == task_id, uint64_t>::type env_prop()
39  {
40  size_t ret(0);
41  std::string envName;
42  switch (T)
43  {
44  case task_id:
45  envName = "DDS_TASK_ID";
46  break;
47  default:
48  return 0;
49  }
50  const char* env = std::getenv(envName.c_str());
51  if (nullptr == env)
52  return ret;
53 
54  try
55  {
56  ret = std::stoul(env);
57  }
58  catch (...)
59  {
60  return 0;
61  }
62 
63  return ret;
64  }
65 
74  template <EEnvProp T>
75  inline typename std::enable_if<T == task_index || T == collection_index, size_t>::type env_prop()
76  {
77  size_t ret(0);
78  std::string envName;
79  switch (T)
80  {
81  case task_index:
82  envName = "DDS_TASK_INDEX";
83  break;
84  case collection_index:
85  envName = "DDS_COLLECTION_INDEX";
86  break;
87  default:
88  return 0;
89  }
90  const char* env = std::getenv(envName.c_str());
91  if (nullptr == env)
92  return ret;
93 
94  try
95  {
96  ret = std::stoi(env);
97  }
98  catch (...)
99  {
100  return 0;
101  }
102 
103  return ret;
104  }
105 
114  template <EEnvProp T>
115  inline typename std::enable_if<T == task_name || T == collection_name || T == group_name || T == dds_location ||
116  T == task_path || T == dds_session_id,
117  std::string>::type
119  {
120  std::string envName;
121  switch (T)
122  {
123  case task_name:
124  envName = "DDS_TASK_NAME";
125  break;
126  case collection_name:
127  envName = "DDS_COLLECTION_NAME";
128  break;
129  case group_name:
130  envName = "DDS_GROUP_NAME";
131  break;
132  case dds_location:
133  envName = "DDS_LOCATION";
134  break;
135  case task_path:
136  envName = "DDS_TASK_PATH";
137  break;
138  case dds_session_id:
139  envName = "DDS_SESSION_ID";
140  break;
141  default:
142  return 0;
143  }
144  const char* env = std::getenv(envName.c_str());
145  if (nullptr == env)
146  return "";
147 
148  return std::string(env);
149  }
150 };
151 
152 #endif /*DDSENVPROP_H_*/
associated with $DDS_COLLECTION_NAME - ID of the parent collection.
Definition: dds_env_prop.h:23
associated with $DDS_TASK_PATH - full path to the user task, for example, main/group1/collection_12/t...
Definition: dds_env_prop.h:20
std::enable_if< T==task_id, uint64_t >::type env_prop()
The function returns a value for a given environment property.
Definition: dds_env_prop.h:38
Definition: dds-agent/src/AgentConnectionManager.h:18
associated with $DDS_TASK_ID environment variable.
Definition: dds_env_prop.h:17
associated with $DDS_GROUP_NAME - ID of the parent group.
Definition: dds_env_prop.h:24
EEnvProp
a list of envioronment properties
Definition: dds_env_prop.h:15
associated with $DDS_TASK_NAME - ID of the task.
Definition: dds_env_prop.h:19
associated with $DDS_SESSION_ID - session ID of the DDS.
Definition: dds_env_prop.h:26
associated with $DDS_TASK_INDEX environment variable.
Definition: dds_env_prop.h:18
associated with $DDS_COLLECTION_INDEX environemnt variable.
Definition: dds_env_prop.h:22
associated with $DDS_LOCATION environemnt variable.
Definition: dds_env_prop.h:25