Commit 46cc7036 authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

Error messages through DBUS

The daemon sends only the error code to the client, instead of sending error code and string description
The client is aware of the nature of the error via the code
parent 9624f08f
......@@ -33,7 +33,8 @@
#include <sys/types.h>
#include <unistd.h>
#define ALSA_ERROR 0
#define ALSA_ERROR_CAPTURE_DEVICE 0
#define ALSA_ERROR_PLAYBACK_DEVICE 1
#define TONE_WITHOUT_MESSAGE 0
#define TONE_WITH_MESSAGE 1
......@@ -582,15 +583,17 @@ sflphone_set_default_account( )
}
void
sflphone_throw_exception( gchar* msg , int err )
sflphone_throw_exception( int errCode )
{
gchar* markup = malloc(1000);
switch( err ){
case ALSA_ERROR:
sprintf( markup , _("<b>ALSA notification</b>\n\n"));
switch( errCode ){
case ALSA_ERROR_PLAYBACK_DEVICE:
sprintf( markup , _("<b>ALSA notification</b>\n\nError while opening playback device"));
break;
case ALSA_ERROR_CAPTURE_DEVICE:
sprintf( markup , _("<b>ALSA notification</b>\n\nError while opening capture device"));
break;
}
sprintf( markup , "%s%s" , markup , msg );
main_window_error_message( markup );
free( markup );
}
......
......@@ -111,6 +111,6 @@ void sflphone_place_call ( call_t * c );
void sflphone_fill_account_list();
void sflphone_set_default_account();
void sflphone_throw_exception( gchar* msg , int err );
void sflphone_throw_exception( int errCode );
void sflphone_fill_codec_list();
#endif
......@@ -152,12 +152,11 @@ accounts_changed_cb (DBusGProxy *proxy,
static void
error_alert(DBusGProxy *proxy,
gchar* errMsg,
int err,
int errCode,
void * foo )
{
g_print ("Error notifying : (%s)\n" , errMsg);
sflphone_throw_exception( errMsg , err );
g_print ("Error notifying : (%i)\n" , errCode);
sflphone_throw_exception( errCode );
}
gboolean
......@@ -254,10 +253,10 @@ dbus_connect ()
dbus_g_proxy_connect_signal (configurationManagerProxy,
"accountsChanged", G_CALLBACK(accounts_changed_cb), NULL, NULL);
dbus_g_object_register_marshaller(g_cclosure_user_marshal_VOID__STRING_INT,
G_TYPE_NONE, G_TYPE_STRING, G_TYPE_INT , G_TYPE_INVALID);
dbus_g_object_register_marshaller(g_cclosure_user_marshal_VOID__INT,
G_TYPE_NONE, G_TYPE_INT , G_TYPE_INVALID);
dbus_g_proxy_add_signal (configurationManagerProxy,
"errorAlert", G_TYPE_STRING , G_TYPE_INT , G_TYPE_INVALID);
"errorAlert", G_TYPE_INT , G_TYPE_INVALID);
dbus_g_proxy_connect_signal (configurationManagerProxy,
"errorAlert", G_CALLBACK(error_alert), NULL, NULL);
return TRUE;
......
......@@ -123,7 +123,9 @@ g_cclosure_user_marshal_VOID__STRING_STRING (GClosure *closure,
data2);
}
/* VOID:STRING,INT (marshaller.list:3) */
/* VOID:INT (marshaller.list:3) */
/* VOID:STRING,INT (marshaller.list:4) */
void
g_cclosure_user_marshal_VOID__STRING_INT (GClosure *closure,
GValue *return_value,
......@@ -160,7 +162,7 @@ g_cclosure_user_marshal_VOID__STRING_INT (GClosure *closure,
data2);
}
/* VOID:STRING,DOUBLE (marshaller.list:4) */
/* VOID:STRING,DOUBLE (marshaller.list:5) */
void
g_cclosure_user_marshal_VOID__STRING_DOUBLE (GClosure *closure,
GValue *return_value,
......
......@@ -22,7 +22,10 @@ extern void g_cclosure_user_marshal_VOID__STRING_STRING (GClosure *closure,
gpointer invocation_hint,
gpointer marshal_data);
/* VOID:STRING,INT (marshaller.list:3) */
/* VOID:INT (marshaller.list:3) */
#define g_cclosure_user_marshal_VOID__INT g_cclosure_marshal_VOID__INT
/* VOID:STRING,INT (marshaller.list:4) */
extern void g_cclosure_user_marshal_VOID__STRING_INT (GClosure *closure,
GValue *return_value,
guint n_param_values,
......@@ -30,7 +33,7 @@ extern void g_cclosure_user_marshal_VOID__STRING_INT (GClosure *closure,
gpointer invocation_hint,
gpointer marshal_data);
/* VOID:STRING,DOUBLE (marshaller.list:4) */
/* VOID:STRING,DOUBLE (marshaller.list:5) */
extern void g_cclosure_user_marshal_VOID__STRING_DOUBLE (GClosure *closure,
GValue *return_value,
guint n_param_values,
......
VOID:STRING,STRING,STRING
VOID:STRING,STRING
VOID:INT
VOID:STRING,INT
VOID:STRING,DOUBLE
......@@ -37,7 +37,7 @@
AudioLayer::AudioLayer(ManagerImpl* manager)
: _defaultVolume(100)
, _errorMessage("")
, _errorMessage(-1)
, _manager(manager)
, _PlaybackHandle( NULL )
, _CaptureHandle( NULL )
......@@ -313,11 +313,10 @@ AudioLayer::open_device(std::string pcm_p, std::string pcm_c, int flag)
if(flag == SFL_PCM_BOTH || flag == SFL_PCM_CAPTURE)
{
_debugAlsa(" Opening capture device %s\n", pcm_c.c_str());
_debugAlsa("Opening capture device %s\n", pcm_c.c_str());
if(err = snd_pcm_open(&_CaptureHandle, pcm_c.c_str(), SND_PCM_STREAM_CAPTURE, 0) < 0){
errMsg << " Error while opening capture device " << pcm_c.c_str() << " (" << snd_strerror(err) << ")";
_debugAlsa(" %s\n", errMsg.str().c_str());
setErrorMessage( errMsg.str() );
_debugAlsa("Error while opening capture device %s\n", pcm_c.c_str());
setErrorMessage( ERROR_ALSA_CAPTURE_DEVICE );
return false;
}
......@@ -346,9 +345,8 @@ AudioLayer::open_device(std::string pcm_p, std::string pcm_c, int flag)
_debugAlsa(" Opening playback device %s\n", pcm_p.c_str());
if(err = snd_pcm_open(&_PlaybackHandle, pcm_p.c_str(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK ) < 0){
errMsg << " Error while opening playback device " << pcm_p.c_str() << " (" << snd_strerror(err) << ")";
_debugAlsa(" %s\n", errMsg.str().c_str());
setErrorMessage( errMsg.str() );
_debugAlsa("Error while opening playback device %s\n", pcm_c.c_str());
setErrorMessage( ERROR_ALSA_PLAYBACK_DEVICE );
return false;
}
if( err = snd_pcm_hw_params_malloc( &hwParams ) < 0 ) {
......
......@@ -157,8 +157,8 @@ class AudioLayer {
bool soundCardIndexExist( int card , int stream );
int soundCardGetIndex( std::string description );
void setErrorMessage(const std::string& error) { _errorMessage = error; }
std::string getErrorMessage() { return _errorMessage; }
void setErrorMessage(const int& error) { _errorMessage = error; }
int getErrorMessage() { return _errorMessage; }
/*
* Get the index of the audio card for capture
......@@ -360,7 +360,7 @@ class AudioLayer {
std::vector<HwIDPair> IDSoundCards;
std::string _errorMessage;
int _errorMessage;
ost::Mutex _mutex;
};
......
......@@ -230,7 +230,6 @@ public:
};
static ::DBus::IntrospectedArgument errorAlert_args[] =
{
{ "errMsg", "s", false },
{ "code", "i", false },
{ 0, 0, 0 }
};
......@@ -351,12 +350,11 @@ public:
::DBus::SignalMessage sig("accountsChanged");
emit_signal(sig);
}
void errorAlert( const ::DBus::String& arg1, const ::DBus::Int32& arg2 )
void errorAlert( const ::DBus::Int32& arg1 )
{
::DBus::SignalMessage sig("errorAlert");
::DBus::MessageIter wi = sig.writer();
wi << arg1;
wi << arg2;
emit_signal(sig);
}
......
......@@ -150,7 +150,6 @@
</signal>
<signal name="errorAlert">
<arg type="s" name="errMsg" direction="out"/>
<arg type="i" name="code" direction="out"/>
</signal>
......
......@@ -30,7 +30,6 @@
typedef float float32;
typedef short int16;
#define _(string) gettext (string)
#ifdef DATAFORMAT_IS_FLOAT
#define SFLDataFormat float32
......@@ -71,7 +70,7 @@ typedef short int16;
#define RINGDIR "ringtones"
#define CODECDIR "codecs"
//#define _(arg) arg
#define _(arg) arg
#define MONO 1
#define CHANNELS 2
#define SIZEBUF 1024*1024
......@@ -111,4 +110,10 @@ typedef short int16;
#define ILBC_STRING_DESCRIPTION "ilbc"
#define RINGTONE_ENABLED 1
#define ERROR_ALSA_CAPTURE_DEVICE 0
#define ERROR_ALSA_PLAYBACK_DEVICE 1
//#define ERROR_ALSA_OPENING_CAPTURE_DEVICE 0
//#define ERROR_ALSA_OPENING_CAPTURE_DEVICE 0
//#define ERROR_ALSA_OPENING_CAPTURE_DEVICE 0
#endif // __GLOBAL_H__
......@@ -106,7 +106,6 @@ ManagerImpl::~ManagerImpl (void)
delete _DNSService; _DNSService = 0;
#endif
//notifyErrClient( " done " );
_debug("%s stop correctly.\n", PROGNAME);
}
......@@ -450,7 +449,7 @@ ManagerImpl::initRegisterAccounts()
iter++;
}
// calls the client notification here in case of errors at startup...
if( _audiodriver -> getErrorMessage() != "" )
if( _audiodriver -> getErrorMessage() != -1 )
notifyErrClient( _audiodriver -> getErrorMessage() );
return true;
}
......@@ -1273,14 +1272,14 @@ ManagerImpl::getOutputAudioPluginList(void)
ManagerImpl::setInputAudioPlugin(const std::string& audioPlugin)
{
_debug("Set input audio plugin\n");
_audiodriver -> setErrorMessage( "" );
_audiodriver -> setErrorMessage( -1 );
_audiodriver -> openDevice( _audiodriver -> getIndexIn(),
_audiodriver -> getIndexOut(),
_audiodriver -> getSampleRate(),
_audiodriver -> getFrameSize(),
SFL_PCM_CAPTURE,
audioPlugin);
if( _audiodriver -> getErrorMessage() != "")
if( _audiodriver -> getErrorMessage() != -1)
notifyErrClient( _audiodriver -> getErrorMessage() );
}
......@@ -1291,14 +1290,14 @@ ManagerImpl::setInputAudioPlugin(const std::string& audioPlugin)
ManagerImpl::setOutputAudioPlugin(const std::string& audioPlugin)
{
_debug("Set output audio plugin\n");
_audiodriver -> setErrorMessage( "" );
_audiodriver -> setErrorMessage( -1 );
_audiodriver -> openDevice( _audiodriver -> getIndexIn(),
_audiodriver -> getIndexOut(),
_audiodriver -> getSampleRate(),
_audiodriver -> getFrameSize(),
SFL_PCM_BOTH,
audioPlugin);
if( _audiodriver -> getErrorMessage() != "")
if( _audiodriver -> getErrorMessage() != -1)
notifyErrClient( _audiodriver -> getErrorMessage() );
// set config
setConfig( AUDIO , ALSA_PLUGIN , audioPlugin );
......@@ -1321,14 +1320,14 @@ ManagerImpl::getAudioOutputDeviceList(void)
ManagerImpl::setAudioOutputDevice(const int index)
{
_debug("Set audio output device: %i\n", index);
_audiodriver -> setErrorMessage( "" );
_audiodriver -> setErrorMessage( -1 );
_audiodriver->openDevice(_audiodriver->getIndexIn(),
index,
_audiodriver->getSampleRate(),
_audiodriver->getFrameSize(),
SFL_PCM_PLAYBACK,
_audiodriver->getAudioPlugin());
if( _audiodriver -> getErrorMessage() != "")
if( _audiodriver -> getErrorMessage() != -1)
notifyErrClient( _audiodriver -> getErrorMessage() );
// set config
setConfig( AUDIO , ALSA_CARD_ID_OUT , index );
......@@ -1351,14 +1350,14 @@ ManagerImpl::getAudioInputDeviceList(void)
ManagerImpl::setAudioInputDevice(const int index)
{
_debug("Set audio input device %i\n", index);
_audiodriver -> setErrorMessage( "" );
_audiodriver -> setErrorMessage( -1 );
_audiodriver->openDevice(index,
_audiodriver->getIndexOut(),
_audiodriver->getSampleRate(),
_audiodriver->getFrameSize(),
SFL_PCM_CAPTURE,
_audiodriver->getAudioPlugin());
if( _audiodriver -> getErrorMessage() != "")
if( _audiodriver -> getErrorMessage() != -1)
notifyErrClient( _audiodriver -> getErrorMessage() );
// set config
setConfig( AUDIO , ALSA_CARD_ID_IN , index );
......@@ -1431,11 +1430,11 @@ ManagerImpl::setRingtoneChoice( const std::string& tone )
}
void
ManagerImpl::notifyErrClient( const std::string& errMsg )
ManagerImpl::notifyErrClient( const int& errCode )
{
if( _dbus ) {
_debug("Call notifyErrClient: %s\n" , errMsg.c_str());
_dbus -> getConfigurationManager() -> errorAlert( errMsg , 0 );
if( _dbus ){
_debug("NOTIFY ERR NUMBER %i\n" , errCode);
_dbus -> getConfigurationManager() -> errorAlert( errCode );
}
}
......@@ -1466,9 +1465,9 @@ ManagerImpl::initAudioDriver(void)
if (_audiodriver == 0) {
_debug("Init audio driver error\n");
} else {
std::string error = getAudioDriver()->getErrorMessage();
if (!error.empty()) {
_debug("Init audio driver: %s\n", error.c_str());
int error = getAudioDriver()->getErrorMessage();
if (error == -1) {
_debug("Init audio driver: %i\n", error);
}
}
}
......@@ -1502,9 +1501,9 @@ ManagerImpl::selectAudioDriver (void)
}
_debugInit(" AudioLayer Opening Device");
_audiodriver->setErrorMessage("");
_audiodriver->setErrorMessage(-1);
_audiodriver->openDevice( numCardIn , numCardOut, sampleRate, frameSize, SFL_PCM_BOTH, alsaPlugin );
if( _audiodriver -> getErrorMessage() != "")
if( _audiodriver -> getErrorMessage() != -1 )
notifyErrClient( _audiodriver -> getErrorMessage());
}
......@@ -2147,10 +2146,10 @@ ManagerImpl::setSwitch(const std::string& switchName, std::string& message) {
audiolayer = getAudioDriver();
if (audiolayer) {
std::string error = audiolayer->getErrorMessage();
int error = audiolayer->getErrorMessage();
int newSampleRate = audiolayer->getSampleRate();
if (!error.empty()) {
if (error == -1) {
message = error;
return false;
}
......
......@@ -368,7 +368,7 @@ public:
* Notify the client that an error occured
* @param errMsg The error message that should popup on the client side
*/
void notifyErrClient( const std::string& errMsg );
void notifyErrClient( const ::DBus::Int32& errCode );
bool getConfigAll(const std::string& sequenceId);
bool getConfig(const std::string& section, const std::string& name, TokenList& arg);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment