Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7684977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:09:02+00:00 2026-05-31T19:09:02+00:00

I am trying to send an array of this struct to a DBus Server:

  • 0

I am trying to send an array of this struct to a DBus Server:

typedef struct
{
    guint arg1;
    guchar msg[DTC_ACTION_PATH_LENGTH];
} DTC_ErrorMessage;

Here is the function I am working on:

gint fillMessage(GPtrArray **msg, DTC_ErrorMessage *data)
{
    g_assert(NULL != msg);
    g_assert(NULL == *msg);
    g_assert(NULL != data);

    *msg = g_ptr_array_new();
    g_assert(NULL != *msg);

    GValueArray *container = g_value_array_new(2); // struct of 2 elements
GValue v;

    memset(&v, 0, sizeof(GValue));

    // Insert first element of the struct
    g_value_init(&v, G_TYPE_INT);
    g_value_set_int(&v, data->arg1);
    g_value_array_append(container, &v);
    g_value_unset(&v);

    // Add code here for the second element of the struct

    g_ptr_array_add(*msg, (gpointer) container);

    return 0;
}

The questions are:

  • Is this the correct way to send complex structures over DBus? Because it seems very “intricate” to me.
  • How can I complete this function in order to add the second element of the struct?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:09:04+00:00Added an answer on May 31, 2026 at 7:09 pm

    This solution seems to work:

    gint fillMessage(GPtrArray **msg, DTC_ErrorMessage *data)
    {
        g_assert(NULL != msg);
        g_assert(NULL == *msg);
        g_assert(NULL != data);
    
        *msg = g_ptr_array_new();
        g_assert(NULL != *msg);
    
        GValueArray *vals;
        GArray *garray;
    
        vals = g_value_array_new(2);
    
        g_value_array_append(vals, NULL);
        g_value_init(g_value_array_get_nth(vals, 0), G_TYPE_UINT);
        g_value_set_uint(g_value_array_get_nth(vals, 0), data->arg1);
    
        garray = g_array_new(FALSE, TRUE, sizeof(guchar));
        gint i;
        for(i = 0; i < DTC_ACTION_PATH_LENGTH; i++)
        {
            g_array_append_val(garray, data->msg[i]);
        }
    
        g_value_array_append(vals, NULL);
        g_value_init (g_value_array_get_nth(vals, 1), dbus_g_type_get_collection ("GArray", G_TYPE_UCHAR));
        g_value_take_boxed (g_value_array_get_nth(vals, 1), garray);
    
        g_ptr_array_add(*msg, vals);
    
        return 0;
    }
    

    Any better solution would be appreciated!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use jQuery's $getJSON to send an array of 'ids'. Here's what
I'm trying to convert a struct to a char array to send over the
I have a string array like {myname,yourname,hisname} and I am trying to send this
I'm trying to load an array in my javascript. I need to send this
Hi Im trying to send an array from php to my javascript. Is this
I am trying to send object's array to Spring controller via jQuery AJAX. Here
I'm trying to send the Length of a Byte array to my server, so
I am trying to send the result of a split() function into an array
I'm trying to copy data from an array of character that send from main
I am trying to send the database Array by using the method below: OracleConnection

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.