diff --git a/Makefile b/Makefile index eb1d02b..cf00108 100644 --- a/Makefile +++ b/Makefile @@ -57,6 +57,7 @@ dist: $(PACKAGE)-$(VERSION)/src/common.c \ $(PACKAGE)-$(VERSION)/src/project.conf \ $(PACKAGE)-$(VERSION)/src/plugins/openmoko.c \ + $(PACKAGE)-$(VERSION)/src/plugins/profiles.c \ $(PACKAGE)-$(VERSION)/src/plugins/Makefile \ $(PACKAGE)-$(VERSION)/src/plugins/project.conf \ $(PACKAGE)-$(VERSION)/COPYING \ diff --git a/src/plugins/Makefile b/src/plugins/Makefile index 6bb9918..ff2a046 100644 --- a/src/plugins/Makefile +++ b/src/plugins/Makefile @@ -1,4 +1,4 @@ -TARGETS = openmoko.so +TARGETS = openmoko.so profiles.so PREFIX = /usr/local DESTDIR = LIBDIR = $(PREFIX)/lib @@ -25,11 +25,21 @@ openmoko_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) openmoko.so: $(openmoko_OBJS) $(LD) -o openmoko.so $(openmoko_OBJS) +profiles_OBJS = profiles.o +profiles_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) `pkg-config --cflags libpulse` +profiles_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) `pkg-config --libs libpulse` + +profiles.so: $(profiles_OBJS) + $(LD) -o profiles.so $(profiles_OBJS) `pkg-config --libs libpulse` + openmoko.o: openmoko.c ../../include/Phone.h $(CC) $(openmoko_CFLAGS) -c openmoko.c +profiles.o: profiles.c ../../include/Phone.h + $(CC) $(profiles_CFLAGS) -c profiles.c + clean: - $(RM) $(openmoko_OBJS) + $(RM) $(openmoko_OBJS) $(profiles_OBJS) distclean: clean $(RM) $(TARGETS) @@ -37,8 +47,11 @@ distclean: clean install: all $(MKDIR) $(DESTDIR)$(LIBDIR)/Phone/plugins $(INSTALL) -m 0644 openmoko.so $(DESTDIR)$(LIBDIR)/Phone/plugins/openmoko.so + $(MKDIR) $(DESTDIR)$(LIBDIR)/Phone/plugins + $(INSTALL) -m 0644 profiles.so $(DESTDIR)$(LIBDIR)/Phone/plugins/profiles.so uninstall: $(RM) $(DESTDIR)$(LIBDIR)/Phone/plugins/openmoko.so + $(RM) $(DESTDIR)$(LIBDIR)/Phone/plugins/profiles.so .PHONY: all clean distclean install uninstall diff --git a/src/plugins/profiles.c b/src/plugins/profiles.c new file mode 100644 index 0000000..b31eea1 --- /dev/null +++ b/src/plugins/profiles.c @@ -0,0 +1,154 @@ +/* $Id$ */ +/* Copyright (c) 2010 Pierre Pronchery */ +/* This file is part of DeforaOS Desktop Phone */ +/* This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + + + +#include +#include +#include +#include +#include +#include +#include "Phone.h" +#include "../../config.h" +#define _(string) gettext(string) + +#ifndef PREFIX +# define PREFIX "/usr/local" +#endif +#ifndef DATADIR +# define DATADIR PREFIX "/share" +#endif + + +/* Profiles */ +/* private */ +/* types */ +typedef struct _Profiles +{ + int event; + /* pulseaudio */ + pa_threaded_mainloop * pam; + pa_context * pac; + pa_operation * pao; +} Profiles; + +/* prototypes */ +static int _profiles_init(PhonePlugin * plugin); +static int _profiles_destroy(PhonePlugin * plugin); +static int _profiles_event(PhonePlugin * plugin, PhoneEvent event, ...); + + +/* public */ +/* variables */ +PhonePlugin plugin = +{ + NULL, + _profiles_init, + _profiles_destroy, + _profiles_event, + NULL +}; + + +/* private */ +/* functions */ +/* profiles_init */ +static int _profiles_init(PhonePlugin * plugin) +{ + Profiles * profiles; + pa_mainloop_api * mapi = NULL; + +#ifdef DEBUG + fprintf(stderr, "DEBUG: %s()\n", __func__); +#endif + if((profiles = malloc(sizeof(*profiles))) == NULL) + return error_set_code(1, "%s", strerror(errno)); + plugin->priv = profiles; + profiles->event = -1; + profiles->pam = pa_threaded_mainloop_new(); + profiles->pac = NULL; + profiles->pao = NULL; + if(profiles->pam == NULL) + { + _profiles_destroy(plugin); + return error_set_code(1, "%s", + _("Could not initialize PulseAudio")); + } + mapi = pa_threaded_mainloop_get_api(profiles->pam); + /* XXX update the context name */ + if((profiles->pac = pa_context_new(mapi, "Openmoko Dialer")) == NULL) + { + _profiles_destroy(plugin); + return error_set_code(1, "%s", + _("Could not initialize PulseAudio")); + } + pa_context_connect(profiles->pac, NULL, 0, NULL); + pa_threaded_mainloop_start(profiles->pam); + return 0; +} + + +/* profiles_destroy */ +static int _profiles_destroy(PhonePlugin * plugin) +{ + Profiles * profiles = plugin->priv; + +#ifdef DEBUG + fprintf(stderr, "DEBUG: %s()\n", __func__); +#endif + if(profiles->pao != NULL) + pa_operation_cancel(profiles->pao); + if(profiles->pac != NULL) + pa_context_unref(profiles->pac); + pa_threaded_mainloop_free(profiles->pam); + free(profiles); + return 0; +} + + +/* profiles_event */ +static int _profiles_event(PhonePlugin * plugin, PhoneEvent event, ...) +{ + Profiles * profiles = plugin->priv; + + if(profiles->event == (int)event) + return 0; + if(profiles->pao != NULL) + pa_operation_cancel(profiles->pao); + profiles->pao = NULL; + switch(event) + { + case PHONE_EVENT_CALL_INCOMING: + profiles->pao = pa_context_play_sample(profiles->pac, + "ringtone", NULL, PA_VOLUME_NORM, NULL, + NULL); + break; + case PHONE_EVENT_SMS_RECEIVED: + profiles->pao = pa_context_play_sample(profiles->pac, + "message", NULL, PA_VOLUME_NORM, NULL, + NULL); + break; + case PHONE_EVENT_SMS_SENT: + break; /* anything to implement? */ + case PHONE_EVENT_CALL_OUTGOING: + case PHONE_EVENT_CALL_TERMINATED: + case PHONE_EVENT_CALL_ESTABLISHED: + pa_operation_cancel(profiles->pao); + break; + } + profiles->event = event; + return 0; +} diff --git a/src/plugins/project.conf b/src/plugins/project.conf index 76e796d..4e045f8 100644 --- a/src/plugins/project.conf +++ b/src/plugins/project.conf @@ -1,4 +1,4 @@ -targets=openmoko +targets=openmoko,profiles cppflags_force=-I ../../include cppflags=-I $(PREFIX)/include cflags_force=-W @@ -12,3 +12,13 @@ install=$(LIBDIR)/Phone/plugins [openmoko.c] depends=../../include/Phone.h + +[profiles] +type=plugin +sources=profiles.c +cflags=`pkg-config --cflags libpulse` +ldflags=`pkg-config --libs libpulse` +install=$(LIBDIR)/Phone/plugins + +[profiles.c] +depends=../../include/Phone.h