Hiya,
TL;DR: Is it possible to define an API function with the return type ‘string’?
I would like to build an API function to return the text representation of an enum value (similar to what LE_RESULT_TXT() uses).
I have defined an api function like so:
FUNCTION string ModeToString
(
int32 pMode IN
);
where pMode is my input value to translate.
I’ve implemented this in my C file like this:
const char *myapi_ModeToString ( int32_t pMode )
{
switch (pMode)
{
case 0: return "MODE 0";
case 1: return "MODE 1";
default: return "(unknown)";
}
}
but the build tools are not happy and throw this error when parsing the .api file:
In file included from /home/developer/legato-18.10.3-octave/framework/include/legato.h:200:0,
from /home/developer/dev-18.10.3-octave/project/mbService/_BUILD_motherboard.wp77xx/api/01815889a894043e810253f2f92771e5/server/myapi_server.h:17,
from /home/developer/dev-18.10.3-octave/project/mbService/_BUILD_motherboard.wp77xx/api/01815889a894043e810253f2f92771e5/server/myapi_server.c:12:
/home/developer/dev-18.10.3-octave/project/mbService/_BUILD_motherboard.wp77xx/api/01815889a894043e810253f2f92771e5/server/myapi_server.c: In function ‘Handle_myapi_ModeToString’:
/home/developer/dev-18.10.3-octave/project/mbService/_BUILD_motherboard.wp77xx/api/01815889a894043e810253f2f92771e5/server/myapi_server.c:356:15: error: too few arguments to function ‘le_pack_PackString’
/home/developer/legato-18.10.3-octave/framework/include/le_log.h:561:15: note: in definition of macro ‘LE_ASSERT’
In file included from /home/developer/legato-18.10.3-octave/framework/include/legato.h:215:0,
from /home/developer/dev-18.10.3-octave/project/mbService/_BUILD_motherboard.wp77xx/api/01815889a894043e810253f2f92771e5/server/myapi_server.h:17,
from /home/developer/dev-18.10.3-octave/project/mbService/_BUILD_motherboard.wp77xx/api/01815889a894043e810253f2f92771e5/server/myapi_server.c:12:
/home/developer/legato-18.10.3-octave/framework/include/le_pack.h:358:20: note: declared here
[7/84] Generating IPC interface code
ninja: build stopped: subcommand failed.
Makefile:84: recipe for target 'build' failed
make: *** [build] Error 1
Any suggestions gratefully accepted.
ciao, Dave