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

TEN-framework / ten-framework / 22890412256

10 Mar 2026 06:39AM UTC coverage: 58.714%. First build
22890412256

Pull #2097

github

web-flow
Merge d59ff8d41 into 65bd8cf55
Pull Request #2097: feat: support sync_stop_before_deinit in graph

165 of 236 new or added lines in 15 files covered. (69.92%)

53334 of 90837 relevant lines covered (58.71%)

877495.58 hits per line

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

35.59
/core/src/ten_runtime/binding/python/native/msg/cmd/start_graph_cmd.c
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
#include "include_internal/ten_runtime/binding/python/msg/cmd/start_graph_cmd.h"
8

9
#include <stdbool.h>
10

11
#include "include_internal/ten_runtime/binding/python/common/error.h"
12
#include "include_internal/ten_runtime/binding/python/msg/cmd/cmd.h"
13
#include "ten_runtime/msg/cmd/start_graph/cmd.h"
14
#include "ten_utils/macro/mark.h"
15

16
typedef ten_py_cmd_t ten_py_cmd_start_graph_t;
17

18
static PyTypeObject *ten_py_cmd_start_graph_type = NULL;
19

20
static ten_py_cmd_start_graph_t *ten_py_cmd_start_graph_create_internal(
21
    PyTypeObject *py_type) {
×
22
  if (!py_type) {
×
23
    py_type = ten_py_cmd_start_graph_type;
×
24
  }
×
25

26
  ten_py_cmd_start_graph_t *py_cmd =
×
27
      (ten_py_cmd_start_graph_t *)py_type->tp_alloc(py_type, 0);
×
28
  TEN_ASSERT(py_cmd, "Failed to allocate memory.");
×
29

30
  ten_signature_set(&py_cmd->msg.signature, TEN_PY_MSG_SIGNATURE);
×
31
  py_cmd->msg.c_msg = NULL;
×
32

33
  return py_cmd;
×
34
}
×
35

36
static void ten_py_cmd_start_graph_destroy(PyObject *self) {
×
37
  ten_py_cmd_start_graph_t *py_cmd = (ten_py_cmd_start_graph_t *)self;
×
38
  TEN_ASSERT(py_cmd, "Invalid argument.");
×
39
  TEN_ASSERT(ten_py_msg_check_integrity((ten_py_msg_t *)py_cmd),
×
40
             "Invalid argument.");
×
41

42
  ten_py_msg_destroy_c_msg(&py_cmd->msg);
×
43
  Py_TYPE(self)->tp_free(self);
×
44
}
×
45

46
static PyObject *ten_py_cmd_start_graph_create(PyTypeObject *type,
47
                                               TEN_UNUSED PyObject *args,
48
                                               TEN_UNUSED PyObject *kw) {
×
49
  ten_py_cmd_start_graph_t *py_cmd =
×
50
      ten_py_cmd_start_graph_create_internal(type);
×
51
  py_cmd->msg.c_msg = ten_cmd_start_graph_create();
×
52
  return (PyObject *)py_cmd;
×
53
}
×
54

55
static PyObject *ten_py_cmd_start_graph_set_predefined_graph_name(
56
    PyObject *self, PyObject *args) {
×
57
  ten_py_cmd_start_graph_t *py_cmd = (ten_py_cmd_start_graph_t *)self;
×
58
  TEN_ASSERT(py_cmd, "Invalid argument.");
×
59
  TEN_ASSERT(ten_py_msg_check_integrity((ten_py_msg_t *)py_cmd),
×
60
             "Invalid argument.");
×
61

62
  const char *predefined_graph_name = NULL;
×
63
  if (!PyArg_ParseTuple(args, "s", &predefined_graph_name)) {
×
64
    return ten_py_raise_py_value_error_exception("Failed to parse arguments.");
×
65
  }
×
66

67
  bool result = ten_cmd_start_graph_set_predefined_graph_name(
×
68
      py_cmd->msg.c_msg, predefined_graph_name, NULL);
×
69

70
  return PyBool_FromLong(result);
×
71
}
×
72

73
static PyObject *ten_py_cmd_start_graph_set_sync_stop_before_deinit(
NEW
74
    PyObject *self, PyObject *args) {
×
NEW
75
  ten_py_cmd_start_graph_t *py_cmd = (ten_py_cmd_start_graph_t *)self;
×
NEW
76
  TEN_ASSERT(py_cmd, "Invalid argument.");
×
NEW
77
  TEN_ASSERT(ten_py_msg_check_integrity((ten_py_msg_t *)py_cmd),
×
NEW
78
             "Invalid argument.");
×
79

NEW
80
  int sync_stop_before_deinit = 0;
×
NEW
81
  if (!PyArg_ParseTuple(args, "p", &sync_stop_before_deinit)) {
×
NEW
82
    return ten_py_raise_py_value_error_exception("Failed to parse arguments.");
×
NEW
83
  }
×
84

NEW
85
  bool result = ten_cmd_start_graph_set_sync_stop_before_deinit(
×
NEW
86
      py_cmd->msg.c_msg, (bool)sync_stop_before_deinit, NULL);
×
87

NEW
88
  return PyBool_FromLong(result);
×
NEW
89
}
×
90

91
static PyObject *ten_py_cmd_start_graph_set_graph_from_json(PyObject *self,
92
                                                            PyObject *args) {
×
93
  ten_py_cmd_start_graph_t *py_cmd = (ten_py_cmd_start_graph_t *)self;
×
94
  TEN_ASSERT(py_cmd, "Invalid argument.");
×
95
  TEN_ASSERT(ten_py_msg_check_integrity((ten_py_msg_t *)py_cmd),
×
96
             "Invalid argument.");
×
97

98
  const char *json_str = NULL;
×
99
  if (!PyArg_ParseTuple(args, "s", &json_str)) {
×
100
    return ten_py_raise_py_value_error_exception("Failed to parse arguments.");
×
101
  }
×
102

103
  bool result = ten_cmd_start_graph_set_graph_from_json_str(py_cmd->msg.c_msg,
×
104
                                                            json_str, NULL);
×
105

106
  return PyBool_FromLong(result);
×
107
}
×
108

109
PyTypeObject *ten_py_cmd_start_graph_py_type(void) {
5✔
110
  static PyMethodDef py_methods[] = {
5✔
111
      {"set_predefined_graph_name",
5✔
112
       ten_py_cmd_start_graph_set_predefined_graph_name, METH_VARARGS, NULL},
5✔
113
      {"set_graph_from_json", ten_py_cmd_start_graph_set_graph_from_json,
5✔
114
       METH_VARARGS, NULL},
5✔
115
      {"set_sync_stop_before_deinit",
5✔
116
       ten_py_cmd_start_graph_set_sync_stop_before_deinit, METH_VARARGS, NULL},
5✔
117
      {NULL, NULL, 0, NULL},
5✔
118
  };
5✔
119

120
  static PyTypeObject py_type = {
5✔
121
      PyVarObject_HEAD_INIT(NULL, 0).tp_name =
5✔
122
          "libten_runtime_python._StartGraphCmd",
5✔
123
      .tp_doc = PyDoc_STR("_StartGraphCmd"),
5✔
124
      .tp_basicsize = sizeof(ten_py_cmd_start_graph_t),
5✔
125
      .tp_itemsize = 0,
5✔
126
      .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
5✔
127
      .tp_base = NULL,  // Will be set at runtime
5✔
128
      .tp_new = ten_py_cmd_start_graph_create,
5✔
129
      .tp_init = NULL,
5✔
130
      .tp_dealloc = ten_py_cmd_start_graph_destroy,
5✔
131
      .tp_getset = NULL,
5✔
132
      .tp_methods = py_methods,
5✔
133
  };
5✔
134

135
  return &py_type;
5✔
136
}
5✔
137

138
bool ten_py_cmd_start_graph_init_for_module(PyObject *module) {
5✔
139
  PyTypeObject *py_type = ten_py_cmd_start_graph_py_type();
5✔
140

141
  // Set the base type at runtime
142
  py_type->tp_base = ten_py_cmd_py_type();
5✔
143

144
  if (PyType_Ready(py_type) < 0) {
5✔
145
    ten_py_raise_py_system_error_exception(
×
146
        "Python CmdStartGraph class is not ready.");
×
147

148
    TEN_ASSERT(0, "Should not happen.");
×
149
    return false;
×
150
  }
×
151

152
  if (PyModule_AddObjectRef(module, "_StartGraphCmd", (PyObject *)py_type) <
5✔
153
      0) {
5✔
154
    ten_py_raise_py_import_error_exception(
×
155
        "Failed to add Python type to module.");
×
156

157
    TEN_ASSERT(0, "Should not happen.");
×
158
    return false;
×
159
  }
×
160
  return true;
5✔
161
}
5✔
162

163
PyObject *ten_py_cmd_start_graph_register_type(TEN_UNUSED PyObject *self,
164
                                               PyObject *args) {
5✔
165
  PyObject *cls = NULL;
5✔
166
  if (!PyArg_ParseTuple(args, "O!", &PyType_Type, &cls)) {
5✔
167
    return NULL;
×
168
  }
×
169

170
  Py_XINCREF(cls);
5✔
171
  Py_XDECREF(ten_py_cmd_start_graph_type);
5✔
172

173
  ten_py_cmd_start_graph_type = (PyTypeObject *)cls;
5✔
174

175
  Py_RETURN_NONE;
5✔
176
}
5✔
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