-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #497 from CopernicaMarketingSoftware/better-connec…
…tion-info Add more information to the ConnectionStartFrame
- Loading branch information
Showing
6 changed files
with
197 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* PlatformName.h | ||
* | ||
* Class to extract the platform name (operating system, etc) | ||
* | ||
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | ||
* @copyright 2023 Copernica BV | ||
*/ | ||
|
||
/** | ||
* Include guard | ||
*/ | ||
#pragma once | ||
|
||
/** | ||
* Dependencies | ||
*/ | ||
#include <sys/utsname.h> | ||
|
||
/** | ||
* Begin of namespace | ||
*/ | ||
namespace AMQP { | ||
|
||
/** | ||
* Class definition | ||
*/ | ||
class PlatformName | ||
{ | ||
private: | ||
/** | ||
* The string holding all info | ||
* @var std::string | ||
*/ | ||
std::string _value; | ||
|
||
public: | ||
/** | ||
* Constructor | ||
*/ | ||
PlatformName() | ||
{ | ||
// all information | ||
struct utsname info; | ||
|
||
// retrieve system info | ||
if (uname(&info) != 0) return; | ||
|
||
// add all info | ||
_value.append(info.sysname).append(" ").append(info.nodename).append(" ").append(info.release).append(" ").append(info.version); | ||
} | ||
|
||
/** | ||
* Destructor | ||
*/ | ||
virtual ~PlatformName() = default; | ||
|
||
/** | ||
* Cast to a const char * | ||
* @return const char * | ||
*/ | ||
operator const char * () const { return _value.data(); } | ||
}; | ||
|
||
/** | ||
* End of namespace | ||
*/ | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* ProgramName.h | ||
* | ||
* Helper class that detects the name of the program | ||
* | ||
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | ||
* @copyright 2023 Copernica BV | ||
*/ | ||
|
||
/** | ||
* Include guard | ||
*/ | ||
#pragma once | ||
|
||
/** | ||
* Dependencies | ||
*/ | ||
#include <limits.h> | ||
#include <unistd.h> | ||
|
||
/** | ||
* Begin of namespace | ||
*/ | ||
namespace AMQP { | ||
|
||
/** | ||
* Class definition | ||
*/ | ||
class ProgramName | ||
{ | ||
private: | ||
/** | ||
* Path of the program | ||
* @var char[] | ||
*/ | ||
char _path[PATH_MAX]; | ||
|
||
/** | ||
* Is the _path valid? | ||
* @var bool | ||
*/ | ||
bool _valid; | ||
|
||
public: | ||
/** | ||
* Constructor | ||
*/ | ||
ProgramName() | ||
{ | ||
// read the link target | ||
auto size = readlink("/proc/self/exe", _path, PATH_MAX); | ||
|
||
// -1 is returned on error, otherwise the size | ||
_valid = size >= 0; | ||
|
||
// set trailing null byte | ||
_path[size == PATH_MAX ? PATH_MAX-1 : size] = '\0'; | ||
} | ||
|
||
/** | ||
* Destructor | ||
*/ | ||
virtual ~ProgramName() = default; | ||
|
||
/** | ||
* Cast to a const char * | ||
* @return const char * | ||
*/ | ||
operator const char * () const | ||
{ | ||
// empty string when not valid | ||
if (!_valid) return ""; | ||
|
||
// return path to executable | ||
return _path; | ||
} | ||
}; | ||
|
||
/** | ||
* End of namespace | ||
*/ | ||
} |