GObj#
Gobjs are modular components that form the building blocks of Yuneta applications. The creation and configuration of gobjs are flexible, allowing developers to instantiate individual gobjs or entire hierarchies using structured APIs and configurations.
GObj Creation APIs#
1. Creating Individual Gobjs#
The primary APIs for creating gobjs include:
API |
Description |
---|---|
|
Creates a GObj with the specified name, GClass, and attributes. |
|
Similar to |
|
Creates the root GObj of a Yuno, typically used to initialize the application. |
|
Creates a service GObj that exposes commands and events for interaction with other components. |
|
Creates a default service GObj with |
|
Creates a volatile GObj, which is not persisted. |
|
Creates a pure child GObj that directly sends events to its parent. |
2. Creating GObj Trees#
Entire hierarchies of gobjs can be created using structured configurations:
gobj_create_tree0
: Creates a GObj tree based on a JSON structure (jn_tree
).gobj_create_tree
: Parses a tree configuration and callsgobj_create_tree0
to instantiate the hierarchy.
GObj Flags (gobj_flag_t
)#
Flags control the behavior and characteristics of gobjs during their creation. They can be combined to define multiple properties.
Flag |
Value |
Description |
---|---|---|
|
|
Marks the GObj as a Yuno root. |
|
|
Sets the GObj as the default service for the Yuno, with |
|
|
Indicates that the GObj is a service, exposing public commands and events. |
|
|
Marks the GObj as volatile, meaning it is not persistent. |
|
|
Sets the GObj as a pure child, sending events directly to its parent. |
|
|
Automatically starts the GObj after creation. |
|
|
Automatically plays the GObj after creation. |
JSON Tree Configuration for GObj Creation#
GObj hierarchies can be defined using JSON structures, making it easy to specify attributes, children, and behavioral flags. A typical JSON tree structure includes:
Key |
Description |
---|---|
|
The name of the GClass for the GObj. |
|
The name of the GObj. |
|
Boolean indicating if the GObj is the default service. |
|
Boolean indicating if the GObj should act as a service. |
|
Boolean indicating if the GObj should start automatically. |
|
Boolean indicating if the GObj should play automatically. |
|
Boolean indicating if the GObj should be disabled. |
|
Boolean indicating if the GObj is a pure child. |
|
A dictionary of attributes to configure the GObj. |
|
A list of child GObjs with their respective configurations. |
Hierarchy Rules:#
If a
subscriber
is not specified, it defaults to the parent GObj.If there is only one child in
zchilds
, it is automatically set as the “bottom” GObj.
Rules for Proper GObj Usage#
Pure Child: Automatically sends events to its parent using
gobj_send_event
.Service: Publishes events externally using
gobj_publish_event
.Default Service: Starts automatically but requires explicit play through the Yuno’s play method.
Benefits of GObj Creation APIs#
Flexibility: Allows creation of individual gobjs or entire hierarchies.
Modularity: Enables clear separation of components through services and child-parent relationships.
Dynamic Behavior: Flags and attributes provide fine-grained control over the GObj’s functionality.
Scalability: JSON tree configurations simplify the management of large, complex GObj hierarchies.