Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The call restrictions of ten_env APIs need to be clarified #139

Open
sunxilin opened this issue Oct 14, 2024 · 2 comments
Open

The call restrictions of ten_env APIs need to be clarified #139

sunxilin opened this issue Oct 14, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@sunxilin
Copy link
Collaborator

The ten_env APIs are not safe to be called in any context or in any thread, so we need to clarify these call restrictions and the exceptions or error messages under incorrect calls.

@halajohn
Copy link
Member

halajohn commented Dec 1, 2024

Some APIs in ten_env already include checks for verifying the correct timing of their invocation. For example, when calling on_configure_done, the TEN runtime ensures that the extension is in the proper state. Using a similar mechanism, we could implement timing checks for all other ten_env APIs.

bool ten_extension_on_configure_done(ten_env_t *self) {
  TEN_ASSERT(self, "Invalid argument.");
  TEN_ASSERT(ten_env_check_integrity(self, true), "Invalid use of ten_env %p.",
             self);

  ten_extension_t *extension = ten_env_get_attached_extension(self);
  TEN_ASSERT(extension, "Invalid argument.");
  TEN_ASSERT(ten_extension_check_integrity(extension, true),
             "Invalid use of extension %p.", extension);

  TEN_LOGD("[%s] on_configure() done.",
           ten_extension_get_name(extension, true));

  if (extension->state != TEN_EXTENSION_STATE_INIT) {    // <== timing check
    TEN_LOGI("[%s] Failed to on_configure_done() because of incorrect timing.",
             ten_extension_get_name(extension, true));
    return false;
  }
}

By leveraging this approach, it is possible to extend similar checks to other APIs in ten_env. This would help enforce proper timing across all API calls, enhancing the robustness of the framework.

1 similar comment
@halajohn
Copy link
Member

halajohn commented Dec 1, 2024

Some APIs in ten_env already include checks for verifying the correct timing of their invocation. For example, when calling on_configure_done, the TEN runtime ensures that the extension is in the proper state. Using a similar mechanism, we could implement timing checks for all other ten_env APIs.

bool ten_extension_on_configure_done(ten_env_t *self) {
  TEN_ASSERT(self, "Invalid argument.");
  TEN_ASSERT(ten_env_check_integrity(self, true), "Invalid use of ten_env %p.",
             self);

  ten_extension_t *extension = ten_env_get_attached_extension(self);
  TEN_ASSERT(extension, "Invalid argument.");
  TEN_ASSERT(ten_extension_check_integrity(extension, true),
             "Invalid use of extension %p.", extension);

  TEN_LOGD("[%s] on_configure() done.",
           ten_extension_get_name(extension, true));

  if (extension->state != TEN_EXTENSION_STATE_INIT) {    // <== timing check
    TEN_LOGI("[%s] Failed to on_configure_done() because of incorrect timing.",
             ten_extension_get_name(extension, true));
    return false;
  }
}

By leveraging this approach, it is possible to extend similar checks to other APIs in ten_env. This would help enforce proper timing across all API calls, enhancing the robustness of the framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

2 participants