[systemd-devel] Dynamically add and remove sd-bus paths in a process

2018-11-02 Thread guhan balasubramanian
Hi,

I have a question regarding manipulating sd-bus paths during run time.

Let us assume the calculator example from:
http://0pointer.net/blog/the-new-sd-bus-api-of-systemd.html

We host the object /net/poettering/Calculator through
net.poettering.Calculator.

I am looking for ways to add/remove objects to the service after the
process has started.
Say adding objects: /net/poettering/ScientificCalculator ,
/net/poettering/ProgrammerCalculator

One approach I could think of is:
- Stop the infinite loop
- Unref the bus and slot
- Call required number of sd_bus_add_object_vtable  objects (3 in this case)
- Request a well known name and restart the infinite loop.

Is this the right way?
Can someone please help with any design patterns, references or pointers on
how we could achieve this?

Thanks,
Guhan

Another approach (Crude but not the desired way):
- Take the number of bus paths from a config file
- Change config file and restart the process (systemctl restart
process_name)
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] Sending complex structures over sd-bus

2018-10-25 Thread guhan balasubramanian
Hi,

I am trying to use the sd-bus to send structures that are a bit complex in
nature.

For example, consider the following:

struct complex_struct {
int some_integers[10];
char *str;
} cs;

cs property_to_send[10];

This d-bus property would be something like "a(ais)".

Assuming I want to send the above array, I am trying to right the
property's function handler in the sd_bus_server for the same.

I know the open and close container can be used for simple arrays. I am
finding it hard to make it work for the nested array case. Can some one
please help point me to any example or references for the same?

Thanks,
Guhan
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Returning arrays from sd-bus methods

2017-06-26 Thread guhan balasubramanian
Hi Lennart,

Thank you for the reply. Please find my comments inline:

On Sat, Jun 24, 2017 at 12:55 AM, Lennart Poettering <lenn...@poettering.net
> wrote:

> On Fri, 23.06.17 20:45, guhan balasubramanian (guhan@gmail.com) wrote:
>
> > Hi,
> >
> > I'm currently trying out sd-bus methods for my application. I am in a
> > situation where I must accept an input and return a byte array based on
> the
> > input.
> >
> > In the vtable. the following declaration is present:
> > SD_BUS_METHOD("method_id", "x", "ay", method_1, 0)
> >
> > And inside the definition for method_1, for returning:
> > uint8_t b[2] = {0x01, 0x02};
> > sd_bus_reply_method_return(m, "ay", b);
>
> if you use sd_bus_reply_method_return() (or sd_bus_append()) the
> arguments to pass for an array is the array's size followed by the
> members. Hence, the following should do what you want:
>
> sd_bus_reply_method_return(m, "ay", 2, 0x01, 0x02);
>

This worked for me. But I had the following three questions based on this:

1. Would it be a good design to construct a va_list of the array elements
and pass it as the last argument in sd_bus_reply_method_return?

2. I wasn't able to find the definition for sd_bus_append, I think you
meant *sd_bus_message_append*() right? But, if I do that and append the
array, I wouldn't be able to use *sd_bus_reply_method_return* with the
correct type. I was able to achieve this on get-property, since
property_handlers wouldn't need a return.

I am not sure about how to handle this one. Would I be able to find a
reference code/doc for this?

3. Is there an API to pass the entire container (array in this case) for a
 method return?


> Lennart
>
> --
> Lennart Poettering, Red Hat
>


Thanks,
Guhan
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] Returning arrays from sd-bus methods

2017-06-23 Thread guhan balasubramanian
Hi,

I'm currently trying out sd-bus methods for my application. I am in a
situation where I must accept an input and return a byte array based on the
input.

In the vtable. the following declaration is present:
SD_BUS_METHOD("method_id", "x", "ay", method_1, 0)

And inside the definition for method_1, for returning:
uint8_t b[2] = {0x01, 0x02};
sd_bus_reply_method_return(m, "ay", b);

This is giving me a segmentation error when I invoke method_1 using busctl.
I don't think this is the right way I should be returning an array type
from a method.

I am not able to find a reference code / documentation for implementing
such methods. Can someone please help me with the right way to do this?

Thanks,
Guhan


Virus-free.
www.avast.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] Storing Data on systemd bus

2017-02-06 Thread guhan balasubramanian
Hi,

I've followed the tutorial on the 0pointer blog [1] for creating a 'system'
service.
I am currently held up with two questions which would help me come up with
a better design for my "inventory" program.

   1. Is it possible to use sd-bus API as an inventory to store and
   retrieve data? Whether sd-bus internally would store the data in the bus
   forever until deleted, something like a message queue?
   2. If above question has a positive answer, I am trying to get and set
   properties by creating a service (Example 1 in Reference - Busctl Man
   Page ). I
   am doing this on the system bus, but I am not able to '*store the data
   in the bus'* as in the example. For now, I am only able to store data in
   the '*process memory' *as global variables.  [2] doesn't seem to help
   much as the bus is not storing the data using SD_BUS_WRITABLE_PROPERTY. Is
   there a reference code or documentation I can refer to?

Please advise and thanks in advance!

-Guhan

References:
1. http://0pointer.net/blog/the-new-sd-bus-api-of-systemd.html
2.
https://github.com/systemd/systemd/blob/master/src/libsystemd/sd-bus/test-bus-objects.c
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel