mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
OP-286 UAVObjectManager: Dont store pointer to initialize function for
UAVObjects, but pass it in from the macro definition. Saves memory for each objects. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2559 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
0fa8589fc3
commit
3fc8169330
@ -135,7 +135,7 @@ const char* UAVObjGetName(UAVObjHandle obj);
|
||||
uint32_t UAVObjGetNumBytes(UAVObjHandle obj);
|
||||
uint16_t UAVObjGetNumInstances(UAVObjHandle obj);
|
||||
UAVObjHandle UAVObjGetLinkedObj(UAVObjHandle obj);
|
||||
uint16_t UAVObjCreateInstance(UAVObjHandle obj);
|
||||
uint16_t UAVObjCreateInstance(UAVObjHandle obj, UAVObjInitializeCallback initCb);
|
||||
int32_t UAVObjIsSingleInstance(UAVObjHandle obj);
|
||||
int32_t UAVObjIsMetaobject(UAVObjHandle obj);
|
||||
int32_t UAVObjIsSettings(UAVObjHandle obj);
|
||||
|
@ -60,7 +60,7 @@
|
||||
#define $(NAME)InstSet(instId, dataIn) UAVObjSetInstanceData($(NAME)Handle(), instId, dataIn)
|
||||
#define $(NAME)ConnectQueue(queue) UAVObjConnectQueue($(NAME)Handle(), queue, EV_MASK_ALL_UPDATES)
|
||||
#define $(NAME)ConnectCallback(cb) UAVObjConnectCallback($(NAME)Handle(), cb, EV_MASK_ALL_UPDATES)
|
||||
#define $(NAME)CreateInstance() UAVObjCreateInstance($(NAME)Handle())
|
||||
#define $(NAME)CreateInstance() UAVObjCreateInstance($(NAME)Handle(),&$(NAME)SetDefaults)
|
||||
#define $(NAME)RequestUpdate() UAVObjRequestUpdate($(NAME)Handle())
|
||||
#define $(NAME)RequestInstUpdate(instId) UAVObjRequestInstanceUpdate($(NAME)Handle(), instId)
|
||||
#define $(NAME)Updated() UAVObjUpdated($(NAME)Handle())
|
||||
@ -80,6 +80,7 @@ $(DATAFIELDINFO)
|
||||
// Generic interface functions
|
||||
int32_t $(NAME)Initialize();
|
||||
UAVObjHandle $(NAME)Handle();
|
||||
void $(NAME)SetDefaults(UAVObjHandle obj, uint16_t instId);
|
||||
|
||||
#endif // $(NAMEUC)_H
|
||||
|
||||
|
@ -69,7 +69,6 @@ struct ObjectListStruct {
|
||||
int8_t isSettings; /** Set to 1 if this object is a settings object */
|
||||
uint16_t numBytes; /** Number of data bytes contained in the object (for a single instance) */
|
||||
uint16_t numInstances; /** Number of instances */
|
||||
UAVObjInitializeCallback initCb; /** Object field and metadata initialization callback */
|
||||
struct ObjectListStruct* linkedObj; /** Linked object, for regular objects this is the metaobject and for metaobjects it is the parent object */
|
||||
ObjectInstList* instances; /** List of object instances, instance 0 always exists */
|
||||
ObjectEventList* events; /** Event queues registered on the object */
|
||||
@ -197,7 +196,6 @@ UAVObjHandle UAVObjRegister(uint32_t id, const char* name, const char* metaName,
|
||||
objEntry->numBytes = numBytes;
|
||||
objEntry->events = NULL;
|
||||
objEntry->numInstances = 0;
|
||||
objEntry->initCb = initCb;
|
||||
objEntry->instances = NULL;
|
||||
objEntry->linkedObj = NULL; // will be set later
|
||||
LL_APPEND(objList, objEntry);
|
||||
@ -225,9 +223,9 @@ UAVObjHandle UAVObjRegister(uint32_t id, const char* name, const char* metaName,
|
||||
}
|
||||
|
||||
// Initialize object fields and metadata to default values
|
||||
if ( objEntry->initCb != NULL )
|
||||
if ( initCb != NULL )
|
||||
{
|
||||
objEntry->initCb((UAVObjHandle)objEntry, 0);
|
||||
initCb((UAVObjHandle)objEntry, 0);
|
||||
}
|
||||
|
||||
// Attempt to load object's metadata from the SD card (not done directly on the metaobject, but through the object)
|
||||
@ -366,7 +364,7 @@ uint16_t UAVObjGetNumInstances(UAVObjHandle obj)
|
||||
* \param[in] obj The object handle
|
||||
* \return The instance ID or 0 if an error
|
||||
*/
|
||||
uint16_t UAVObjCreateInstance(UAVObjHandle obj)
|
||||
uint16_t UAVObjCreateInstance(UAVObjHandle obj, UAVObjInitializeCallback initCb)
|
||||
{
|
||||
ObjectList* objEntry;
|
||||
ObjectInstList* instEntry;
|
||||
@ -384,9 +382,9 @@ uint16_t UAVObjCreateInstance(UAVObjHandle obj)
|
||||
}
|
||||
|
||||
// Initialize instance data
|
||||
if ( objEntry->initCb != NULL )
|
||||
if ( initCb != NULL )
|
||||
{
|
||||
objEntry->initCb(obj, instEntry->instId);
|
||||
initCb(obj, instEntry->instId);
|
||||
}
|
||||
|
||||
// Unlock
|
||||
|
@ -42,9 +42,6 @@
|
||||
// Private variables
|
||||
static UAVObjHandle handle;
|
||||
|
||||
// Private functions
|
||||
static void setDefaults(UAVObjHandle obj, uint16_t instId);
|
||||
|
||||
/**
|
||||
* Initialize object.
|
||||
* \return 0 Success
|
||||
@ -54,7 +51,7 @@ int32_t $(NAME)Initialize()
|
||||
{
|
||||
// Register object with the object manager
|
||||
handle = UAVObjRegister($(NAMEUC)_OBJID, $(NAMEUC)_NAME, $(NAMEUC)_METANAME, 0,
|
||||
$(NAMEUC)_ISSINGLEINST, $(NAMEUC)_ISSETTINGS, $(NAMEUC)_NUMBYTES, &setDefaults);
|
||||
$(NAMEUC)_ISSINGLEINST, $(NAMEUC)_ISSETTINGS, $(NAMEUC)_NUMBYTES, &$(NAME)SetDefaults);
|
||||
|
||||
// Done
|
||||
if (handle != 0)
|
||||
@ -72,7 +69,7 @@ int32_t $(NAME)Initialize()
|
||||
* If a default value is not specified the object fields
|
||||
* will be initialized to zero.
|
||||
*/
|
||||
static void setDefaults(UAVObjHandle obj, uint16_t instId)
|
||||
void $(NAME)SetDefaults(UAVObjHandle obj, uint16_t instId)
|
||||
{
|
||||
$(NAME)Data data;
|
||||
UAVObjMetadata metadata;
|
||||
|
Loading…
x
Reference in New Issue
Block a user