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