diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-08 17:05:57 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-08 17:05:57 +0200 |
commit | ff2627e7c597e50025ca4d91ff8168eec80f9054 (patch) | |
tree | ab3d97087d70ee23c5af0d6d52cbb97660c6e3e6 /lib | |
parent | 8198cd06195f4217fd6b1afb675f3a316c951a1e (diff) | |
download | abrt-ff2627e7c597e50025ca4d91ff8168eec80f9054.tar.gz abrt-ff2627e7c597e50025ca4d91ff8168eec80f9054.tar.xz abrt-ff2627e7c597e50025ca4d91ff8168eec80f9054.zip |
make Warning, Error and Update send unicast dbus messages
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CommLayer/CommLayerInner.cpp | 71 | ||||
-rw-r--r-- | lib/CommLayer/CommLayerInner.h | 4 | ||||
-rw-r--r-- | lib/CommLayer/Observer.h | 4 |
3 files changed, 48 insertions, 31 deletions
diff --git a/lib/CommLayer/CommLayerInner.cpp b/lib/CommLayer/CommLayerInner.cpp index ec4dc904..5450b41c 100644 --- a/lib/CommLayer/CommLayerInner.cpp +++ b/lib/CommLayer/CommLayerInner.cpp @@ -1,50 +1,63 @@ -#include <pthread.h> /* pthread_self() */ +#include <pthread.h> +#include <map> #include "abrtlib.h" #include "CommLayerInner.h" static CObserver *s_pObs; -static pthread_t s_main_id; + +typedef std::map<uint64_t, std::string> map_uint_str_t; +static map_uint_str_t s_mapClientID; +static pthread_mutex_t s_map_mutex; +static bool s_map_mutex_inited; void init_daemon_logging(CObserver *pObs) { s_pObs = pObs; - s_main_id = pthread_self(); + if (!s_map_mutex_inited) + { + pthread_mutex_init(&s_map_mutex, NULL); + s_map_mutex_inited = true; + } +} + +void set_client_name(const char* name) +{ + uint64_t key = uint64_t(pthread_self()); + + pthread_mutex_lock(&s_map_mutex); + if (!name) + s_mapClientID.erase(key); + else + s_mapClientID[key] = name; + pthread_mutex_unlock(&s_map_mutex); } void warn_client(const std::string& pMessage) { if (!s_pObs) return; - pthread_t self = pthread_self(); - if (self != s_main_id) - { - s_pObs->Warning(pMessage,(uint64_t)self); -//log("w: '%s'", s.c_str()); - } - else - { - s_pObs->Warning(pMessage); -// debug: this should not happen - if it is, we are trying to log to a client -// but we have no job id! -log("W: '%s'", pMessage.c_str()); - } + + uint64_t key = uint64_t(pthread_self()); + + pthread_mutex_lock(&s_map_mutex); + map_uint_str_t::const_iterator ki = s_mapClientID.find(key); + const char* peer = (ki != s_mapClientID.end() ? ki->second.c_str() : NULL); + pthread_mutex_unlock(&s_map_mutex); + + s_pObs->Warning(pMessage, peer, key); } void update_client(const std::string& pMessage) { if (!s_pObs) return; - pthread_t self = pthread_self(); - if (self != s_main_id) - { - s_pObs->Status(pMessage, (uint64_t)self); -//log("u: '%s'", s.c_str()); - } - else - { - s_pObs->Status(pMessage); -// debug: this should not happen - if it is, we are trying to log to a client -// but we have no job id! -log("U: '%s'", pMessage.c_str()); - } + + uint64_t key = uint64_t(pthread_self()); + + pthread_mutex_lock(&s_map_mutex); + map_uint_str_t::const_iterator ki = s_mapClientID.find(key); + const char* peer = (ki != s_mapClientID.end() ? ki->second.c_str() : NULL); + pthread_mutex_unlock(&s_map_mutex); + + s_pObs->Status(pMessage, peer, key); } diff --git a/lib/CommLayer/CommLayerInner.h b/lib/CommLayer/CommLayerInner.h index 2b4f63a3..d161cfc7 100644 --- a/lib/CommLayer/CommLayerInner.h +++ b/lib/CommLayer/CommLayerInner.h @@ -5,6 +5,10 @@ void init_daemon_logging(CObserver *pObs); +/* + * Set client's name (dbus ID). NULL unsets it. + */ +void set_client_name(const char* name); /* Ask a client to warn the user about a non-fatal, but unexpected condition. * In GUI, it will usually be presented as a popup message. */ diff --git a/lib/CommLayer/Observer.h b/lib/CommLayer/Observer.h index 5c983949..421dc0cc 100644 --- a/lib/CommLayer/Observer.h +++ b/lib/CommLayer/Observer.h @@ -9,8 +9,8 @@ class CObserver { public: virtual ~CObserver() {} - virtual void Status(const std::string& pMessage, uint64_t pDest=0) = 0; - virtual void Warning(const std::string& pMessage, uint64_t pDest=0) = 0; + virtual void Status(const std::string& pMessage, const char* peer, uint64_t pDest) = 0; + virtual void Warning(const std::string& pMessage, const char* peer, uint64_t pDest) = 0; }; #endif |