Active Topics

 


Reply
Thread Tools
jaeezzy's Avatar
Posts: 664 | Thanked: 160 times | Joined on Jul 2008 @ Australia
#1
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 ). 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
 

The Following User Says Thank You to jaeezzy For This Useful Post:
krk969's Avatar
Posts: 754 | Thanked: 630 times | Joined on Sep 2009 @ London
#2
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 !
__________________
Developer of :
Buddy - budget/expense manager ( website )
Showtime - a telly channel listing viewer/reminder ( website )
Travelapp - london underground status/planner ( website )
Batlevel - desktop widget for battery level ( website )

“I hear and I forget. I see and I remember. I do and I understand.”

Last edited by krk969; 2010-03-08 at 10:53.
 

The Following 2 Users Say Thank You to krk969 For This Useful Post:
jaeezzy's Avatar
Posts: 664 | Thanked: 160 times | Joined on Jul 2008 @ Australia
#3
Originally Posted by krk969 View Post
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 !
Thanks for the the reply. The main idea I took from brainstorm as it will be bit of a practise as well but I guess it's killing me coz I have been trying since to use the mce-dev but without any success. Googling didn't help either. I just couldn't figure out how I can make use of those constants. As you said that you have tried them yourself, it would be great if you could show me how you did. Thank you.
 
qwerty12's Avatar
Posts: 4,274 | Thanked: 5,358 times | Joined on Sep 2007 @ Looking at y'all and sighing
#4
Originally Posted by jaeezzy View Post
I just couldn't figure out how I can make use of those constants.
In combination with the D-Bus method calls and signals it provides (http://maemo.org/api_refs/5.0/5.0-fi...5a46afdad43a94 and http://maemo.org/api_refs/5.0/5.0-fi...1a695659d394da in particular). What are you programming your daemon in? Are you using Qt or GLib/GTK?
 
jaeezzy's Avatar
Posts: 664 | Thanked: 160 times | Joined on Jul 2008 @ Australia
#5
Originally Posted by qwerty12 View Post
In combination with the D-Bus method calls and signals it provides (http://maemo.org/api_refs/5.0/5.0-fi...5a46afdad43a94 and http://maemo.org/api_refs/5.0/5.0-fi...1a695659d394da in particular). What are you programming your daemon in? Are you using Qt or GLib/GTK?
Thanks. I'm using GLib/GTK.

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 * ..

Last edited by jaeezzy; 2010-03-08 at 17:10.
 
krk969's Avatar
Posts: 754 | Thanked: 630 times | Joined on Sep 2009 @ London
#6
Originally Posted by jaeezzy View Post
Thanks. I'm using GLib/GTK.
I suggest you try using QT , if you are starting off, its much simpler to read and write
__________________
Developer of :
Buddy - budget/expense manager ( website )
Showtime - a telly channel listing viewer/reminder ( website )
Travelapp - london underground status/planner ( website )
Batlevel - desktop widget for battery level ( website )

“I hear and I forget. I see and I remember. I do and I understand.”
 
jaeezzy's Avatar
Posts: 664 | Thanked: 160 times | Joined on Jul 2008 @ Australia
#7
Originally Posted by krk969 View Post
I suggest you try using QT , if you are starting off, its much simpler to read and write
ya I'm thinking but as I'm bit familier with C, I started with C/GTK.
 
qwerty12's Avatar
Posts: 4,274 | Thanked: 5,358 times | Joined on Sep 2007 @ Looking at y'all and sighing
#8
Originally Posted by krk969 View Post
if you are starting off, its much simpler to read and write
**** no!

@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.

Last edited by qwerty12; 2010-03-08 at 17:28.
 

The Following User Says Thank You to qwerty12 For This Useful Post:
jaeezzy's Avatar
Posts: 664 | Thanked: 160 times | Joined on Jul 2008 @ Australia
#9
Originally Posted by qwerty12 View Post
**** no!

@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.
Thanks. BTW, it seems I was doing exactly same thing which I got from the web but just didn't work so thought it wasn't how it should be done any way here it is. I would be glad if any one can point out where I did wrong. Thanks.

Code:
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <glib.h>
#include <stdio.h>
#include <string.h>

#include <mce/dbus-names.h>
#include <mce/mode-names.h>

#include <stdlib.h>

typedef struct{
	DBusGProxy *proxy;
	gchar *call_state;
	gchar *call_e_state;	
} PSSwitcherD;
	
static void mce_call_state_changed(DBusGProxy*, const gchar*, const gchar*, gpointer);
static void private_free(gpointer);
static GStaticPrivate private_key = G_STATIC_PRIVATE_INIT;

int main(int argc, char *argv[]){
	DBusGConnection *dbus;
	GError *dbus_err = NULL;
	
	PSSwitcherD *switcher;
	switcher = g_new0(PSSwitcherD, 1);
	g_static_private_set(&private_key, switcher, private_free);
	
	dbus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &dbus_err);
	
	if (!dbus){
		g_print("D-BUS Connection FAILED!!!\n");
		g_clear_error(&dbus_err);
		return 1;
	}
	
	switcher->proxy = dbus_g_proxy_new_for_name(dbus, MCE_SERVICE, MCE_SIGNAL_PATH, MCE_SIGNAL_IF);
	dbus_g_proxy_add_signal(switcher->proxy, MCE_CALL_STATE_SIG, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
	dbus_g_proxy_connect_signal(switcher->proxy, MCE_CALL_STATE_SIG, G_CALLBACK(mce_call_state_changed), NULL, NULL);
	
	g_print("Requesting current call state...\n");
	
	dbus_g_proxy_call(switcher->proxy, MCE_CALL_STATE_GET, &dbus_err, G_TYPE_INVALID, G_TYPE_STRING, 
					  &switcher->call_state, G_TYPE_STRING, &switcher->call_e_state, G_TYPE_INVALID);
					  
	if (dbus_err){
		g_print("couldn't request current call state.\n");
		g_clear_error(&dbus_err);
	}else{
		g_print("Current state is %s.\n", switcher->call_state);
	}
	
	return 0;
}

static void mce_call_state_changed(DBusGProxy *proxy, const gchar *call_state, const gchar *call_e_state,
							gpointer user_data){
	PSSwitcherD *switcher;
	switcher = g_static_private_get(&private_key);
	g_return_if_fail(switcher != NULL);
	g_print("Call state changed to %s\n", call_state);
	
	g_free(switcher->call_state);
	switcher->call_state = g_strdup(call_state);
	
	g_free(switcher->call_e_state);
	switcher->call_e_state = g_strdup(call_e_state);
	
	if (g_strcmp0(call_state, MCE_CALL_STATE_NONE))
		g_print("DOING NOTHING\n");
	else if (g_strcmp0(call_state, MCE_CALL_STATE_RINGING))
		g_print("BLOODY RINGING\n");
}

static void private_free(gpointer data){
	PSSwitcherD *switcher;
	switcher = data;
	g_free(switcher->call_state);
	g_free(switcher->call_e_state);
	if (switcher->proxy)
		g_object_unref(switcher->proxy);
	g_free(switcher);
}
 
qwerty12's Avatar
Posts: 4,274 | Thanked: 5,358 times | Joined on Sep 2007 @ Looking at y'all and sighing
#10
Originally Posted by qwerty12 View Post
When I've finished it, I'll post again with another sample that automatically prints out the state when it changes.
As promised: http://qwerty12.qole.org/pimp2.tar

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.
 
Reply


 
Forum Jump


All times are GMT. The time now is 21:07.