maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   How to create Qt service? (https://talk.maemo.org/showthread.php?t=67039)

smandava 2010-12-15 20:34

How to create Qt service?
 
Hi,

My requirement is to create a Qt based backend service that runs when the device boots and call a function periodically (say every 15 minutes). Very similar to a cron tab.

So far I could find QDBus and QtMobility service framework modules that shows how to implement a service. It is not clear from the documentation weather these services can be run as daemons or the service die after serving the client request.

Can somebody provide a qt way of creating service that runs as daemon and doesn't hurt device battery? Any example projects or code snippets would be much appreciated.

Thanks,
Sateesh.

kif 2010-12-15 22:32

Re: How to create Qt service?
 
Hi

You can use QtService, you can download it from qt.nokia.com.

I'm using it in one of my projects, and it works great with QtMobility and QDBus, only problem I had was when trying to use anything from user space (calendar in my case), as this is a service, it does not have readily access to user space.

Kim

uvatbc 2010-12-15 23:53

Re: How to create Qt service?
 
Quote:

Originally Posted by smandava (Post 897611)
Hi,

My requirement is to create a Qt based backend service that runs when the device boots and call a function periodically (say every 15 minutes). Very similar to a cron tab.

So far I could find QDBus and QtMobility service framework modules that shows how to implement a service. It is not clear from the documentation weather these services can be run as daemons or the service die after serving the client request.

Can somebody provide a qt way of creating service that runs as daemon and doesn't hurt device battery? Any example projects or code snippets would be much appreciated.

Thanks,
Sateesh.

It depends what you want to achieve. A service is fundamentally an application that has no user interaction and thus no need for a UI.
It may be instructed to perform certain functionality by "poking" it using an IPC mechanism like DBus.

If you intend your service to be cross platform to Windows or Mac, then you should use QtService.
Installing and starting the service is heavily dependent on the target OS:
eg. Most Linux variants have upstart / init.d / event.d, Windows would require you to setup registry entries or invoke SCM.

smandava 2010-12-16 00:47

Re: How to create Qt service?
 
Thanks for the leads about QTSevice. If QTService doesn't work in user space, I am afraid I cant use it. I will look at the QTService api closely.

To clarify what exactly what I am trying to achieve, I have a qt application that can sync Google contacts with N900 device contacts. I am trying to set it up as a service so that the service can call the sync function every 15 minutes without user interaction. Cross platform functionality is not my primary concern at this time.

This service needs to run under the user space and be started every time the device is rebooted. I am not sure if init.d/event.d scripts always run as root or if they can be configured to run under user space.

I will have another UI client that will poke the service to modify the update frequency etc..

Thanks,
Sateesh.

uvatbc 2010-12-16 01:17

Re: How to create Qt service?
 
All of QT is user space. Do not even think of using it in kernel mode.

Also: I have a google contacts API parser ready in case you're interested.
I was supposed to work on a google contacts sync tool, but I've pushed it back until my other project is in better shape.

MohammadAG 2010-12-16 01:42

Re: How to create Qt service?
 
Why not just use a QTimer instance?

smandava 2010-12-16 01:49

Re: How to create Qt service?
 
Quote:

Originally Posted by uvatbc (Post 897788)
All of QT is user space. Do not even think of using it in kernel mode.

Also: I have a google contacts API parser ready in case you're interested.
I was supposed to work on a google contacts sync tool, but I've pushed it back until my other project is in better shape.

I guess what Kim mentioned above is QtMobilty Contacts Api opens the address book for the user who started the process. For instance QContactManager.contacts() calls gives different results for user account and developer account even tho its the same binary is making the call.

If the service is started (by init.d or upstart) as root user, the service will see the address book of root account instead of the intended default user account. Do you know if init.d or event.d scripts can start a process as default user?

I am noob to the Qt Programming. I would love to get the GData parser if you have available. Please PM me or post the link to this thread.

Thanks,
Sateesh.

smandava 2010-12-16 01:59

Re: How to create Qt service?
 
Quote:

Originally Posted by MohammadAG (Post 897796)
Why not just use a QTimer instance?

I am new to Qt and not sure if If this a common way to creating server in Qt. Not sure if the program consumes any resources (effecting the battery life) while sitting waiting for QTimer signal.

If this not CPU intensive, I will proceed with this option.

Thanks,
Sateesh.

javispedro 2010-12-16 02:13

Re: How to create Qt service?
 
There's a cron-like daemon running on the device:

http://wiki.maemo.org/Documentation/...larm_Framework

smandava 2010-12-16 02:32

Re: How to create Qt service?
 
Quote:

Originally Posted by javispedro (Post 897807)
There's a cron-like daemon running on the device:

http://wiki.maemo.org/Documentation/...larm_Framework

Great. I wish there is a Qt API for alarmd.


All times are GMT. The time now is 00:59.

vBulletin® Version 3.8.8