Skip to content

Commit 9524205

Browse files
committed
[occ] Support environment variable for control port
1 parent ce8471a commit 9524205

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

occ/OccGlobals.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@
2222
* Intergovernmental Organization or submit itself to any jurisdiction.
2323
*/
2424

25+
/** @file OccGlobals.h
26+
* @brief Global constants for OCC library.
27+
*/
28+
2529
#ifndef OCC_OCCGLOBALS_H
2630
#define OCC_OCCGLOBALS_H
2731

28-
#define OCC_DEFAULT_PORT 47100
29-
#define OCC_CONTROL_PORT_ARG "control-port"
32+
#define OCC_DEFAULT_PORT 47100 /// Fallback value for the control port
33+
#define OCC_CONTROL_PORT_ARG "control-port" /// Name of the boost::program_option to use for the control port parameter
34+
#define OCC_CONTROL_PORT_ENV "OCC_CONTROL_PORT" /// Name of the env variable to query for the control port
3035

3136
#endif //OCC_OCCGLOBALS_H

occ/occlib/OccInstance.cxx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ using namespace std::literals;
3434

3535
OccInstance::OccInstance(RuntimeControlledObject *rco, int controlPort)
3636
{
37+
if (!controlPort) {
38+
if (const char* env_controlPort = std::getenv(OCC_CONTROL_PORT_ENV)) {
39+
controlPort = std::atoi(env_controlPort);
40+
}
41+
else {
42+
controlPort = OCC_DEFAULT_PORT;
43+
std::cout << "no control port configured, defaulting to " << OCC_DEFAULT_PORT;
44+
}
45+
}
3746
m_grpcThread = std::thread(&OccInstance::runServer, this, rco, controlPort);
3847
}
3948

occ/occlib/OccInstance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class RuntimeControlledObject;
3939
class OCC_EXPORT OccInstance
4040
{
4141
public:
42-
explicit OccInstance(RuntimeControlledObject *rco, int controlPort = OCC_DEFAULT_PORT);
42+
explicit OccInstance(RuntimeControlledObject *rco, int controlPort = 0);
4343
explicit OccInstance(RuntimeControlledObject *rco, const boost::program_options::variables_map& vm);
4444
virtual ~OccInstance();
4545

0 commit comments

Comments
 (0)