TEMU  4.4
The Terma Emulator
Component.h
Go to the documentation of this file.
1 //===-- temu-c/Component.h - TEMU Component Support ------------*- C++ -*-===//
2 //
3 // TEMU: The Terma Emulator
4 // (c) Terma 2016
5 // Authors: Mattias Holm <maho (at) terma.com>
6 //
7 //===----------------------------------------------------------------------===//
8 
9 //------------------------------------------------------------------------------
10 // WARNING!!! WARNING!!! EXPERIMENTAL API WARNING!!! WARNING!!! WARNING!!!
11 //
12 // BE WARNED THAT THIS API IS EXPERIMENTAL, UNSTABLE AND NOT WELL TESTED.
13 // IN PARTICULAR, THE API MAY CRASH ON OCCASIONS.
14 //------------------------------------------------------------------------------
15 #ifndef TEMU_SUPPORT_COMPONENT_H
16 #define TEMU_SUPPORT_COMPONENT_H
17 
18 #include "temu-c/Support/Attributes.h"
19 #include "temu-c/Support/Objsys.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #ifndef TEMU_COMPONENT_DEFINED
26 #define TEMU_COMPONENT_DEFINED
27 typedef struct temu_Component temu_Component;
28 #endif // !TEMU_COMPONENT_DEFINED
29 
30 
31 /*!
32  * Register a new component class in
33  *
34  * \param CompClass Name of the component to be registered
35  * \param Create The constructor function that allocates the component
36  * \param Dispose The destructor function
37  * \result Pointer to the new class
38  */
39 TEMU_API temu_Class*
40 temu_registerComponent(const char *CompClass,
41  temu_ObjectCreateFunc Create,
42  temu_ObjectDisposeFunc Dispose);
43 
44 /*!
45  * Allocate a component object.
46  *
47  * The component create shall be called in the component
48  * constructor/create function (the create function passed to the
49  * registerComponent function). It will allocate an opaque component
50  * object with the relevant name.
51  *
52  * The returned component is what the component constructor should
53  * return.
54  *
55  * \param Name Name of component
56  * \result Component pointer
57  */
58 TEMU_API temu_Component_* temu_componentCreate(const char *Name);
59 
60 /*!
61  * Deallocate a component object
62  *
63  * The component dispose shall be called by the component
64  * destructor/dispose function registered in the registerComponent
65  * call.
66  *
67  * Note that a component is seen as owning all the objects created
68  * with createComponentObject, and subsequently, all objects created
69  * will be recursively deleted when deleting the component.
70  *
71  * \param Comp Component to dispose.
72  */
73 TEMU_API void temu_componentDispose(void *Comp); // Default destructor
74 
75 /*!
76  * Add delegate interface to component
77  *
78  * Delegate interfaces are interfaces in objects internal in the
79  * component. It is possible to use the connect function to attach
80  * directly to a component delegated interface (although, in practice
81  * the connection is done to the internal object's interface).
82  *
83  * Note that delegate interface do not support interface arrays, and
84  * can only expose a single interface instance at present.
85  *
86  * \param Comp the component to add the delegate interface to.
87  * \param Name name of the delegate interface
88  * \param Iface Interface reference which the delegated interface is
89  * resolved to
90  */
91 TEMU_API void temu_componentAddDelegateIface(temu_Component_ *Comp,
92  const char *Name,
93  temu_IfaceRef Iface);
94 
95 /*!
96  * Add delegate property to component
97  *
98  * Delegate property are properties in objects internal in the
99  * component. It is possible to use the connect function to connect
100  * from a delegated property directly using the component instead of
101  * the underlying object.
102  *
103  * \param Comp the component to add the delegate interface to.
104  * \param Name name of the delegate property
105  * \param Obj Object to which the property resolves to.
106  * \param PropName Name of property in Obj
107  */
108 
109 TEMU_API void temu_componentAddDelegateProp(temu_Component_ *Comp,
110  const char *Name, temu_Object_ *Obj,
111  const char *PropName);
112 
113 /*!
114  * Query the component for a delegated interface
115  *
116  * Normally this function is not needed for the end user, however
117  * some usecases can be seen for exposing this. It returns the
118  * IfaceRef that has been added as a delegate interface. The main use
119  * is to redelegate delegated interfaces in a component of components.
120  *
121  * \param Comp The component to query the IfaceRef from
122  * \param Name Name of the interface reference.
123  * \result Interface reference associated with Name, if none is found,
124  * iref type will be teTY_Invalid.
125  */
126 TEMU_API temu_IfaceRef temu_componentGetDelegateIface(temu_Component *Comp,
127  const char *Name);
128 
129 /*!
130  * Query the compontent for a delegated property
131  *
132  * Normally this should not be called by the user. But is useful in
133  * case the user constructs components of components in which case a
134  * component can redelegate delegated properties.
135  *
136  * \param Comp The componten to query
137  * \param Name Name of delegated property
138  * \result Object name pair with the target object and property name.
139  */
140 TEMU_API temu_PropName
141 temu_componentGetDelegateProp(temu_Component *Comp,
142  const char *Name);
143 
144 /*!
145  * Create an object in a component.
146  *
147  * This function works as the temu_createObject, except that the
148  * object created is inserted in the component.
149  *
150  * The function is indended to be used in the component constructor.
151  *
152  * Object names are uniqued using the objnamefmt paramters and
153  * following varargs. Plus, that the name of the component itself is
154  * prefixed as '[compname]-'.
155  *
156  * \param Comp The component under which the object is to be created.
157  * \param Class class of the created object
158  * \param Args NULL terminated array of create arguments for the
159  * constructor.
160  * \param ObjNameFmt Name of created object, but it allows for printf
161  * style string names, simplifying the creation of
162  * multiple objects of the same type.
163  * \result Pointer to created object.
164  */
165 TEMU_API temu_Object_* temu_createComponentObject(temu_Component_ *Comp, const char *Class,
166  const temu_CreateArg *Args,
167  const char *ObjNameFmt, ...);
168 
169 
170 /*!
171  * Get named object in component
172  * \param Comp Component pointer
173  * \param Name String without the component prefix (i.e. local name)
174  * \result NULL if the object is not a member in the component
175  */
176 TEMU_API temu_Object_ * temu_componentGetObject(temu_Component_ *Comp, const char *Name);
177 
178 
179 
180 // Call function on every component
181 /*!
182  * Iterate over all components and call a function on them
183  *
184  * \param Func The function to be called on each component, with the signature *Func)(temu_Component*,void*)
185  * \param Arg The second argument to be passed to the function, for passing context
186  */
187 TEMU_API void temu_foreachComponent(void (*Func)(temu_Component*,void*), void *Arg);
188 
189 /*!
190  * Iterate over all root components and call a function on them
191  *
192  * \param Func The function to be called on each component, with the signature *Func)(temu_Component*,void*)
193  * \param Arg The second argument to be passed to the function, for passing context
194  */
195 TEMU_API void temu_foreachRootComponent(void (*Func)(temu_Component*,void*), void *Arg);
196 
197 #ifdef __cplusplus
198 }
199 #endif
200 
201 #endif /* !TEMU_SUPPORT_COMPONENT_H */
temu_foreachComponent
TEMU_API void temu_foreachComponent(void(*Func)(temu_Component *, void *), void *Arg)
temu_Component
struct temu_Component temu_Component
Definition: Objsys.h:57
temu_componentDispose
TEMU_API void temu_componentDispose(void *Comp)
temu_componentAddDelegateProp
TEMU_API void temu_componentAddDelegateProp(temu_Component_ *Comp, const char *Name, temu_Object_ *Obj, const char *PropName)
temu_componentAddDelegateIface
TEMU_API void temu_componentAddDelegateIface(temu_Component_ *Comp, const char *Name, temu_IfaceRef Iface)
temu_foreachRootComponent
TEMU_API void temu_foreachRootComponent(void(*Func)(temu_Component *, void *), void *Arg)