![]() |
Help with creating daemon for n900
Hi,
I'm trying to create a simple daemon that switches the speaker on/off by sliding the keyboard while on the call. I'm getting the result but the thing is its switching all the time and continuously monitoring the devices which, of course, gonna shorten battery life. So I'm trying to create a daemon that gets triggered only when the user clicks the "Answer" button to answer a call and stops with the user ending the call. So, just wondering if this is possible. In the mean time I'm going through the script from shortcutd that triggers the daemon and at the top it has "start on XSESSIONS_STARTING" followed by "stop on stopped hal" -: (ya I'm just learning to write one and most of the things in this script is kinda foreign language to me :D). Is it responsible for what I'm looking for and if so what are the other combinations I can choose? Any help/suggestions or links would be greatly appreciated. Thanks |
Re: Help with creating daemon for n900
not a 100% sure about this until I try it myself but you could register for the call state signal using dbus wrappers
MCE_CALL_STATE_SIG can have states like MCE_CALL_STATE_NONE "none" No ongoing call. #define MCE_CALL_STATE_RINGING "ringing" Call ringing. #define MCE_CALL_STATE_ACTIVE "active" Call on-going. you can activate listening to the keyboard status when the call is active or ringing. You could further listen to call status only when screen is on ( MCE_DISPLAY_STATUS_GET ), that would save battery as well. btw, I like your idea, good luck ! :) |
Re: Help with creating daemon for n900
Quote:
|
Re: Help with creating daemon for n900
Quote:
|
Re: Help with creating daemon for n900
Quote:
EDIT: Just went through the links and ya thats what I'm been going through till now - 4am, without being able to figure out how to use 'em as it just says return gchar * .. |
Re: Help with creating daemon for n900
Quote:
|
Re: Help with creating daemon for n900
Quote:
|
Re: Help with creating daemon for n900
Quote:
@jaeezzy Here's an example, using the lovely DBus-GLib bindings, that gets the current state and prints it out: http://slexy.org/view/s287btiNxS As you can see, I'm not in the habit of commenting my code. I'll try and explain anything asked, but I'm no expert on D-Bus. When I've finished it, I'll post again with another sample that automatically prints out the state when it changes. |
Re: Help with creating daemon for n900
Quote:
Code:
#include <dbus/dbus-glib.h> |
Re: Help with creating daemon for n900
Quote:
Make it, and run it on the N900. Whenever the call state changes, you will see a message. Use the code to implement something similar in your code (like !strcmp in the callback for MCE_CALL_STATE_ACTIVE etc. to know if you're in a call, and if you're using gtk_main, ignore the GMainloop stuff in the example.). I see you've been posting as I've been posting my sample. Take a look at the code I've given first, please. :) Merging my "on demand" code in #8 with this shouldn't be hard. |
Re: Help with creating daemon for n900
Quote:
|
Re: Help with creating daemon for n900
Quote:
|
Re: Help with creating daemon for n900
Quote:
g_signal_new requires a marshaller to be able to send whatever it receives (in this case, the two gchars* from MCE) to the callback function (see http://gnomejournal.org/article/36/w...d-gtk28-part-2 for an example on how it's used there). So, according to http://maemo.org/api_refs/5.0/5.0-fi...5a46afdad43a94 , we receive two gchars*. So our callback function signature is to look like "static void call_state_changed_cb (DBusGProxy *object G_GNUC_UNUSED, const gchar *call_state, const gchar *emergency_call_state G_GNUC_UNUSED, gpointer user_data G_GNUC_UNUSED)". (G_GNUC_UNUSED is only there because I'm [generally] pedantic/anal about GCC warnings...) But if we look at http://maemo.org/api_refs/5.0/5.0-fi...-Closures.html , we see GLib only comes with a marshaller (g_cclosure_marshal_VOID__STRING) that would only handle "static void call_state_changed_cb (DBusGProxy *object G_GNUC_UNUSED, const gchar *call_state, gpointer user_data G_GNUC_UNUSED)" (i.e. a DBus signal that only sends back one gchar*). That is not what we want and, in any case, it wouldn't work - the callback function would never be called. So we use glib-genmarshal to create a marshaller that understands VOID__STRING_STRING, matching the signature of the first callback function and we then use dbus_g_object_register_marshaller () to register it with DBus-GLib. |
Re: Help with creating daemon for n900
Quote:
Anyway, I've got it to work and quickly created a .deb file and does what it is suppose to do. I guess I'll start a new thread for it and let this one continue coz I have more to implement ;) |
Re: Help with creating daemon for n900
Quote:
But if you wish to use libhal; I haven't looked too deep into libhal because of the libdbus requirement, but I believe it requires a DBusConnection rather than a DBusGConnection. You can get a DBusConnection from your DBusGConnection by calling dbus_g_connection_get_connection (). The DBusConnection will automatically be integrated into the mainloop because dbus_connection_setup_with_g_main was called when you did dbus_g_dbus_get. However, you will have to look into the libhal API reference to see how you check for events and the like - I can't help there, sorry. P.S. If you're just checking to see if the keyboard is slid open, you can get the value of the GConf key /system/osso/af/slide-open. GConfClient is rather easy to use and you can get notifications of the key being changed. |
| All times are GMT. The time now is 22:24. |
vBulletin® Version 3.8.8