libptpmgmt  1.4
libptpmgmt library that provides the functionality of linuxptp pmc
json.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: LGPL-3.0-or-later
2  SPDX-FileCopyrightText: Copyright © 2021 Erez Geva <ErezGeva2@gmail.com> */
3 
12 #ifndef __PTPMGMT_JSON_H
13 #define __PTPMGMT_JSON_H
14 
15 #ifdef __cplusplus
16 #include "msg.h"
17 
18 __PTPMGMT_NAMESPACE_BEGIN
19 
26 std::string msg2json(const Message &message, int indent = 0);
27 
35 std::string tlv2json(mng_vals_e managementId, const BaseMngTlv *tlv,
36  int indent = 0);
37 
43 class Json2msg
44 {
45  private:
46  std::unique_ptr<BaseMngTlv> m_tlvData;
47  /* Mandatory */
48  mng_vals_e m_managementId = NULL_PTP_MANAGEMENT;
49  actionField_e m_action = GET;
50  /* optional */
51  enum {
52  have_unicastFlag,
53  have_PTPProfileSpecific,
54  have_domainNumber,
55  have_versionPTP,
56  have_minorVersionPTP,
57  have_sequenceId,
58  have_sdoId,
59  have_srcPort,
60  have_dstPort,
61  have_limit,
62  };
63  bool m_have[have_limit] = { false };
64  bool m_unicastFlag = false;
65  uint8_t m_PTPProfileSpecific = 0, m_domainNumber = 0,
66  m_versionPTP = 2, m_minorVersionPTP = 1;
67  uint16_t m_sequenceId = 0;
68  uint32_t m_sdoId = 0;
69  PortIdentity_t m_srcPort = {{0}, 0}, m_dstPort = {{0}, 0};
70  public:
71  /* keep for ABI backward compatibility. */
72  ~Json2msg();
75  __PTPMGMT_DEPRECATED_DEC(static bool selectLib(const std::string &));
76  __PTPMGMT_DEPRECATED_DEC(static const char *loadLibrary());
77  __PTPMGMT_DEPRECATED_DEC(static bool isLibShared());
78  __PTPMGMT_DEPRECATED_DEC(bool fromJsonObj(const void *));
85  bool fromJson(const std::string &json);
90  mng_vals_e managementId() const { return m_managementId; }
96  const BaseMngTlv *dataField() const { return m_tlvData.get(); }
101  actionField_e actionField() const { return m_action; }
106  bool isUnicast() const { return m_unicastFlag; }
111  bool haveIsUnicast() const { return m_have[have_unicastFlag]; }
116  uint8_t PTPProfileSpecific() const { return m_PTPProfileSpecific; }
121  bool havePTPProfileSpecific() const { return m_have[have_PTPProfileSpecific]; }
126  uint8_t domainNumber() const { return m_domainNumber; }
131  bool haveDomainNumber() const { return m_have[have_domainNumber]; }
136  uint8_t versionPTP() const { return m_versionPTP; }
141  bool haveVersionPTP() const { return m_have[have_versionPTP]; }
146  uint8_t minorVersionPTP() const { return m_minorVersionPTP; }
151  bool haveMinorVersionPTP() const { return m_have[have_minorVersionPTP]; }
156  uint16_t sequenceId() const { return m_sequenceId; }
161  bool haveSequenceId() const { return m_have[have_sequenceId]; }
166  uint32_t sdoId() const { return m_sdoId; }
171  bool haveSdoId() const { return m_have[have_sdoId]; }
176  const PortIdentity_t &srcPort() const { return m_srcPort; }
181  bool haveSrcPort() const { return m_have[have_srcPort]; }
186  const PortIdentity_t &dstPort() const { return m_dstPort; }
191  bool haveDstPort() const { return m_have[have_dstPort]; }
196  bool setAction(Message &message) const {
197  return message.setAction(m_action, m_managementId, m_tlvData.get());
198  }
199 };
200 
201 __PTPMGMT_NAMESPACE_END
202 #else /* __cplusplus */
203 #include "c/json.h"
204 #endif /* __cplusplus */
205 
206 #endif /* __PTPMGMT_JSON_H */
Convert a management or a signalling message to JSON.
Create and parse PTP management messages.
Definition: json.h:44
mng_vals_e managementId() const
Definition: json.h:90
bool haveVersionPTP() const
Definition: json.h:141
uint32_t sdoId() const
Definition: json.h:166
bool haveSdoId() const
Definition: json.h:171
actionField_e actionField() const
Definition: json.h:101
bool haveDomainNumber() const
Definition: json.h:131
uint8_t PTPProfileSpecific() const
Definition: json.h:116
uint8_t versionPTP() const
Definition: json.h:136
bool havePTPProfileSpecific() const
Definition: json.h:121
uint8_t domainNumber() const
Definition: json.h:126
bool isUnicast() const
Definition: json.h:106
bool haveSequenceId() const
Definition: json.h:161
bool fromJson(const std::string &json)
const PortIdentity_t & srcPort() const
Definition: json.h:176
bool haveSrcPort() const
Definition: json.h:181
bool setAction(Message &message) const
Definition: json.h:196
const BaseMngTlv * dataField() const
Definition: json.h:96
const PortIdentity_t & dstPort() const
Definition: json.h:186
uint16_t sequenceId() const
Definition: json.h:156
bool haveMinorVersionPTP() const
Definition: json.h:151
bool haveDstPort() const
Definition: json.h:191
uint8_t minorVersionPTP() const
Definition: json.h:146
bool haveIsUnicast() const
Definition: json.h:111
Handle PTP management message.
Definition: msg.h:58
bool setAction(actionField_e actionField, mng_vals_e tlv_id, const BaseMngTlv *dataSend=nullptr)
__PTPMGMT_NAMESPACE_BEGIN std::string msg2json(const Message &message, int indent=0)
std::string tlv2json(mng_vals_e managementId, const BaseMngTlv *tlv, int indent=0)
mng_vals_e
Management TLVs ID.
Definition: mngIds.h:29
Definition: types.h:962
Definition: types.h:717
actionField_e
Definition: types.h:191
@ GET
Definition: types.h:192