@@ -24,6 +24,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2424#include < sstream>
2525#include < map>
2626
27+ #include " StructuredLoggingKeys.hpp"
2728#include " ServiceConfigKeys.hpp"
2829#include " Configuration.hpp"
2930#include " EndpointAddress.hpp"
@@ -70,6 +71,8 @@ class ServiceDescriptor
7071 inline bool operator ==(const ServiceDescriptor& rhs) const ;
7172 inline bool operator !=(const ServiceDescriptor& rhs) const ;
7273 inline std::string to_string () const ;
74+ inline std::vector<std::pair<std::string, std::string>> to_keyValues () const ;
75+
7376 inline Core::EndpointAddress to_endpointAddress () const ;
7477
7578public:
@@ -304,6 +307,47 @@ std::string ServiceDescriptor::to_string() const
304307 return ss.str ();
305308}
306309
310+
311+ std::vector<std::pair<std::string, std::string>> ServiceDescriptor::to_keyValues () const
312+ {
313+ namespace Keys = SilKit::Services::Logging::Keys;
314+
315+ std::vector<std::pair<std::string, std::string>> kv;
316+ std::string controllerTypeName;
317+ std::stringstream ss;
318+
319+ kv.push_back ({Keys::participantName, GetParticipantName ()});
320+
321+ switch (GetServiceType ())
322+ {
323+ case ServiceType::Link:
324+ kv.push_back ({Keys::networkType, Config::to_string (GetNetworkType ())});
325+ kv.push_back ({Keys::networkName, GetNetworkName ()});
326+ break ;
327+ case ServiceType::Controller:
328+ case ServiceType::SimulatedController:
329+ if (!GetSupplementalDataItem (SilKit::Core::Discovery::controllerType, controllerTypeName))
330+ {
331+ throw LogicError (
332+ " ServiceDescriptor::to_keyValues() failed: No controller type defined in supplemental data." );
333+ }
334+ kv.push_back ({Keys::controllerTypeName, controllerTypeName});
335+ kv.push_back ({Keys::networkName, GetNetworkName ()});
336+ kv.push_back ({Keys::serviceName, GetServiceName ()});
337+ break ;
338+ case ServiceType::InternalController:
339+ kv.push_back ({Keys::serviceName, GetServiceName ()});
340+ break ;
341+ case ServiceType::Undefined:
342+ kv.push_back ({Keys::networkName, GetNetworkName ()});
343+ kv.push_back ({Keys::serviceName, GetServiceName ()});
344+ break ;
345+ }
346+
347+ kv.push_back ({Keys::serviceType, SilKit::Core::to_string (GetServiceType ())});
348+ return kv;
349+ }
350+
307351EndpointAddress ServiceDescriptor::to_endpointAddress () const
308352{
309353 return {GetParticipantId (), GetServiceId ()};
0 commit comments