Commit bf99cb74 authored by llea's avatar llea
Browse files

Handle error messages - Handle refused calls

parent d3d9795f
......@@ -42,6 +42,7 @@ OBJS = \
configurationtree.o \
dtmf.o \
dtmfgenerator.o \
error.o \
g711.o \
main.o \
manager.o \
......@@ -66,8 +67,8 @@ OBJS = \
volumecontrol.o volumecontrol.moc.o \
stun.o udp.o
start: check prereq all
#start: check all
#start: check prereq all
start: check all
check:
ifeq ($(CONFIGURE_CONF),../configure.conf)
......
......@@ -47,10 +47,10 @@ public:
virtual unsigned int readableBytes (void) = 0;
AudioBuffer audio_buf; // Buffer that the application fills
protected:
DeviceState devstate; // Current state
DeviceMode devmode; // Current mode
};
......
......@@ -35,10 +35,11 @@
#define ALSA_DEVICE "plughw:0,0"
AudioDriversALSA::AudioDriversALSA(DeviceMode mode) : AudioDrivers () {
AudioDriversALSA::AudioDriversALSA(DeviceMode mode, Error *error) :
AudioDrivers () {
this->error = error;
audio_hdl = (snd_pcm_t *) NULL;
initDevice(mode);
}
AudioDriversALSA::~AudioDriversALSA (void) {
......@@ -59,7 +60,7 @@ AudioDriversALSA::initDevice (DeviceMode mode) {
int err;
if (devstate == DeviceOpened) {
printf ("ERROR: ALSA Device Already Open !\n");
error->errorName(DEVICE_ALREADY_OPEN, NULL);
return -1;
}
......@@ -83,6 +84,7 @@ AudioDriversALSA::initDevice (DeviceMode mode) {
if (err < 0) {
printf ("ERROR: ALSA/snd_pcm_open: Cannot open audio device (%s)\n",
snd_strerror (err));
error->errorName(OPEN_FAILED_DEVICE, NULL);
return -1;
}
////////////////////////////////////////////////////////////////////////////
......@@ -95,6 +97,7 @@ AudioDriversALSA::initDevice (DeviceMode mode) {
if (err < 0) {
printf ("Cannot allocate hardware parameter structure (%s)\n",
snd_strerror (err));
error->errorName(PARAMETER_STRUCT_ERROR_ALSA, (char*)snd_strerror(err));
return -1;
}
......@@ -102,6 +105,7 @@ AudioDriversALSA::initDevice (DeviceMode mode) {
if ((err = snd_pcm_hw_params_any (audio_hdl, hw_params)) < 0) {
printf ("Cannot initialize hardware parameter structure (%s)\n",
snd_strerror (err));
error->errorName(PARAMETER_STRUCT_ERROR_ALSA, (char*)snd_strerror(err));
return -1;
}
......@@ -109,6 +113,8 @@ AudioDriversALSA::initDevice (DeviceMode mode) {
SND_PCM_ACCESS_RW_INTERLEAVED);
if (err < 0) {
printf ("Cannot set access type (%s)\n", snd_strerror (err));
error->errorName(ACCESS_TYPE_ERROR_ALSA, (char*)snd_strerror(err));
return -1;
}
// Set sample formats (Signed, 16Bits, little endian)
......@@ -116,6 +122,7 @@ AudioDriversALSA::initDevice (DeviceMode mode) {
SND_PCM_FORMAT_S16_LE);
if (err < 0) {
printf ("Cannot set sample format (%s)\n", snd_strerror (err));
error->errorName(SAMPLE_FORMAT_ERROR_ALSA, (char*)snd_strerror(err));
return -1;
}
......@@ -128,6 +135,7 @@ AudioDriversALSA::initDevice (DeviceMode mode) {
&exact_rate, 0);
if (err < 0) {
printf ("Cannot set sample rate (%s)\n", snd_strerror (err));
error->errorName(SAMPLE_RATE_ERROR_ALSA, (char*)snd_strerror(err));
return -1;
}
if (exact_rate != rate) {
......@@ -138,6 +146,7 @@ AudioDriversALSA::initDevice (DeviceMode mode) {
err = snd_pcm_hw_params_set_channels (audio_hdl, hw_params, MONO);
if (err < 0) {
printf ("Cannot set channel count (%s)\n", snd_strerror (err));
error->errorName(CHANNEL_ERROR_ALSA, (char*)snd_strerror(err));
return -1;
}
......@@ -145,6 +154,7 @@ AudioDriversALSA::initDevice (DeviceMode mode) {
err = snd_pcm_hw_params (audio_hdl, hw_params);
if (err < 0) {
printf ("Cannot set parameters (%s)\n", snd_strerror (err));
error->errorName(PARAM_SETUP_ALSA, (char*)snd_strerror(err));
return -1;
}
......@@ -163,7 +173,7 @@ AudioDriversALSA::initDevice (DeviceMode mode) {
int
AudioDriversALSA::writeBuffer (void) {
if (devstate != DeviceOpened) {
printf ("ALSA: writeBuffer(): Device Not Open\n");
error->errorName(DEVICE_NOT_OPEN, NULL);
return -1;
}
......@@ -189,7 +199,7 @@ AudioDriversALSA::writeBuffer (void) {
int
AudioDriversALSA::readBuffer (void *ptr, int bytes) {
if( devstate != DeviceOpened ) {
printf ("ALSA: readBuffer(): Device Not Open\n");
error->errorName(DEVICE_NOT_OPEN, NULL);
return -1;
}
......@@ -214,12 +224,14 @@ AudioDriversALSA::resetDevice (void) {
printf("Resetting...\n");
if ((err = snd_pcm_drop(audio_hdl)) < 0) {
printf ("ALSA: drop() error: %s\n", snd_strerror (err));
printf ("ALSA: drop() error: %s\n", snd_strerror (err));
error->errorName(DROP_ERROR_ALSA, (char*)snd_strerror(err));
return -1;
}
if ((err = snd_pcm_prepare(audio_hdl)) < 0) {
printf ("ALSA: prepare() error: %s\n", snd_strerror (err));
printf ("ALSA: prepare() error: %s\n", snd_strerror (err));
error->errorName(PREPARE_ERROR_ALSA, (char*)snd_strerror(err));
return -1;
}
......
......@@ -23,6 +23,8 @@
#include <alsa/asoundlib.h>
#include "audiodrivers.h"
#include "error.h"
/**
* This is the ALSA implementation of DspOut.
......@@ -35,7 +37,7 @@ public:
* Constructs a AudioDriversALSA object representing the given
* filename. Default is /dev/dsp.
*/
AudioDriversALSA(DeviceMode);
AudioDriversALSA(DeviceMode, Error*);
/**
* Destructor. Will close the device if it is open.
......@@ -50,6 +52,8 @@ public:
unsigned int readableBytes (void) { return 0; }
private:
Error * error;
snd_pcm_t *audio_hdl;
void closeDevice (void);
};
......
......@@ -35,7 +35,9 @@
#include "global.h"
AudioDriversOSS::AudioDriversOSS (DeviceMode mode) : AudioDrivers () {
AudioDriversOSS::AudioDriversOSS (DeviceMode mode, Error *error) :
AudioDrivers () {
this->error = error;
audio_fd = -1;
initDevice(mode);
}
......@@ -73,24 +75,27 @@ AudioDriversOSS::initDevice (DeviceMode mode) {
}
if (devstate == DeviceOpened) {
error->errorName(DEVICE_ALREADY_OPEN, NULL);
return -1;
}
// Open device in non-blocking mode
audio_fd = open (AUDIO_DEVICE, oflag | O_NONBLOCK );
if (audio_fd == -1) {
printf ("ERROR: Open Failed\n");
return -1;
}
error->errorName(OPEN_FAILED_DEVICE, NULL);
return -1;
}
// Remove O_NONBLOCK
int flags = fcntl(audio_fd, F_GETFL) & ~O_NONBLOCK;
fcntl (audio_fd, F_SETFL, flags);
// Fragments : No limit (0x7FFF),
int frag = ( ( 0x7FFF << 16 ) | 7 );
if (ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &frag)) {
printf ("ERROR: SETFRAG %s\n", strerror(errno));
error->errorName(FRAGMENT_ERROR_OSS, strerror(errno));
return -1;
}
......@@ -100,6 +105,7 @@ AudioDriversOSS::initDevice (DeviceMode mode) {
if (ioctl(audio_fd, SNDCTL_DSP_SETFMT, &format) == -1) {
printf("ERROR: SETFMT %s\n", strerror(errno));
error->errorName(SAMPLE_FORMAT_ERROR_OSS, strerror(errno));
return -1;
}
if (format != AFMT_S16_LE) {
......@@ -111,6 +117,7 @@ AudioDriversOSS::initDevice (DeviceMode mode) {
int channels = MONO;
if (ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &channels) == -1) {
printf ("ERROR: DSP_STEREO %s\n", strerror(errno));
error->errorName(CHANNEL_ERROR_OSS, strerror(errno));
return -1;
}
if (channels != MONO) {
......@@ -122,6 +129,7 @@ AudioDriversOSS::initDevice (DeviceMode mode) {
int rate = SAMPLING_RATE;
if (ioctl(audio_fd, SNDCTL_DSP_SPEED, &rate ) == -1 ) {
printf ("ERROR: DSP_SPEED %s\n", strerror(errno));
error->errorName(SAMPLE_RATE_ERROR_OSS, strerror(errno));
return -1;
}
......@@ -135,11 +143,13 @@ AudioDriversOSS::initDevice (DeviceMode mode) {
if (mode == WriteOnly) {
if (ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info) == -1) {
printf ("ERROR: GETISPACE %s\n", strerror(errno));
error->errorName(GETISPACE_ERROR_OSS, strerror(errno));
return -1;
}
} else {
if (ioctl(audio_fd, SNDCTL_DSP_GETISPACE, &info ) == -1) {
printf ("ERROR: GETOSPACE %s\n", strerror(errno));
error->errorName(GETOSPACE_ERROR_OSS, strerror(errno));
return -1;
}
}
......@@ -180,12 +190,11 @@ AudioDriversOSS::openDevice (int exist_fd) {
int
AudioDriversOSS::readBuffer (void *ptr, int bytes) {
if( devstate != DeviceOpened ) {
printf ("Device Not Open\n");
return false;
}
ssize_t count = bytes;
ssize_t rc;
rc = read (audio_fd, ptr, count);
if (rc < 0) {
printf ("rc < 0 read(): %s\n", strerror(errno));
......@@ -201,7 +210,6 @@ AudioDriversOSS::readBuffer (void *ptr, int bytes) {
int
AudioDriversOSS::readBuffer (int bytes) {
if( devstate != DeviceOpened ) {
printf ("Device Not Open\n");
return -1;
}
......@@ -227,7 +235,7 @@ AudioDriversOSS::readBuffer (int bytes) {
int
AudioDriversOSS::writeBuffer (void *ptr, int len) {
if (devstate != DeviceOpened ) {
printf ("Device Not Opened\n");
error->errorName(DEVICE_NOT_OPEN, NULL);
return -1;
}
......@@ -258,7 +266,7 @@ AudioDriversOSS::writeBuffer (void *ptr, int len) {
int
AudioDriversOSS::writeBuffer (void) {
if (devstate != DeviceOpened ) {
printf ("Device Not Opened\n");
error->errorName(DEVICE_NOT_OPEN, NULL);
return -1;
}
......
......@@ -25,13 +25,14 @@
#include "audiodrivers.h"
#include "error.h"
// TODO : a mettre dans config
#define AUDIO_DEVICE "/dev/dsp"
class AudioDriversOSS : public AudioDrivers {
public:
AudioDriversOSS (DeviceMode);
AudioDriversOSS (DeviceMode, Error*);
~AudioDriversOSS (void);
int initDevice (DeviceMode);
......@@ -46,7 +47,7 @@ public:
int audio_fd;
private:
int closeDevice (void);
Error * error;
};
#endif // _AUDIO_DRIVERS_OSS_H
......@@ -154,7 +154,6 @@ AudioRtpRTX::~AudioRtpRTX () {
void
AudioRtpRTX::run (void) {
// AudioCodec ac;
unsigned char *data_to_send;
short *data_mute;
short *data_from_mic;
......@@ -328,10 +327,10 @@ AudioRtpRTX::run (void) {
audioDevice->audio_buf.setData (data_for_speakers,
manager->getSpkrVolume());
// Notify (with a bip) an incoming call when there is already call
// Notify (with a bip) an incoming call when there is already a call
countTime += TimerPort::getElapsed();
if (manager->sip->getNumberPendingCalls() != 1) {
if ((countTime % 3000) <= 10 and (countTime % 3000) >= 0) {
if (manager->getNumberPendingCalls() != 1 and manager->ringing()) {
if ((countTime % 2000) <= 10 and (countTime % 2000) >= 0) {
manager->notificationIncomingCall();
}
}
......
This diff is collapsed.
This diff is collapsed.
/****************************************************************************
** Form interface generated from reading ui file 'configurationpanel.ui'
**
** Created: Thu Mar 31 12:04:22 2005
** Created: Tue Apr 12 09:35:08 2005
** by: The User Interface Compiler ($Id$)
**
** WARNING! All changes made in this file will be lost!
......@@ -118,9 +118,10 @@ public:
QTabWidget* Tab_About;
QWidget* DriversPage_5;
QLabel* textLabel2_2;
QLabel* pixmapLabel1;
QWidget* CodecsPage_4;
QLabel* textLabel1;
QLabel* pixmapLabel2;
QLabel* textLabel1;
public slots:
virtual void saveSlot();
......@@ -165,6 +166,7 @@ protected slots:
private:
QPixmap image0;
QPixmap image1;
void init();
......
#include "error.h"
#include <string>
using namespace std;
Error::Error (Manager *_mngr){
this->mngr = _mngr;
issetError = 0;
}
int
Error::errorName (Error_enum num_name, char* err) {
string str;
switch (num_name){
// Handle opening device errors
case DEVICE_NOT_OPEN:
printf ("ERROR: Device Not Open\n");
mngr->errorDisplay("Device not open ");
issetError = 2;
break;
case DEVICE_ALREADY_OPEN:
printf ("ERROR: Device Already Open !\n");
mngr->errorDisplay("Device already open ");
issetError = 2;
break;
case OPEN_FAILED_DEVICE:
printf ("ERROR: Open Failed\n");
mngr->errorDisplay("Open device failed ");
issetError = 2;
break;
// Handle ALSA errors
case PARAMETER_STRUCT_ERROR_ALSA:
str = str.append("Error with hardware parameter structure: ") + err;
mngr->errorDisplay((char*)str.data());
issetError = 1;
break;
case ACCESS_TYPE_ERROR_ALSA:
str = str.append("Cannot set access type: ") + err;
mngr->errorDisplay((char*)str.data());
issetError = 1;
break;
case SAMPLE_FORMAT_ERROR_ALSA:
str = str.append("Cannot set sample format: ") + err;
mngr->errorDisplay((char*)str.data());
issetError = 1;
break;
case SAMPLE_RATE_ERROR_ALSA:
str = str.append("Cannot set sample rate: ") + err;
mngr->errorDisplay((char*)str.data());
issetError = 1;
break;
case CHANNEL_ERROR_ALSA:
str = str.append("Cannot set channel: ") + err;
mngr->errorDisplay((char*)str.data());
issetError = 1;
break;
case PARAM_SETUP_ALSA:
str = str.append("Cannot set parameters: ") + err;
mngr->errorDisplay((char*)str.data());
issetError = 1;
break;
case DROP_ERROR_ALSA:
str = str.append("Error: drop(): ") + err;
mngr->errorDisplay((char*)str.data());
issetError = 1;
break;
case PREPARE_ERROR_ALSA:
str = str.append("Error: prepare(): ") + err;
mngr->errorDisplay((char*)str.data());
issetError = 1;
break;
// Handle OSS errors
case FRAGMENT_ERROR_OSS:
str = str.append("Error: SNDCTL_DSP_SETFRAGMENT: ") + err;
mngr->errorDisplay((char*)str.data());
issetError = 1;
break;
case SAMPLE_FORMAT_ERROR_OSS:
str = str.append("Error: SNDCTL_DSP_SETFMT: ") + err;
mngr->errorDisplay((char*)str.data());
issetError = 1;
break;
case CHANNEL_ERROR_OSS:
str = str.append("Error: SNDCTL_DSP_CHANNELS: ") + err;
mngr->errorDisplay((char*)str.data());
issetError = 1;
break;
case SAMPLE_RATE_ERROR_OSS:
str = str.append("Error: SNDCTL_DSP_SPEED: ") + err;
mngr->errorDisplay((char*)str.data());
issetError = 1;
break;
case GETISPACE_ERROR_OSS:
str = str.append("Error: SNDCTL_DSP_GETISPACE: ") + err;
mngr->errorDisplay((char*)str.data());
issetError = 1;
break;
case GETOSPACE_ERROR_OSS:
str = str.append("Error: SNDCTL_DSP_GETOSPACE: ") + err;
mngr->errorDisplay((char*)str.data());
issetError = 1;
break;
// Handle setup errors
case HOST_PART_FIELD_EMPTY:
mngr->errorDisplay("Fill host part field");
issetError = 2;
break;
case USER_PART_FIELD_EMPTY:
mngr->errorDisplay("Fill user part field");
issetError = 2;
break;
case PASSWD_FIELD_EMPTY:
mngr->errorDisplay("Fill password field");
issetError = 2;
break;
// Handle sip uri
case FROM_ERROR:
mngr->errorDisplay("Error for 'From' header");
issetError = 1;
break;
case TO_ERROR:
mngr->errorDisplay("Error for 'To' header");
issetError = 1;
break;
default:
issetError = 0;
break;
}
return issetError;
}
#ifndef __ERROR_H__
#define __ERROR_H__
#include <stdio.h>
#include "manager.h"
typedef enum {
DEVICE_NOT_OPEN = 0,
DEVICE_ALREADY_OPEN,
OPEN_FAILED_DEVICE,
PARAMETER_STRUCT_ERROR_ALSA,
ACCESS_TYPE_ERROR_ALSA,
SAMPLE_FORMAT_ERROR_ALSA,
SAMPLE_RATE_ERROR_ALSA,
CHANNEL_ERROR_ALSA,
PARAM_SETUP_ALSA,
DROP_ERROR_ALSA,
PREPARE_ERROR_ALSA,
FRAGMENT_ERROR_OSS,
SAMPLE_FORMAT_ERROR_OSS,
CHANNEL_ERROR_OSS,
SAMPLE_RATE_ERROR_OSS,
GETISPACE_ERROR_OSS,
GETOSPACE_ERROR_OSS,
HOST_PART_FIELD_EMPTY,
USER_PART_FIELD_EMPTY,
PASSWD_FIELD_EMPTY,
FROM_ERROR,
TO_ERROR
} Error_enum;
class Error {
public:
Error (Manager *);
~Error (void) {};
int errorName (Error_enum, char *);
inline int getError (void) { return issetError; }
inline void setError(int err) { issetError = err; }
private:
Manager *mngr;
int issetError;
};
#endif // __ERROR_H__
......@@ -46,13 +46,13 @@
#include "audiortp.h"
#include "sip.h"
#include "qtGUImainwindow.h"
#include "error.h"
#include <string>
using namespace std;
Manager::Manager (QString *Dc = NULL) {
DirectCall = Dc;
bool exist;
for (int i = 0; i < NUMBER_OF_LINES; i++) {
phLines[i] = new PhoneLine ();
}
......@@ -67,9 +67,9 @@ Manager::Manager (QString *Dc = NULL) {
sip = new SIP(this);
tone = new ToneGenerator(this);
audioRTP = new AudioRtp(this);
error = new Error(this);
sip_init();
selectAudioDriver();
// Init variables
......@@ -90,7 +90,7 @@ Manager::Manager (QString *Dc = NULL) {
gui()->configuration();
}
initVolume ();
initVolume ();
}
Manager::~Manager (void) {
......@@ -117,7 +117,8 @@ Manager::createSettingsPath (void) {
bool exist = true;
char * buffer;
// Get variable $HOME
buffer = getenv ("HOME"); path = string(buffer);
buffer = getenv ("HOME");
path = string(buffer);
path = path + "/." + PROGNAME;
if (mkdir (path.data(), 0755) != 0) {
......@@ -134,21 +135,21 @@ Manager::createSettingsPath (void) {
}
return exist;
}
/**
* Call audio driver constructor according to the selected driver in setup
*/
void
void
Manager::selectAudioDriver (void) {
if (Config::getb("Audio", "Drivers.driverOSS")) {
useAlsa = false;
this->audiodriver = new AudioDriversOSS (AudioDrivers::ReadWrite);
this->audiodriver = new AudioDriversOSS (AudioDrivers::ReadWrite, error);
}
if (Config::getb("Audio", "Drivers.driverALSA")) {
#ifdef ALSA
useAlsa = true;
this->audiodriver = new AudioDriversALSA (AudioDrivers::WriteOnly);
this->audiodriverReadAlsa = new AudioDriversALSA (AudioDrivers::ReadOnly);
this->audiodriver = new AudioDriversALSA (AudioDrivers::WriteOnly, error);
this->audiodriverReadAlsa = new AudioDriversALSA (AudioDrivers::ReadOnly, error);
#endif