How to use own defined struct in .api file

Hello,
I have a requirement to use my own defined structure in the .api file. Somehow I am successfully doing this like below:

File: abc.api
REFERENCE Params;
FUNCTION Info(Params params OUT);

File: abcd.h
typedef struct {
//Common parameters
int32_t signal_strength;
int32_t temperature;
uint32_t level;
}abc_Params;

File: abcde.c
void abc_Info(abc_ParamsRef_t* params) {

//Here I can’t access the struct members
}

Could anyone please help

Hello sowviroy

*.api files do not support structures

Solution #1:
Use different functions to pass the difference structure fields

Solution #2:
abc_Params myStruc;
Use le_event_Report ( myEvtId, & myStruc, sizeof ( myStruc ) );

KR.

I do need to use a structure in an API call.
Legato documentation shows there is a provision for STRUCT. But it is not recognised by compiler.
Wasnt it supposed to work?

Hiya,

API doesn’t support a struct as a ‘datatype’.

The struct you see mentioned in the docs are just how the IPC library deals with references - they’re actually an opaque data type that you treat as a void pointer.

This has caused me grief for a couple of years…

ciao, Dave

hi any samples available how to use struct in user defined api.thanks in advance

how about this?

StructApi.tar.gz (3.0 KB)
am getting the following error, can u guide me how to pass input to the struct and my sample is attached for your refernce

Jan 6 10:27:00 swi-mdm9x28-wp user.info Legato: INFO | ClientCompExe[4274]/ClientComp T=main | ClientComp.c _ClientComp_COMPONENT_INIT() 17 | LOG_CLIENT> start
Jan 6 10:27:00 swi-mdm9x28-wp user.info Legato: INFO | ClientCompExe[4274]/ClientComp T=main | ClientComp.c _ClientComp_COMPONENT_INIT() 24 | LOG_CLIENT> make the request no 1 to server
Jan 6 10:27:00 swi-mdm9x28-wp user.info Legato: INFO | StructApiComponentExe[4273]/StructApiComponent T=main | StructApiComponent.c Sample_logMessage() 26 | LOG_SERVER> received the message “log from client : request no 1” from a client.
Jan 6 10:27:10 swi-mdm9x28-wp user.emerg Legato: EMR | ClientCompExe[4274]/framework T=main | Sample_client.c Sample_arraySend() 667 | Assert Failed: ‘Sample_PackARRAY123( &_msgBufPtr, &_msgBufSize, asdPtr )’
Jan 6 10:27:10 swi-mdm9x28-wp user.info Legato: INFO | supervisor[4058]/supervisor T=main | proc.c proc_SigChildHandler() 2051 | Process ‘ClientCompExe’ (PID: 4274) has exited with exit code 1.
Jan 6 10:27:10 swi-mdm9x28-wp user.warn Legato: -WRN- | supervisor[4058]/supervisor T=main | app.c app_SigChildHandler() 4031 | Process ‘ClientCompExe’ in app ‘StructApi’ faulted: Ignored.

Can yoy use the sample code in the link which is proven to be working fine

i exactly use the same program but getting error , the only change made is instead of two app i used two component

How about just running my app with two app

getting same error, dont know what am missing

Are you using swi-wp76_4.7.0

no its swi-wp76_4.0.1

Can you try the same