The profiles plug-in is in charge of ringing, vibrating, etc

This commit is contained in:
Pierre Pronchery 2010-05-17 14:04:36 +00:00
parent 5122bb6248
commit cdd5518525
4 changed files with 181 additions and 3 deletions

View File

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

View File

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

154
src/plugins/profiles.c Normal file
View File

@ -0,0 +1,154 @@
/* $Id$ */
/* Copyright (c) 2010 Pierre Pronchery <khorben@defora.org> */
/* 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 <http://www.gnu.org/licenses/>. */
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <libintl.h>
#include <pulse/pulseaudio.h>
#include <System.h>
#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;
}

View File

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