Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AWA_OPAQUE macro to Awa static API #68

Merged
3 commits merged into from
Mar 17, 2016
Merged

Add AWA_OPAQUE macro to Awa static API #68

3 commits merged into from
Mar 17, 2016

Conversation

cdewbery
Copy link
Collaborator

The opaque data type is a little different from all the others
being that it is variable length (and doesn't provide another
mechanism to determine it's length, i.e NULL terminated)

This means we need to store a provide a pointer to data, as
well as a pointer to store the length to the
AwaStaticClient_RegisterResourceWithPointer() function.

Now we could simply pass in a pointer to a AwaOpaque data type,
but this is setup for dynamic memory allocation, which goes
against the whole point of the WithPointer() function.

So, to allow variable length opaque data types to be statically
allocated, I have added the AWA_OPAQUE macro.

This macro can be used in place of a variable declaration.

for example:

AWA_OPAQUE(opaque, 32);

strcpy(opaque.Data, "hello");
opaque.Size = strlen("hello");

AWA_OPAQUE(opaque_array, 32)[10];

strcpy(opaque_array[2].Data, "hello2");
opaque_array[2].Size = strlen("hello2");

I have also added the internal data type AwaStaticOpaque which allows
the core to access the elements like so:

AwaStaticOpaque * temp = (AwaStaticOpaque*)&opaque
printf("size %d value %s\n", temp->Size, temp->Data);

Signed-off-by: Chris Dewbery [email protected]

Chris Dewbery added 3 commits March 17, 2016 15:56
The opaque data type is a little different from all the others
being that it is variable length (and doesn't provide another
mechanism to determine it's length, i.e NULL terminated)

This means we need to store a provide a pointer to data, as
well as a pointer to store the length to the
AwaStaticClient_RegisterResourceWithPointer() function.

Now we could simply pass in a pointer to a AwaOpaque data type,
but this is setup for dynamic memory allocation, which goes
against the whole point of the WithPointer() function.

So, to allow variable length opaque data types to be statically
allocated, I have added the AWA_OPAQUE macro.

This macro can be used in place of a variable declaration.

for example:

    AWA_OPAQUE(opaque, 32);

    strcpy(opaque.Data, "hello");
    opaque.Size = strlen("hello");

    AWA_OPAQUE(opaque_array, 32)[10];

    strcpy(opaque_array[2].Data, "hello2");
    opaque_array[2].Size = strlen("hello2");

I have also added the internal data type AwaStaticOpaque which allows
the core to access the elements like so:

    AwaStaticOpaque * temp = (AwaStaticOpaque*)&opaque
    printf("size %d value %s\n", temp->Size, temp->Data);

Signed-off-by: Chris Dewbery <[email protected]>
ghost pushed a commit that referenced this pull request Mar 17, 2016
Add AWA_OPAQUE macro to Awa static API
@ghost ghost merged commit fe3aa6c into ConnectivityFoundry:master Mar 17, 2016
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant