• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

TEN-framework / ten-framework / 20008373563

07 Dec 2025 06:18PM UTC coverage: 55.723% (+1.1%) from 54.616%
20008373563

push

github

web-flow
fix: coveralls app arguments (#1835)

* fix: coveralls app arguments

* fix: path consistency in lcov and work env

---------

Co-authored-by: Nie Zhihe <niezhihe@shengwang.cn>

45848 of 82278 relevant lines covered (55.72%)

795052.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

46.69
/core/include/ten_runtime/binding/cpp/detail/msg/msg.h
1
//
2
// Copyright © 2025 Agora
3
// This file is part of TEN Framework, an open source project.
4
// Licensed under the Apache License, Version 2.0, with certain conditions.
5
// Refer to the "LICENSE" file in the root directory for more information.
6
//
7
#pragma once
8

9
#include "ten_runtime/ten_config.h"
10

11
#include <string>
12

13
#include "ten_runtime/binding/cpp/detail/loc.h"
14
#include "ten_runtime/common/error_code.h"
15
#include "ten_runtime/common/loc.h"
16
#include "ten_runtime/msg/msg.h"
17
#include "ten_utils/lang/cpp/lib/error.h"
18
#include "ten_utils/lang/cpp/lib/value.h"
19
#include "ten_utils/lib/buf.h"
20
#include "ten_utils/lib/json.h"
21
#include "ten_utils/lib/smart_ptr.h"
22
#include "ten_utils/macro/check.h"
23
#include "ten_utils/value/value.h"
24
#include "ten_utils/value/value_get.h"
25
#include "ten_utils/value/value_json.h"
26

27
namespace ten {
28

29
class ten_env_t;
30
class cmd_result_t;
31
class msg_t;
32
class msg_internal_accessor_t;
33

34
class msg_t {
35
 public:
36
  virtual ~msg_t() { relinquish_underlying_msg(); }
66,921✔
37

38
  // @{
39
  msg_t(msg_t &other) = delete;
40
  msg_t(msg_t &&other) = delete;
41
  msg_t &operator=(const msg_t &other) = delete;
42
  msg_t &operator=(msg_t &&other) noexcept = delete;
43
  // @}
44

45
  explicit operator bool() const { return c_msg != nullptr; }
×
46

47
  std::string get_name(error_t *err = nullptr) const {
2,789✔
48
    TEN_ASSERT(c_msg, "Should not happen.");
2,789✔
49

50
    if (c_msg == nullptr) {
2,789✔
51
      if (err != nullptr && err->get_c_error() != nullptr) {
×
52
        ten_error_set(err->get_c_error(), TEN_ERROR_CODE_GENERIC,
×
53
                      "Invalid TEN message.");
×
54
      }
×
55
      return "";
×
56
    }
×
57

58
    return ten_msg_get_name(c_msg);
2,789✔
59
  }
2,789✔
60

61
  loc_t get_source(error_t *err = nullptr) const {
18✔
62
    TEN_ASSERT(c_msg, "Should not happen.");
18✔
63

64
    if (c_msg == nullptr) {
18✔
65
      if (err != nullptr && err->get_c_error() != nullptr) {
×
66
        ten_error_set(err->get_c_error(), TEN_ERROR_CODE_INVALID_ARGUMENT,
×
67
                      "Invalid TEN message.");
×
68
      }
×
69
      return {nullptr, nullptr, nullptr};
×
70
    }
×
71

72
    const char *app_uri = nullptr;
18✔
73
    const char *graph_id = nullptr;
18✔
74
    const char *extension_name = nullptr;
18✔
75

76
    ten_msg_get_source(c_msg, &app_uri, &graph_id, &extension_name,
18✔
77
                       err != nullptr ? err->get_c_error() : nullptr);
18✔
78

79
    return {optional<std::string>{app_uri}, optional<std::string>{graph_id},
18✔
80
            optional<std::string>{extension_name}};
18✔
81
  }
18✔
82

83
  bool set_dests(const std::vector<loc_t> &dests,
84
                 error_t *err = nullptr) const {
1,878✔
85
    TEN_ASSERT(c_msg, "Should not happen.");
1,878✔
86

87
    if (c_msg == nullptr) {
1,878✔
88
      if (err != nullptr && err->get_c_error() != nullptr) {
×
89
        ten_error_set(err->get_c_error(), TEN_ERROR_CODE_INVALID_ARGUMENT,
×
90
                      "Invalid TEN message.");
×
91
      }
×
92
      return false;
×
93
    }
×
94

95
    for (const auto &dest : dests) {
1,878✔
96
      if (!ten_loc_str_check_correct(
1,878✔
97
              dest.app_uri ? dest.app_uri->c_str() : nullptr,
1,878✔
98
              dest.graph_id ? dest.graph_id->c_str() : nullptr,
1,878✔
99
              dest.extension_name ? dest.extension_name->c_str() : nullptr,
1,878✔
100
              err != nullptr ? err->get_c_error() : nullptr)) {
1,878✔
101
        return false;
×
102
      }
×
103
    }
1,878✔
104

105
    ten_msg_clear_dest(c_msg);
1,878✔
106

107
    for (const auto &dest : dests) {
1,878✔
108
      ten_msg_add_dest(
1,878✔
109
          c_msg, dest.app_uri ? dest.app_uri->c_str() : nullptr,
1,878✔
110
          dest.graph_id ? dest.graph_id->c_str() : nullptr,
1,878✔
111
          dest.extension_name ? dest.extension_name->c_str() : nullptr);
1,878✔
112
    }
1,878✔
113

114
    return true;
1,878✔
115
  }
1,878✔
116

117
  bool is_property_exist(const char *path, error_t *err = nullptr) {
7✔
118
    TEN_ASSERT(c_msg, "Should not happen.");
7✔
119

120
    if (c_msg == nullptr) {
7✔
121
      if (err != nullptr && err->get_c_error() != nullptr) {
×
122
        ten_error_set(err->get_c_error(), TEN_ERROR_CODE_INVALID_ARGUMENT,
×
123
                      "Invalid TEN message.");
×
124
      }
×
125
      return false;
×
126
    }
×
127

128
    TEN_ASSERT(path && strlen(path), "path should not be empty.");
7✔
129

130
    return ten_msg_is_property_exist(
7✔
131
        c_msg, path, err != nullptr ? err->get_c_error() : nullptr);
7✔
132
  }
7✔
133

134
  uint8_t get_property_uint8(const char *path, error_t *err = nullptr) {
×
135
    ten_value_t *c_value = peek_property_value(path, err);
×
136
    if (c_value == nullptr) {
×
137
      return 0;
×
138
    }
×
139
    return ten_value_get_uint8(c_value,
×
140
                               err != nullptr ? err->get_c_error() : nullptr);
×
141
  }
×
142

143
  uint16_t get_property_uint16(const char *path, error_t *err = nullptr) {
×
144
    ten_value_t *c_value = peek_property_value(path, err);
×
145
    if (c_value == nullptr) {
×
146
      return 0;
×
147
    }
×
148
    return ten_value_get_uint16(c_value,
×
149
                                err != nullptr ? err->get_c_error() : nullptr);
×
150
  }
×
151

152
  uint32_t get_property_uint32(const char *path, error_t *err = nullptr) {
×
153
    ten_value_t *c_value = peek_property_value(path, err);
×
154
    if (c_value == nullptr) {
×
155
      return 0;
×
156
    }
×
157
    return ten_value_get_uint32(c_value,
×
158
                                err != nullptr ? err->get_c_error() : nullptr);
×
159
  }
×
160

161
  uint64_t get_property_uint64(const char *path, error_t *err = nullptr) {
×
162
    ten_value_t *c_value = peek_property_value(path, err);
×
163
    if (c_value == nullptr) {
×
164
      return 0;
×
165
    }
×
166
    return ten_value_get_uint64(c_value,
×
167
                                err != nullptr ? err->get_c_error() : nullptr);
×
168
  }
×
169

170
  int8_t get_property_int8(const char *path, error_t *err = nullptr) {
×
171
    ten_value_t *c_value = peek_property_value(path, err);
×
172
    if (c_value == nullptr) {
×
173
      return 0;
×
174
    }
×
175
    return ten_value_get_int8(c_value,
×
176
                              err != nullptr ? err->get_c_error() : nullptr);
×
177
  }
×
178

179
  int16_t get_property_int16(const char *path, error_t *err = nullptr) {
×
180
    ten_value_t *c_value = peek_property_value(path, err);
×
181
    if (c_value == nullptr) {
×
182
      return 0;
×
183
    }
×
184
    return ten_value_get_int16(c_value,
×
185
                               err != nullptr ? err->get_c_error() : nullptr);
×
186
  }
×
187

188
  int32_t get_property_int32(const char *path, error_t *err = nullptr) {
24✔
189
    ten_value_t *c_value = peek_property_value(path, err);
24✔
190
    if (c_value == nullptr) {
24✔
191
      return 0;
1✔
192
    }
1✔
193
    return ten_value_get_int32(c_value,
23✔
194
                               err != nullptr ? err->get_c_error() : nullptr);
23✔
195
  }
24✔
196

197
  int64_t get_property_int64(const char *path, error_t *err = nullptr) {
27✔
198
    ten_value_t *c_value = peek_property_value(path, err);
27✔
199
    if (c_value == nullptr) {
27✔
200
      return 0;
×
201
    }
×
202
    return ten_value_get_int64(c_value,
27✔
203
                               err != nullptr ? err->get_c_error() : nullptr);
27✔
204
  }
27✔
205

206
  float get_property_float32(const char *path, error_t *err = nullptr) {
×
207
    ten_value_t *c_value = peek_property_value(path, err);
×
208
    if (c_value == nullptr) {
×
209
      return 0.0F;
×
210
    }
×
211
    return ten_value_get_float32(c_value,
×
212
                                 err != nullptr ? err->get_c_error() : nullptr);
×
213
  }
×
214

215
  double get_property_float64(const char *path, error_t *err = nullptr) {
×
216
    ten_value_t *c_value = peek_property_value(path, err);
×
217
    if (c_value == nullptr) {
×
218
      return 0.0F;
×
219
    }
×
220
    return ten_value_get_float64(c_value,
×
221
                                 err != nullptr ? err->get_c_error() : nullptr);
×
222
  }
×
223

224
  std::string get_property_string(const char *path, error_t *err = nullptr) {
1,040✔
225
    ten_value_t *c_value = peek_property_value(path, err);
1,040✔
226
    if (c_value == nullptr) {
1,040✔
227
      return "";
4✔
228
    }
4✔
229

230
    const char *raw_str = ten_value_peek_raw_str(
1,036✔
231
        c_value, err != nullptr ? err->get_c_error() : nullptr);
1,036✔
232

233
    if (raw_str == nullptr) {
1,036✔
234
      TEN_ASSERT(0, "Should not happen.");
×
235
      return "";
×
236
    }
×
237

238
    return raw_str;
1,036✔
239
  }
1,036✔
240

241
  void *get_property_ptr(const char *path, error_t *err = nullptr) {
26,661✔
242
    ten_value_t *c_value = peek_property_value(path, err);
26,661✔
243
    if (c_value == nullptr) {
26,661✔
244
      return nullptr;
×
245
    }
×
246
    return ten_value_get_ptr(c_value,
26,661✔
247
                             err != nullptr ? err->get_c_error() : nullptr);
26,661✔
248
  }
26,661✔
249

250
  bool get_property_bool(const char *path, error_t *err = nullptr) {
10✔
251
    ten_value_t *c_value = peek_property_value(path, err);
10✔
252
    if (c_value == nullptr) {
10✔
253
      return false;
×
254
    }
×
255
    return ten_value_get_bool(c_value,
10✔
256
                              err != nullptr ? err->get_c_error() : nullptr);
10✔
257
  }
10✔
258

259
  // Pay attention to its copy semantics.
260
  ten::buf_t get_property_buf(const char *path, error_t *err = nullptr) {
×
261
    auto result = ten::buf_t{};
×
262

×
263
    ten_value_t *c_value = peek_property_value(path, err);
×
264
    if (c_value == nullptr) {
×
265
      return result;
×
266
    }
×
267

×
268
    ten_buf_t *c_buf = ten_value_peek_buf(
×
269
        c_value, err != nullptr ? err->get_c_error() : nullptr);
×
270
    if (c_buf == nullptr) {
×
271
      return result;
×
272
    }
×
273

×
274
    ten_buf_init_with_copying_data(&result.buf, c_buf->data, c_buf->size);
×
275

×
276
    return result;
×
277
  }
×
278

279
  std::string get_property_to_json(const char *path = nullptr,
280
                                   error_t *err = nullptr) const {
928✔
281
    if (c_msg == nullptr) {
928✔
282
      if (err != nullptr && err->get_c_error() != nullptr) {
×
283
        ten_error_set(err->get_c_error(), TEN_ERROR_CODE_INVALID_ARGUMENT,
×
284
                      "Invalid TEN message.");
×
285
      }
×
286
      return "";
×
287
    }
×
288

289
    std::string result;
928✔
290

291
    auto *value = peek_property_value(path, err);
928✔
292
    if (value == nullptr) {
928✔
293
      return result;
×
294
    }
×
295

296
    ten_json_t c_json = TEN_JSON_INIT_VAL(ten_json_create_new_ctx(), true);
928✔
297
    bool success = ten_value_to_json(value, &c_json);
928✔
298
    if (!success) {
928✔
299
      if (err != nullptr && err->get_c_error() != nullptr) {
×
300
        ten_error_set(err->get_c_error(), TEN_ERROR_CODE_GENERIC,
×
301
                      "Invalid TEN message.");
×
302
      }
×
303
      return result;
×
304
    }
×
305

306
    bool must_free = false;
928✔
307
    const char *json_str = ten_json_to_string(&c_json, nullptr, &must_free);
928✔
308
    TEN_ASSERT(json_str, "Failed to convert a JSON to a string");
928✔
309

310
    result = json_str;
928✔
311

312
    ten_json_deinit(&c_json);
928✔
313
    if (must_free) {
928✔
314
      TEN_FREE(json_str);
928✔
315
    }
928✔
316

317
    return result;
928✔
318
  }
928✔
319

320
  bool set_property(const char *path, int8_t value, error_t *err = nullptr) {
×
321
    return set_property_impl(path, ten_value_create_int8(value), err);
×
322
  }
×
323

324
  bool set_property(const char *path, int16_t value, error_t *err = nullptr) {
×
325
    return set_property_impl(path, ten_value_create_int16(value), err);
×
326
  }
×
327

328
  bool set_property(const char *path, int32_t value, error_t *err = nullptr) {
57✔
329
    return set_property_impl(path, ten_value_create_int32(value), err);
57✔
330
  }
57✔
331

332
  bool set_property(const char *path, int64_t value, error_t *err = nullptr) {
8✔
333
    return set_property_impl(path, ten_value_create_int64(value), err);
8✔
334
  }
8✔
335

336
  bool set_property(const char *path, uint8_t value, error_t *err = nullptr) {
×
337
    return set_property_impl(path, ten_value_create_uint8(value), err);
×
338
  }
×
339

340
  bool set_property(const char *path, uint16_t value, error_t *err = nullptr) {
×
341
    return set_property_impl(path, ten_value_create_uint16(value), err);
×
342
  }
×
343

344
  bool set_property(const char *path, uint32_t value, error_t *err = nullptr) {
×
345
    return set_property_impl(path, ten_value_create_uint32(value), err);
×
346
  }
×
347

348
  bool set_property(const char *path, uint64_t value, error_t *err = nullptr) {
×
349
    return set_property_impl(path, ten_value_create_uint64(value), err);
×
350
  }
×
351

352
  bool set_property(const char *path, float value, error_t *err = nullptr) {
×
353
    return set_property_impl(path, ten_value_create_float32(value), err);
×
354
  }
×
355

356
  bool set_property(const char *path, double value, error_t *err = nullptr) {
×
357
    return set_property_impl(path, ten_value_create_float64(value), err);
×
358
  }
×
359

360
  bool set_property(const char *path, bool value, error_t *err = nullptr) {
9✔
361
    return set_property_impl(path, ten_value_create_bool(value), err);
9✔
362
  }
9✔
363

364
  bool set_property(const char *path, void *value, error_t *err = nullptr) {
26,662✔
365
    if (value == nullptr) {
26,662✔
366
      if (err != nullptr && err->get_c_error() != nullptr) {
1✔
367
        ten_error_set(err->get_c_error(), TEN_ERROR_CODE_INVALID_ARGUMENT,
×
368
                      "Invalid argment.");
×
369
      }
×
370
      return false;
1✔
371
    }
1✔
372
    return set_property_impl(
26,661✔
373
        path, ten_value_create_ptr(value, nullptr, nullptr, nullptr), err);
26,661✔
374
  }
26,662✔
375

376
  bool set_property(const char *path, const char *value,
377
                    error_t *err = nullptr) {
1,722✔
378
    if (value == nullptr) {
1,722✔
379
      if (err != nullptr && err->get_c_error() != nullptr) {
1✔
380
        ten_error_set(err->get_c_error(), TEN_ERROR_CODE_INVALID_ARGUMENT,
×
381
                      "Invalid argment.");
×
382
      }
×
383
      return false;
1✔
384
    }
1✔
385
    return set_property_impl(path, ten_value_create_string(value), err);
1,721✔
386
  }
1,722✔
387

388
  bool set_property(const char *path, const std::string &value,
389
                    error_t *err = nullptr) {
22✔
390
    return set_property_impl(path, ten_value_create_string(value.c_str()), err);
22✔
391
  }
22✔
392

393
  // Pay attention to its copy semantics.
394
  bool set_property(const char *path, const ten::buf_t &value,
395
                    error_t *err = nullptr) {
3✔
396
    if (value.data() == nullptr) {
3✔
397
      if (err != nullptr && err->get_c_error() != nullptr) {
1✔
398
        ten_error_set(err->get_c_error(), TEN_ERROR_CODE_INVALID_ARGUMENT,
×
399
                      "Invalid argment.");
×
400
      }
×
401
      return false;
1✔
402
    }
1✔
403
    ten_buf_t buf;
2✔
404
    ten_buf_init_with_copying_data(&buf, value.data(), value.size());
2✔
405
    return set_property_impl(path, ten_value_create_buf_with_move(buf), err);
2✔
406
  }
3✔
407

408
  bool set_property_from_json(const char *path, const char *json,
409
                              error_t *err = nullptr) {
831✔
410
    TEN_ASSERT(c_msg, "Should not happen.");
831✔
411

412
    if (c_msg == nullptr) {
831✔
413
      if (err != nullptr && err->get_c_error() != nullptr) {
×
414
        ten_error_set(err->get_c_error(), TEN_ERROR_CODE_GENERIC,
×
415
                      "Invalid TEN message.");
×
416
      }
×
417
      return false;
×
418
    }
×
419

420
    ten_json_t *c_json = ten_json_from_string(
831✔
421
        json, err != nullptr ? err->get_c_error() : nullptr);
831✔
422
    if (c_json == nullptr) {
831✔
423
      return false;
×
424
    }
×
425

426
    ten_value_t *value = ten_value_from_json(c_json);
831✔
427
    ten_json_destroy(c_json);
831✔
428

429
    return set_property_impl(path, value, err);
831✔
430
  }
831✔
431

432
  // Internal use only.
433
  ten_shared_ptr_t *get_underlying_msg() const { return c_msg; }
61,054✔
434

435
 protected:
436
  friend class ten_env_t;
437
  friend class cmd_result_t;
438

439
  // @{
440
  // Used by the constructor of the real command class to create a base command
441
  // first.
442
  msg_t() = default;
443
  explicit msg_t(ten_shared_ptr_t *msg) : c_msg(msg) {}
66,921✔
444
  // @}
445

446
  /**
447
   * @note Note the move semantics of @a value. The @a value should not be
448
   * used after calling this function.
449
   */
450
  bool set_property_impl(const char *path, ten_value_t *value,
451
                         error_t *err = nullptr) {
29,311✔
452
    TEN_ASSERT(c_msg, "Should not happen.");
29,311✔
453

454
    if (c_msg == nullptr) {
29,311✔
455
      if (err != nullptr && err->get_c_error() != nullptr) {
×
456
        ten_error_set(err->get_c_error(), TEN_ERROR_CODE_INVALID_ARGUMENT,
×
457
                      "Invalid TEN message.");
×
458
      }
×
459
      return false;
×
460
    }
×
461

462
    bool rc = ten_msg_set_property(
29,311✔
463
        c_msg, path, value, err != nullptr ? err->get_c_error() : nullptr);
29,311✔
464

465
    if (!rc) {
29,311✔
466
      ten_value_destroy(value);
×
467
    }
×
468
    return rc;
29,311✔
469
  }
29,311✔
470

471
  void relinquish_underlying_msg() {
66,921✔
472
    if (c_msg != nullptr) {
66,921✔
473
      ten_shared_ptr_destroy(c_msg);
66,921✔
474
      c_msg = nullptr;
66,921✔
475
    }
66,921✔
476
  }
66,921✔
477

478
  ten_shared_ptr_t *c_msg = nullptr;  // NOLINT
479

480
 private:
481
  friend msg_internal_accessor_t;
482

483
  ten_value_t *peek_property_value(const char *path, error_t *err) const {
28,691✔
484
    TEN_ASSERT(c_msg, "Should not happen.");
28,691✔
485

486
    if (c_msg == nullptr) {
28,691✔
487
      if (err != nullptr && err->get_c_error() != nullptr) {
×
488
        ten_error_set(err->get_c_error(), TEN_ERROR_CODE_INVALID_ARGUMENT,
×
489
                      "Invalid TEN message.");
×
490
      }
×
491
      return nullptr;
×
492
    }
×
493

494
    return ten_msg_peek_property(c_msg, path,
28,691✔
495
                                 err != nullptr ? err->get_c_error() : nullptr);
28,691✔
496
  }
28,691✔
497

498
  // Not sure if we should have this as a public API, so for now, let's keep it
499
  // private.
500
  TEN_MSG_TYPE get_type(error_t *err = nullptr) const {
29✔
501
    if (c_msg == nullptr) {
29✔
502
      if (err != nullptr && err->get_c_error() != nullptr) {
×
503
        ten_error_set(err->get_c_error(), TEN_ERROR_CODE_INVALID_ARGUMENT,
×
504
                      "Invalid TEN message.");
×
505
      }
×
506
      return TEN_MSG_TYPE_INVALID;
×
507
    }
×
508

509
    return ten_msg_get_type(c_msg);
29✔
510
  }
29✔
511
};
512

513
// NOLINTEND(cert-dcl50-cpp)
514

515
}  // namespace ten
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc