@lynx-js/lynx-library-headers 0.0.1-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/README.md +53 -0
  2. package/include/base/include/value/lynx_api_types.h +57 -0
  3. package/include/base/include/value/lynx_value_api.h +204 -0
  4. package/include/base/include/value/lynx_value_types.h +73 -0
  5. package/include/capi/lynx_env_capi.h +47 -0
  6. package/include/capi/lynx_event_reporter_service_capi.h +67 -0
  7. package/include/capi/lynx_export.h +27 -0
  8. package/include/capi/lynx_extension_module_capi.h +148 -0
  9. package/include/capi/lynx_extension_module_types_capi.h +17 -0
  10. package/include/capi/lynx_generic_resource_fetcher_capi.h +124 -0
  11. package/include/capi/lynx_group_capi.h +42 -0
  12. package/include/capi/lynx_http_service_capi.h +113 -0
  13. package/include/capi/lynx_load_meta_capi.h +52 -0
  14. package/include/capi/lynx_log_capi.h +69 -0
  15. package/include/capi/lynx_memory_capi.h +28 -0
  16. package/include/capi/lynx_native_module_capi.h +51 -0
  17. package/include/capi/lynx_native_view_capi.h +163 -0
  18. package/include/capi/lynx_resource_request_capi.h +71 -0
  19. package/include/capi/lynx_resource_response_capi.h +92 -0
  20. package/include/capi/lynx_runtime_lifecycle_observer_capi.h +62 -0
  21. package/include/capi/lynx_security_service_capi.h +52 -0
  22. package/include/capi/lynx_service_center_capi.h +50 -0
  23. package/include/capi/lynx_template_bundle_capi.h +39 -0
  24. package/include/capi/lynx_template_data_capi.h +33 -0
  25. package/include/capi/lynx_trace_capi.h +62 -0
  26. package/include/capi/lynx_trail_service_capi.h +35 -0
  27. package/include/capi/lynx_types.h +750 -0
  28. package/include/capi/lynx_update_meta_capi.h +33 -0
  29. package/include/capi/lynx_view_builder_capi.h +113 -0
  30. package/include/capi/lynx_view_capi.h +174 -0
  31. package/include/capi/lynx_view_client_capi.h +81 -0
  32. package/include/capi/lynx_vsync_monitor_capi.h +38 -0
  33. package/include/capi/lynx_windowless_renderer_capi.h +213 -0
  34. package/include/js_native_api.h +608 -0
  35. package/include/js_native_api_types.h +202 -0
  36. package/include/lynx/base/include/value/lynx_api_types.h +57 -0
  37. package/include/lynx/base/include/value/lynx_value_api.h +204 -0
  38. package/include/lynx/base/include/value/lynx_value_types.h +73 -0
  39. package/include/lynx/extension.h +6 -0
  40. package/include/lynx/platform/embedder/public/capi/lynx_env_capi.h +47 -0
  41. package/include/lynx/platform/embedder/public/capi/lynx_event_reporter_service_capi.h +67 -0
  42. package/include/lynx/platform/embedder/public/capi/lynx_export.h +27 -0
  43. package/include/lynx/platform/embedder/public/capi/lynx_extension_module_capi.h +148 -0
  44. package/include/lynx/platform/embedder/public/capi/lynx_extension_module_types_capi.h +17 -0
  45. package/include/lynx/platform/embedder/public/capi/lynx_generic_resource_fetcher_capi.h +124 -0
  46. package/include/lynx/platform/embedder/public/capi/lynx_group_capi.h +42 -0
  47. package/include/lynx/platform/embedder/public/capi/lynx_http_service_capi.h +113 -0
  48. package/include/lynx/platform/embedder/public/capi/lynx_load_meta_capi.h +52 -0
  49. package/include/lynx/platform/embedder/public/capi/lynx_log_capi.h +69 -0
  50. package/include/lynx/platform/embedder/public/capi/lynx_memory_capi.h +28 -0
  51. package/include/lynx/platform/embedder/public/capi/lynx_native_module_capi.h +51 -0
  52. package/include/lynx/platform/embedder/public/capi/lynx_native_view_capi.h +163 -0
  53. package/include/lynx/platform/embedder/public/capi/lynx_resource_request_capi.h +71 -0
  54. package/include/lynx/platform/embedder/public/capi/lynx_resource_response_capi.h +92 -0
  55. package/include/lynx/platform/embedder/public/capi/lynx_runtime_lifecycle_observer_capi.h +62 -0
  56. package/include/lynx/platform/embedder/public/capi/lynx_security_service_capi.h +52 -0
  57. package/include/lynx/platform/embedder/public/capi/lynx_service_center_capi.h +50 -0
  58. package/include/lynx/platform/embedder/public/capi/lynx_template_bundle_capi.h +39 -0
  59. package/include/lynx/platform/embedder/public/capi/lynx_template_data_capi.h +33 -0
  60. package/include/lynx/platform/embedder/public/capi/lynx_trace_capi.h +62 -0
  61. package/include/lynx/platform/embedder/public/capi/lynx_trail_service_capi.h +35 -0
  62. package/include/lynx/platform/embedder/public/capi/lynx_types.h +750 -0
  63. package/include/lynx/platform/embedder/public/capi/lynx_update_meta_capi.h +33 -0
  64. package/include/lynx/platform/embedder/public/capi/lynx_view_builder_capi.h +113 -0
  65. package/include/lynx/platform/embedder/public/capi/lynx_view_capi.h +174 -0
  66. package/include/lynx/platform/embedder/public/capi/lynx_view_client_capi.h +81 -0
  67. package/include/lynx/platform/embedder/public/capi/lynx_vsync_monitor_capi.h +38 -0
  68. package/include/lynx/platform/embedder/public/capi/lynx_windowless_renderer_capi.h +213 -0
  69. package/include/lynx/platform/embedder/public/lynx_env.h +104 -0
  70. package/include/lynx/platform/embedder/public/lynx_event_reporter_service.h +96 -0
  71. package/include/lynx/platform/embedder/public/lynx_event_simulation_proxy.h +31 -0
  72. package/include/lynx/platform/embedder/public/lynx_extension_module.h +521 -0
  73. package/include/lynx/platform/embedder/public/lynx_generic_resource_fetcher.h +178 -0
  74. package/include/lynx/platform/embedder/public/lynx_group.h +70 -0
  75. package/include/lynx/platform/embedder/public/lynx_http_service.h +211 -0
  76. package/include/lynx/platform/embedder/public/lynx_load_meta.h +120 -0
  77. package/include/lynx/platform/embedder/public/lynx_native_module.h +9 -0
  78. package/include/lynx/platform/embedder/public/lynx_native_view.h +201 -0
  79. package/include/lynx/platform/embedder/public/lynx_resource_request.h +56 -0
  80. package/include/lynx/platform/embedder/public/lynx_resource_response.h +63 -0
  81. package/include/lynx/platform/embedder/public/lynx_runtime_lifecycle_observer.h +102 -0
  82. package/include/lynx/platform/embedder/public/lynx_security_service.h +78 -0
  83. package/include/lynx/platform/embedder/public/lynx_service_center.h +64 -0
  84. package/include/lynx/platform/embedder/public/lynx_template_bundle.h +65 -0
  85. package/include/lynx/platform/embedder/public/lynx_template_data.h +104 -0
  86. package/include/lynx/platform/embedder/public/lynx_trail_service.h +81 -0
  87. package/include/lynx/platform/embedder/public/lynx_update_meta.h +56 -0
  88. package/include/lynx/platform/embedder/public/lynx_value.h +270 -0
  89. package/include/lynx/platform/embedder/public/lynx_view.h +364 -0
  90. package/include/lynx/platform/embedder/public/lynx_view_client.h +226 -0
  91. package/include/lynx/platform/embedder/public/lynx_vsync_monitor.h +70 -0
  92. package/include/lynx/platform/embedder/public/lynx_windowless_renderer.h +302 -0
  93. package/include/lynx/registration.h +178 -0
  94. package/include/lynx_env.h +104 -0
  95. package/include/lynx_event_reporter_service.h +96 -0
  96. package/include/lynx_event_simulation_proxy.h +31 -0
  97. package/include/lynx_extension.h +10 -0
  98. package/include/lynx_extension_module.h +521 -0
  99. package/include/lynx_generic_resource_fetcher.h +178 -0
  100. package/include/lynx_group.h +70 -0
  101. package/include/lynx_http_service.h +211 -0
  102. package/include/lynx_load_meta.h +120 -0
  103. package/include/lynx_native_module.h +9 -0
  104. package/include/lynx_native_view.h +201 -0
  105. package/include/lynx_resource_request.h +56 -0
  106. package/include/lynx_resource_response.h +63 -0
  107. package/include/lynx_runtime_lifecycle_observer.h +102 -0
  108. package/include/lynx_security_service.h +78 -0
  109. package/include/lynx_service_center.h +64 -0
  110. package/include/lynx_template_bundle.h +65 -0
  111. package/include/lynx_template_data.h +104 -0
  112. package/include/lynx_trail_service.h +81 -0
  113. package/include/lynx_update_meta.h +56 -0
  114. package/include/lynx_value.h +270 -0
  115. package/include/lynx_view.h +364 -0
  116. package/include/lynx_view_client.h +226 -0
  117. package/include/lynx_vsync_monitor.h +70 -0
  118. package/include/lynx_windowless_renderer.h +302 -0
  119. package/include/napi-inl.deprecated.h +186 -0
  120. package/include/napi-inl.h +6607 -0
  121. package/include/napi.h +3208 -0
  122. package/include/node_api.h +276 -0
  123. package/include/node_api_types.h +59 -0
  124. package/include/third_party/weak-node-api/headers/js_native_api.h +608 -0
  125. package/include/third_party/weak-node-api/headers/js_native_api_types.h +202 -0
  126. package/include/third_party/weak-node-api/headers/napi-inl.deprecated.h +186 -0
  127. package/include/third_party/weak-node-api/headers/napi-inl.h +6607 -0
  128. package/include/third_party/weak-node-api/headers/napi.h +3208 -0
  129. package/include/third_party/weak-node-api/headers/node_api.h +276 -0
  130. package/include/third_party/weak-node-api/headers/node_api_types.h +59 -0
  131. package/include/third_party/weak-node-api/headers/weak_napi_defines.h +331 -0
  132. package/include/third_party/weak-node-api/headers/weak_napi_undefs.h +282 -0
  133. package/include/weak_napi_defines.h +331 -0
  134. package/include/weak_napi_undefs.h +282 -0
  135. package/package.json +29 -0
@@ -0,0 +1,63 @@
1
+ // Copyright 2025 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ #ifndef PLATFORM_EMBEDDER_PUBLIC_LYNX_RESOURCE_RESPONSE_H_
5
+ #define PLATFORM_EMBEDDER_PUBLIC_LYNX_RESOURCE_RESPONSE_H_
6
+
7
+ #include "capi/lynx_resource_response_capi.h"
8
+
9
+ namespace lynx {
10
+ namespace pub {
11
+ namespace resource {
12
+
13
+ /**
14
+ * @apidoc
15
+ * @brief `LynxResourceResponse` is a class that represents a resource response.
16
+ */
17
+ class LynxResourceResponse {
18
+ public:
19
+ explicit LynxResourceResponse(lynx_resource_response_t* response)
20
+ : response_(response) {}
21
+
22
+ ~LynxResourceResponse() { lynx_resource_response_release(response_); }
23
+
24
+ /**
25
+ * @apidoc
26
+ * @brief Set the code of the resource response.
27
+ * @param code The code of the resource response.
28
+ */
29
+ void SetCode(int code) { lynx_resource_response_set_code(response_, code); }
30
+
31
+ /**
32
+ * @apidoc
33
+ * @brief Set the error message of the resource response.
34
+ * @param msg The error message of the resource response.
35
+ */
36
+ void SetErrorMessage(const char* msg) {
37
+ lynx_resource_response_set_error_message(response_, msg);
38
+ }
39
+
40
+ /**
41
+ * @apidoc
42
+ * @brief Set the data of the resource response.
43
+ * @param content The data of the resource response.
44
+ * @param length The length of the data of the resource response.
45
+ * @param dtor The destructor of the data of the resource response.
46
+ * @param opaque The opaque data of the resource response.
47
+ */
48
+ void SetData(uint8_t* content, size_t length,
49
+ void (*dtor)(uint8_t*, size_t, void*) = nullptr,
50
+ void* opaque = nullptr) {
51
+ lynx_resource_response_set_data(response_, content, length, dtor, opaque);
52
+ }
53
+
54
+ void Complete() { lynx_resource_response_callback(response_); }
55
+
56
+ private:
57
+ lynx_resource_response_t* response_;
58
+ };
59
+ } // namespace resource
60
+ } // namespace pub
61
+ } // namespace lynx
62
+
63
+ #endif // PLATFORM_EMBEDDER_PUBLIC_LYNX_RESOURCE_RESPONSE_H_
@@ -0,0 +1,102 @@
1
+ // Copyright 2025 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ #ifndef PLATFORM_EMBEDDER_PUBLIC_LYNX_RUNTIME_LIFECYCLE_OBSERVER_H_
5
+ #define PLATFORM_EMBEDDER_PUBLIC_LYNX_RUNTIME_LIFECYCLE_OBSERVER_H_
6
+
7
+ #include <memory>
8
+
9
+ #include "capi/lynx_runtime_lifecycle_observer_capi.h"
10
+
11
+ #ifdef USE_WEAK_SUFFIX_NAPI
12
+ #include "third_party/weak-node-api/headers/weak_napi_defines.h"
13
+ #endif
14
+
15
+ namespace lynx {
16
+ namespace pub {
17
+
18
+ /**
19
+ * @apidoc
20
+ * @brief `LynxRuntimeLifecycleObserver` is the observer class for the
21
+ * lifecycle events of the Lynx runtime.
22
+ */
23
+ class LynxRuntimeLifecycleObserver
24
+ : public std::enable_shared_from_this<LynxRuntimeLifecycleObserver> {
25
+ public:
26
+ LynxRuntimeLifecycleObserver() = default;
27
+ virtual ~LynxRuntimeLifecycleObserver() {
28
+ if (observer_) {
29
+ lynx_runtime_lifecycle_observer_release(observer_);
30
+ }
31
+ }
32
+
33
+ void InitIfNeeded() {
34
+ if (observer_) {
35
+ return;
36
+ }
37
+ // Hold a weak pointer.
38
+ observer_ = lynx_runtime_lifecycle_observer_create_with_finalizer(
39
+ new std::weak_ptr<LynxRuntimeLifecycleObserver>(weak_from_this()),
40
+ [](lynx_runtime_lifecycle_observer_t*, void* user_data) {
41
+ std::weak_ptr<LynxRuntimeLifecycleObserver>* weak_ptr =
42
+ reinterpret_cast<std::weak_ptr<LynxRuntimeLifecycleObserver>*>(
43
+ user_data);
44
+ delete weak_ptr;
45
+ });
46
+
47
+ lynx_runtime_lifecycle_observer_bind_attach_callback(
48
+ observer_,
49
+ [](lynx_runtime_lifecycle_observer_t* observer, napi_env env) {
50
+ std::weak_ptr<LynxRuntimeLifecycleObserver>* weak_ptr =
51
+ reinterpret_cast<std::weak_ptr<LynxRuntimeLifecycleObserver>*>(
52
+ lynx_runtime_lifecycle_observer_get_user_data(observer));
53
+ std::shared_ptr<LynxRuntimeLifecycleObserver> shared_observer =
54
+ weak_ptr ? weak_ptr->lock() : nullptr;
55
+ if (shared_observer) {
56
+ shared_observer->OnRuntimeAttach(env);
57
+ }
58
+ });
59
+ lynx_runtime_lifecycle_observer_bind_detach_callback(
60
+ observer_, [](lynx_runtime_lifecycle_observer_t* observer) {
61
+ std::weak_ptr<LynxRuntimeLifecycleObserver>* weak_ptr =
62
+ reinterpret_cast<std::weak_ptr<LynxRuntimeLifecycleObserver>*>(
63
+ lynx_runtime_lifecycle_observer_get_user_data(observer));
64
+ std::shared_ptr<LynxRuntimeLifecycleObserver> shared_observer =
65
+ weak_ptr ? weak_ptr->lock() : nullptr;
66
+ if (shared_observer) {
67
+ shared_observer->OnRuntimeDetach();
68
+ }
69
+ });
70
+ }
71
+
72
+ /**
73
+ * @apidoc
74
+ * @brief Callback function invoked when the runtime is attached.
75
+ * Derived classes can override this method to perform custom operations
76
+ * when the runtime attaches.
77
+ * @param env The Napi environment.
78
+ */
79
+ virtual void OnRuntimeAttach(napi_env env) {}
80
+
81
+ /**
82
+ * @apidoc
83
+ * @brief Callback function invoked when the runtime is detached.
84
+ * Derived classes can override this method to perform custom cleanup
85
+ * operations when the runtime detaches.
86
+ */
87
+ virtual void OnRuntimeDetach() {}
88
+
89
+ lynx_runtime_lifecycle_observer_t* Impl() { return observer_; }
90
+
91
+ private:
92
+ lynx_runtime_lifecycle_observer_t* observer_ = nullptr;
93
+ };
94
+
95
+ } // namespace pub
96
+ } // namespace lynx
97
+
98
+ #ifdef USE_WEAK_SUFFIX_NAPI
99
+ #include "third_party/weak-node-api/headers/weak_napi_undefs.h"
100
+ #endif
101
+
102
+ #endif // PLATFORM_EMBEDDER_PUBLIC_LYNX_RUNTIME_LIFECYCLE_OBSERVER_H_
@@ -0,0 +1,78 @@
1
+ // Copyright 2025 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ #ifndef PLATFORM_EMBEDDER_PUBLIC_LYNX_SECURITY_SERVICE_H_
5
+ #define PLATFORM_EMBEDDER_PUBLIC_LYNX_SECURITY_SERVICE_H_
6
+
7
+ #include <cstdint>
8
+ #include <memory>
9
+ #include <string>
10
+ #include <unordered_map>
11
+ #include <vector>
12
+
13
+ #include "capi/lynx_security_service_capi.h"
14
+ #include "capi/lynx_service_center_capi.h"
15
+ #include "lynx_service_center.h"
16
+
17
+ namespace lynx {
18
+ namespace pub {
19
+
20
+ class LynxSecurityService
21
+ : public LynxServiceBase,
22
+ public std::enable_shared_from_this<LynxSecurityService> {
23
+ public:
24
+ LynxSecurityService() = default;
25
+ ~LynxSecurityService() = default;
26
+
27
+ void InitIfNeeded() override {
28
+ if (security_service_) {
29
+ return;
30
+ }
31
+ security_service_ = lynx_security_service_create_with_finalizer(
32
+ new std::weak_ptr<LynxSecurityService>(weak_from_this()),
33
+ [](lynx_security_service_t* security_service, void* user_data) {
34
+ std::weak_ptr<LynxSecurityService>* weak_ptr =
35
+ reinterpret_cast<std::weak_ptr<LynxSecurityService>*>(user_data);
36
+ delete weak_ptr;
37
+ });
38
+ lynx_security_service_bind(
39
+ security_service_, [](lynx_security_service_t* security_service,
40
+ uint8_t* content, size_t length, const char* url,
41
+ lynx_tasm_type_e type, const char** error_msg) {
42
+ std::weak_ptr<LynxSecurityService>* weak_ptr =
43
+ reinterpret_cast<std::weak_ptr<LynxSecurityService>*>(
44
+ lynx_security_service_get_user_data(security_service));
45
+ std::shared_ptr<LynxSecurityService> shared_security_service =
46
+ weak_ptr ? weak_ptr->lock() : nullptr;
47
+ if (shared_security_service) {
48
+ return shared_security_service->VerifyTASM(content, length, url,
49
+ type, error_msg);
50
+ }
51
+ return 0;
52
+ });
53
+ }
54
+
55
+ lynx_service_type_e GetServiceType() override { return kServiceTypeSecurity; }
56
+
57
+ void* Impl() override { return security_service_; }
58
+
59
+ /**
60
+ * @brief This function is designed to use specified verify logic to check the
61
+ * template consistency.
62
+ * @param content The TASM content to be checked.
63
+ * @param length The TASM content length.
64
+ * @param url The TASM content URL.
65
+ * @param type The TASM type.
66
+ * @param error_msg The error message.
67
+ * @return int The verification result.
68
+ */
69
+ virtual int VerifyTASM(uint8_t* content, size_t length, const char* url,
70
+ lynx_tasm_type_e type, const char** error_msg) = 0;
71
+
72
+ private:
73
+ lynx_security_service_t* security_service_ = nullptr;
74
+ };
75
+ } // namespace pub
76
+ } // namespace lynx
77
+
78
+ #endif // PLATFORM_EMBEDDER_PUBLIC_LYNX_SECURITY_SERVICE_H_
@@ -0,0 +1,64 @@
1
+ // Copyright 2025 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ #ifndef PLATFORM_EMBEDDER_PUBLIC_LYNX_SERVICE_CENTER_H_
5
+ #define PLATFORM_EMBEDDER_PUBLIC_LYNX_SERVICE_CENTER_H_
6
+
7
+ #include <memory>
8
+ #include <unordered_map>
9
+
10
+ #include "capi/lynx_service_center_capi.h"
11
+
12
+ namespace lynx {
13
+ namespace pub {
14
+
15
+ class LynxServiceBase {
16
+ public:
17
+ LynxServiceBase() = default;
18
+ virtual ~LynxServiceBase() = default;
19
+
20
+ virtual void InitIfNeeded() = 0;
21
+
22
+ virtual lynx_service_type_e GetServiceType() = 0;
23
+
24
+ virtual void* Impl() = 0;
25
+ };
26
+
27
+ /**
28
+ * @brief LynxServiceCenter is the service center of Lynx. It provides methods
29
+ * for registering services.
30
+ */
31
+ class LynxServiceCenter {
32
+ public:
33
+ static LynxServiceCenter& GetInstance() {
34
+ static LynxServiceCenter instance;
35
+ return instance;
36
+ }
37
+
38
+ LynxServiceCenter(const LynxServiceCenter&) = delete;
39
+ LynxServiceCenter& operator=(const LynxServiceCenter&) = delete;
40
+
41
+ /**
42
+ * @brief RegisterService is used to register a service.
43
+ * @param service The service to be registered.
44
+ */
45
+ void RegisterService(std::shared_ptr<LynxServiceBase> service) {
46
+ service->InitIfNeeded();
47
+ lynx_service_register_service(service_center_, service->GetServiceType(),
48
+ service->Impl());
49
+ services_[service->GetServiceType()] = service;
50
+ }
51
+
52
+ private:
53
+ LynxServiceCenter() { service_center_ = lynx_service_get_center_instance(); }
54
+ ~LynxServiceCenter() = default;
55
+
56
+ lynx_service_center_t* service_center_ = nullptr;
57
+ std::unordered_map<lynx_service_type_e, std::shared_ptr<LynxServiceBase> >
58
+ services_;
59
+ };
60
+
61
+ } // namespace pub
62
+ } // namespace lynx
63
+
64
+ #endif // PLATFORM_EMBEDDER_PUBLIC_LYNX_SERVICE_CENTER_H_
@@ -0,0 +1,65 @@
1
+ // Copyright 2025 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ #ifndef PLATFORM_EMBEDDER_PUBLIC_LYNX_TEMPLATE_BUNDLE_H_
5
+ #define PLATFORM_EMBEDDER_PUBLIC_LYNX_TEMPLATE_BUNDLE_H_
6
+
7
+ #include <string>
8
+
9
+ #include "capi/lynx_template_bundle_capi.h"
10
+
11
+ namespace lynx {
12
+ namespace pub {
13
+
14
+ /**
15
+ * @apidoc
16
+ * @brief `TemplateBundle` is the output product of the PreDecode capability
17
+ * provided by the Lynx SDK. Client developers can parse the Lynx App Bundle
18
+ * product in advance to obtain the `TemplateBundle` object and consume the App
19
+ * Bundle product.
20
+ */
21
+ class LynxTemplateBundle {
22
+ public:
23
+ LynxTemplateBundle(uint8_t* content, size_t size,
24
+ void (*dtor)(uint8_t*, size_t, void*) = nullptr,
25
+ void* opaque = nullptr)
26
+ : template_bundle_(
27
+ lynx_template_bundle_create(content, size, dtor, opaque)) {}
28
+
29
+ ~LynxTemplateBundle() { lynx_template_bundle_release(template_bundle_); }
30
+
31
+ /**
32
+ * @apidoc
33
+ * @brief Determines whether the current `TemplateBundle` object is valid.
34
+ * @return `true` if the current `TemplateBundle` object is valid, else
35
+ * `false`.
36
+ */
37
+ bool IsValid() const {
38
+ return lynx_template_bundle_is_valid(template_bundle_);
39
+ }
40
+
41
+ /**
42
+ * @apidoc
43
+ * @brief When `TemplateBundle` is an invalid object, use this method to
44
+ * obtain the exception information that occurred during template parsing
45
+ * @return The exception information.
46
+ */
47
+ std::string GetErrorMessage() {
48
+ const char* error_message =
49
+ lynx_template_bundle_get_error_message(template_bundle_);
50
+ return error_message ? std::string(error_message) : "";
51
+ }
52
+
53
+ lynx_template_bundle_t* Impl() { return template_bundle_; }
54
+
55
+ LynxTemplateBundle(const LynxTemplateBundle&) = delete;
56
+ LynxTemplateBundle& operator=(const LynxTemplateBundle&) = delete;
57
+
58
+ private:
59
+ lynx_template_bundle_t* template_bundle_;
60
+ };
61
+
62
+ } // namespace pub
63
+ } // namespace lynx
64
+
65
+ #endif // PLATFORM_EMBEDDER_PUBLIC_LYNX_TEMPLATE_BUNDLE_H_
@@ -0,0 +1,104 @@
1
+ // Copyright 2025 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ #ifndef PLATFORM_EMBEDDER_PUBLIC_LYNX_TEMPLATE_DATA_H_
5
+ #define PLATFORM_EMBEDDER_PUBLIC_LYNX_TEMPLATE_DATA_H_
6
+
7
+ #include <string>
8
+
9
+ #include "capi/lynx_template_data_capi.h"
10
+
11
+ namespace lynx {
12
+ namespace pub {
13
+
14
+ /**
15
+ * @apidoc
16
+ * @brief TemplateData is a data structure provided by Lynx. It is used to store
17
+ * the data types accepted by Lynx at runtime and can be constructed using
18
+ * either a string or a map type.
19
+ */
20
+ class LynxTemplateData {
21
+ public:
22
+ /**
23
+ * @apidoc
24
+ * @brief Constructs a new LynxTemplateData object.
25
+ * @param json The JSON string used to create the template data.
26
+ */
27
+ explicit LynxTemplateData(const std::string& json)
28
+ : template_data_(lynx_template_data_create_from_json(json.c_str())) {}
29
+ ~LynxTemplateData() { lynx_template_data_release(template_data_); }
30
+
31
+ /**
32
+ * @apidoc
33
+ * @brief Update the current TemplateData with the JSON string.
34
+ * @param json The JSON string used to update the template data.
35
+ */
36
+ void UpdateWithJson(const std::string& json) {
37
+ if (read_only_) {
38
+ // If the data is read only, we can't update it.
39
+ return;
40
+ }
41
+ if (template_data_) {
42
+ lynx_template_data_release(template_data_);
43
+ }
44
+ template_data_ = lynx_template_data_create_from_json(json.c_str());
45
+ if (!processor_name_.empty()) {
46
+ lynx_template_data_mark_state(template_data_, processor_name_.c_str());
47
+ }
48
+ }
49
+
50
+ /**
51
+ * @apidoc
52
+ * @brief Mark the current TemplateData with the associated dataProcessor
53
+ * name.
54
+ * @param name Marked name.
55
+ */
56
+ void MarkState(const std::string& name) {
57
+ processor_name_ = name;
58
+ lynx_template_data_mark_state(template_data_, name.c_str());
59
+ }
60
+
61
+ /**
62
+ * @apidoc
63
+ * @brief Mark the current TemplateData as read-only. TemplateData will be
64
+ * sync to Native. For Thread-Safety, we will clone the value in Native Side.
65
+ * In some case, this may result in performance-loss, If your data won't
66
+ * change any more, Please call this method to mark value Read-Only, so we'll
67
+ * no longer clone the value any more to improve performance.
68
+ */
69
+ void MarkReadOnly() {
70
+ read_only_ = true;
71
+ lynx_template_data_set_read_only(template_data_, read_only_);
72
+ }
73
+
74
+ /**
75
+ * @apidoc
76
+ * @brief Check if the current TemplateData is read-only.
77
+ * @return True if the current TemplateData is read-only, false otherwise.
78
+ */
79
+ bool IsReadOnly() const { return read_only_; }
80
+
81
+ /**
82
+ * @apidoc
83
+ * @brief Get the name of the dataProcessor associated with the current
84
+ * TemplateData.
85
+ * @return The name of the dataProcessor associated with the current
86
+ * TemplateData.
87
+ */
88
+ std::string GetProcessorName() const { return processor_name_; }
89
+
90
+ lynx_template_data_t* Impl() { return template_data_; }
91
+
92
+ LynxTemplateData(const LynxTemplateData&) = delete;
93
+ LynxTemplateData& operator=(const LynxTemplateData&) = delete;
94
+
95
+ private:
96
+ lynx_template_data_t* template_data_;
97
+ std::string processor_name_;
98
+ bool read_only_ = false;
99
+ };
100
+
101
+ } // namespace pub
102
+ } // namespace lynx
103
+
104
+ #endif // PLATFORM_EMBEDDER_PUBLIC_LYNX_TEMPLATE_DATA_H_
@@ -0,0 +1,81 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ #ifndef PLATFORM_EMBEDDER_PUBLIC_LYNX_TRAIL_SERVICE_H_
5
+ #define PLATFORM_EMBEDDER_PUBLIC_LYNX_TRAIL_SERVICE_H_
6
+
7
+ #include <memory>
8
+ #include <optional>
9
+ #include <string>
10
+
11
+ #include "capi/lynx_service_center_capi.h"
12
+ #include "capi/lynx_trail_service_capi.h"
13
+ #include "lynx_service_center.h"
14
+
15
+ namespace lynx {
16
+ namespace pub {
17
+
18
+ class LynxTrailService : public LynxServiceBase,
19
+ public std::enable_shared_from_this<LynxTrailService> {
20
+ public:
21
+ LynxTrailService() = default;
22
+ ~LynxTrailService() override {
23
+ if (trail_service_) {
24
+ lynx_trail_service_release(trail_service_);
25
+ trail_service_ = nullptr;
26
+ }
27
+ }
28
+
29
+ void InitIfNeeded() override {
30
+ if (trail_service_) {
31
+ return;
32
+ }
33
+ // LynxTrailService must be owned by std::shared_ptr before InitIfNeeded()
34
+ // is called; otherwise weak_from_this() is empty and callbacks return null.
35
+ std::weak_ptr<LynxTrailService> self = weak_from_this();
36
+ trail_service_ = lynx_trail_service_create_with_finalizer(
37
+ new std::weak_ptr<LynxTrailService>(self),
38
+ [](lynx_trail_service_t* trail_service, void* user_data) {
39
+ std::weak_ptr<LynxTrailService>* weak_ptr =
40
+ reinterpret_cast<std::weak_ptr<LynxTrailService>*>(user_data);
41
+ delete weak_ptr;
42
+ });
43
+ lynx_trail_service_bind(
44
+ trail_service_,
45
+ [](lynx_trail_service_t* trail_service, const char* key) {
46
+ std::weak_ptr<LynxTrailService>* weak_ptr =
47
+ reinterpret_cast<std::weak_ptr<LynxTrailService>*>(
48
+ lynx_trail_service_get_user_data(trail_service));
49
+ std::shared_ptr<LynxTrailService> shared_trail_service =
50
+ weak_ptr ? weak_ptr->lock() : nullptr;
51
+ if (!shared_trail_service) {
52
+ return static_cast<const char*>(nullptr);
53
+ }
54
+ std::optional<std::string> value =
55
+ shared_trail_service->GetStringValueForTrailKey(key ? key : "");
56
+ if (!value) {
57
+ return static_cast<const char*>(nullptr);
58
+ }
59
+ // The returned pointer is valid until the next callback on the same
60
+ // thread. Callers must copy it immediately.
61
+ static thread_local std::string result;
62
+ result = *value;
63
+ return result.c_str();
64
+ });
65
+ }
66
+
67
+ lynx_service_type_e GetServiceType() override { return kServiceTypeTrail; }
68
+
69
+ void* Impl() override { return trail_service_; }
70
+
71
+ virtual std::optional<std::string> GetStringValueForTrailKey(
72
+ const std::string& key) = 0;
73
+
74
+ private:
75
+ lynx_trail_service_t* trail_service_ = nullptr;
76
+ };
77
+
78
+ } // namespace pub
79
+ } // namespace lynx
80
+
81
+ #endif // PLATFORM_EMBEDDER_PUBLIC_LYNX_TRAIL_SERVICE_H_
@@ -0,0 +1,56 @@
1
+ // Copyright 2025 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ #ifndef PLATFORM_EMBEDDER_PUBLIC_LYNX_UPDATE_META_H_
5
+ #define PLATFORM_EMBEDDER_PUBLIC_LYNX_UPDATE_META_H_
6
+
7
+ #include <memory>
8
+
9
+ #include "capi/lynx_update_meta_capi.h"
10
+ #include "lynx_template_data.h"
11
+
12
+ namespace lynx {
13
+ namespace pub {
14
+
15
+ /**
16
+ * @apidoc
17
+ * @brief LynxUpdateMeta is the update meta of Lynx. It provides methods for
18
+ * setting update data and global props.
19
+ */
20
+ class LynxUpdateMeta {
21
+ public:
22
+ LynxUpdateMeta() : update_meta_(lynx_update_meta_create()) {}
23
+
24
+ ~LynxUpdateMeta() { lynx_update_meta_release(update_meta_); }
25
+
26
+ /**
27
+ * @apidoc
28
+ * @brief Set the update data of the current LynxUpdateMeta.
29
+ * @param data The update data to be set.
30
+ */
31
+ void SetUpdateData(std::shared_ptr<LynxTemplateData> data) {
32
+ lynx_update_meta_set_update_data(update_meta_, data->Impl());
33
+ }
34
+
35
+ /**
36
+ * @apidoc
37
+ * @brief Set the global props of the current LynxUpdateMeta.
38
+ * @param global_props The global props to be set.
39
+ */
40
+ void SetGlobalProps(std::shared_ptr<LynxTemplateData> global_props) {
41
+ lynx_update_meta_set_global_props(update_meta_, global_props->Impl());
42
+ }
43
+
44
+ lynx_update_meta_t* Impl() { return update_meta_; }
45
+
46
+ LynxUpdateMeta(const LynxUpdateMeta&) = delete;
47
+ LynxUpdateMeta& operator=(const LynxUpdateMeta&) = delete;
48
+
49
+ private:
50
+ lynx_update_meta_t* update_meta_;
51
+ };
52
+
53
+ } // namespace pub
54
+ } // namespace lynx
55
+
56
+ #endif // PLATFORM_EMBEDDER_PUBLIC_LYNX_UPDATE_META_H_