Using empty arrays for passing of variable structures as arguments
Bogdan Lotko
boguslaw.lotko at chello.at
Fri Jun 17 04:38:10 PDT 2011
Hello,
Is it a good idea to use arrays for controlling the variable content of
a structure ( normally it would be a pointer that could be NULL) by passing
it as parameter?
e.g.
typedef strruct
{
int x;
int y;
} structB;
struct A
{
bool hasB; // just as example
structB *sB; // Must not be NULL if hasB == true
...
}
The sent type will be always coded as (ba(ii)) where the array can have
0 or 1 entries.
If the structB is empty ("sB == NULL") the empty array will be sent.
The coding in low level API would be like:
// Structure container strA for struct A already opened
dbus_message_iter_open_container( &str,
DBUS_TYPE_ARRAY,
(ii),
&arr );
// if "not NULL" open and fill the strB container for struct B
// otherwise close the arr container immediately
dbus_message_iter_open_container( &strA, &arr );
Is there any other / better method do this same?
Thanks for your help
with best regards,
Bogdan
More information about the dbus
mailing list