Pelagicore / gdbus-codegen-glibmm

Code generator for C++ D-Bus stubs and proxies using Giomm/Glibmm
GNU Lesser General Public License v2.1
23 stars 25 forks source link

Problem with methods that output (si) #13

Closed klukaspl closed 6 years ago

klukaspl commented 6 years ago

Hi,

the problematic thing was to generate the method that get int as input argument, and output (si) - variant containing string and integer. My solution: In my code I overloaded the ret function in _common.h file to the following:

void ret(Glib::VariantContainerBase& p0)
{
m_message->return_value(p0);
}

then in my working class I implemented my example function as that:

virtual void myFunction (gint32 InArg, ProcessorMessageHelper msg)
  {
    std::cout << "HERE THE InArg IS: " << InArg << std::endl;

    Glib::VariantContainerBase::CType outArg = NULL;

    unsigned int outArg2 = InArg + 100;
    std::string outArg1 = "Example: " + std::to_string(InArg) + " VALUE IS: ";
    outArg = g_variant_new("(si)", outArg1.c_str(), outArg2);
    Glib::Variant<unsigned int> outVar(outArg);
    Glib::VariantContainerBase response = Glib::VariantContainerBase::create_tuple(outVar);

    msg.ret(response);
  }

I hope this can help someone to get the solution before the generator will be capable to solve that.

BTW: the example function is definied in XML as:

<method name="myFunction">
      <arg name="InArg"  direction="in"  type="i"/>
      <arg name="OutArg" direction="out" type="(si)"/>
</method>

BR Krzysztof

jonte commented 6 years ago

Hi Krzysztof,

@mardy has been working on adding "complex" type support to the code generator in the past few days, and we just (a few minutes ago) merged support for that. One of the complex types now supported is structs, such as your (si).

The tests now contain a test case for (ss), which should be very similar to your (si). For the XML, see here: https://github.com/Pelagicore/gdbus-codegen-glibmm/blob/master/test/common/many-types.xml#L45,

For the C++ code which accepts the (ss) as an input parameter, see here: https://github.com/Pelagicore/gdbus-codegen-glibmm/blob/master/test/stub/teststubmain.cpp#L125 and for returning it, you can see that there is now a auto-generated ret which takes a std::tuple: https://github.com/Pelagicore/gdbus-codegen-glibmm/blob/master/test/stub/teststubmain.cpp#L128.

You can also see the latest test run, where we generate code for (ss) on both stub and proxy side, and make a test run here: https://travis-ci.org/Pelagicore/gdbus-codegen-glibmm/jobs/371881144#L1658

I hope this solves your issue!

klukaspl commented 6 years ago

Hi,

Thank you for update. I tried new generated function:

void ret(std::tuple<Glib::ustring,gint32> p0)
{
    std::vector<Glib::VariantBase> vlist;
    vlist.push_back(Glib::Variant<std::tuple<Glib::ustring,gint32> >::create((p0)));

    m_message->return_value(Glib::Variant<Glib::VariantBase>::create_tuple(vlist));
}

But have the following problem with compilation:

error: ‘create’ is not a member of ‘Glib::Variant<std::tuple<Glib::ustring, int> >’ vlist.push_back(Glib::Variant<std::tuple<Glib::ustring,gint32> >::create((p0)));

Any ideas?

BR Krzysztof

jonte commented 6 years ago

Hi,

Which version of glibmm are you using?

This has been verified to work on 2.56 (https://travis-ci.org/Pelagicore/gdbus-codegen-glibmm/jobs/371881144#L1546).

klukaspl commented 6 years ago

Hi, I belive I have glibmm-2.4 2.24.4. The funny thing is that the ide is showing that create is the member function but maybe this is using newer header. EDIT:: And the documentation claims that:

static Variant<std::string> Glib::Variant< std::string >::create ( const std::string & data )

since glibmm 2.28:

So my library is obsolete! That is the answer.

Thank you for your support! BR, Krzysztof