summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Applet/Applet.cpp50
-rw-r--r--src/Applet/CCApplet.cpp53
-rw-r--r--src/Applet/CCApplet.h13
-rw-r--r--src/Applet/Makefile.am4
-rw-r--r--src/Daemon/CrashWatcher.cpp29
-rw-r--r--src/Daemon/CrashWatcher.h7
-rw-r--r--src/Daemon/Makefile.am5
7 files changed, 124 insertions, 37 deletions
diff --git a/src/Applet/Applet.cpp b/src/Applet/Applet.cpp
index 39b0cc41..cc40642e 100644
--- a/src/Applet/Applet.cpp
+++ b/src/Applet/Applet.cpp
@@ -1,40 +1,54 @@
+/*
+ Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ 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; either version 2 of the License, or
+ (at your option) any later version.
+
+ 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, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
#include "CCApplet.h"
-#include "DBusManager.h"
+#include "DBusClient.h"
#include <iostream>
//@@global applet object
CApplet *applet;
static void
-crash_notify_cb(DBusGProxy *proxy, char* progname, gpointer user_data)
+crash_notify_cb(const char* progname)
{
- DBusError error;
- dbus_error_init (&error);
#ifdef DEBUG
std::cerr << "Application " << progname << " has crashed!" << std::endl;
#endif
/* smth happend, show the blinking icon */
applet->BlinkIcon(true);
applet->ShowIcon();
+ //applet->AddEvent(uid, std::string(progname));
+ applet->SetIconTooltip("A crash in package %s has been detected!", progname);
}
int main(int argc, char **argv)
{
Gtk::Main kit(argc, argv);
applet = new CApplet();
- CDBusManager dm;
- /* connect to the daemon */
- try
- {
- dm.ConnectToDaemon();
- }
- catch(std::string err)
- {
- std::cerr << "Applet: " << err << std::endl;
- return -1;
- }
- /* catch the CC crash notify on the dbus */
- dm.RegisterToMessage("Crash",G_CALLBACK(crash_notify_cb),NULL,NULL);
- /* run the main loop and wait for some events */
+ /* move to the DBusClient::connect */
+ DBus::Glib::BusDispatcher dispatcher;
+ /* this should bind the dispatcher with mainloop */
+ dispatcher.attach(NULL);
+ DBus::default_dispatcher = &dispatcher;
+
+ DBus::Connection conn = DBus::Connection::SystemBus();
+ CDBusClient client(conn, CC_DBUS_PATH, CC_DBUS_NAME);
+ client.ConnectCrashHandler(crash_notify_cb);
Gtk::Main::run();
return 0;
}
diff --git a/src/Applet/CCApplet.cpp b/src/Applet/CCApplet.cpp
index fd9741ae..17ff6f92 100644
--- a/src/Applet/CCApplet.cpp
+++ b/src/Applet/CCApplet.cpp
@@ -19,33 +19,66 @@
#include "CCApplet.h"
#include <iostream>
+#include <cstdarg>
+#include <sstream>
CApplet::CApplet()
{
-
m_nStatusIcon = Gtk::StatusIcon::create(Gtk::Stock::DIALOG_WARNING);
m_nStatusIcon->set_visible(false);
- // LTM click
+ // LMB click
m_nStatusIcon->signal_activate().connect(sigc::mem_fun(*this, &CApplet::OnAppletActivate_CB));
- SetIconToolip("Pending events:");
+ m_nStatusIcon->signal_popup_menu().connect(sigc::mem_fun(*this, &CApplet::OnMenuPopup_cb));
+ SetIconTooltip("Pending events: %i",m_mapEvents.size());
+
}
CApplet::~CApplet()
{
}
-void CApplet::SetIconToolip(const Glib::ustring& tip)
+void CApplet::SetIconTooltip(const char *format, ...)
{
- m_nStatusIcon->set_tooltip(tip);
+ va_list args;
+ // change to smth sane like MAX_TOOLTIP length or rewrite this whole sh*t
+ size_t n,size = 10;
+ char *buf = new char[size];
+ va_start (args, format);
+ while((n = vsnprintf (buf, size, format, args)) > size)
+ {
+ // string was larger than our buffer
+ // alloc larger buffer
+ size = n+1;
+ delete[] buf;
+ buf = new char[size];
+ }
+ va_end (args);
+ if (n != -1)
+ {
+ m_nStatusIcon->set_tooltip(Glib::ustring((const char*)buf));
+ }
+ else
+ {
+ m_nStatusIcon->set_tooltip("Error while setting tooltip!");
+ }
+ delete[] buf;
}
void CApplet::OnAppletActivate_CB()
{
m_nStatusIcon->set_visible(false);
//std::cout << "Activate" << std::endl;
+ //if(m_pMenuPopup)
+ //m_pMenuPopup->show();
}
+void CApplet::OnMenuPopup_cb(guint button, guint32 activate_time)
+{
+ /* for now just hide the icon on RMB */
+ m_nStatusIcon->set_blinking(false);
+}
+
void CApplet::ShowIcon()
{
m_nStatusIcon->set_visible(true);
@@ -56,6 +89,16 @@ void CApplet::HideIcon()
m_nStatusIcon->set_visible(false);
}
+int CApplet::AddEvent(int pUUID, const std::string& pProgname)
+{
+ m_mapEvents[pUUID] = "pProgname";
+ SetIconTooltip("Pending events: %i",m_mapEvents.size());
+}
+
+int CApplet::RemoveEvent(int pUUID)
+{
+ m_mapEvents.erase(pUUID);
+}
void CApplet::BlinkIcon(bool pBlink)
{
m_nStatusIcon->set_blinking(pBlink);
diff --git a/src/Applet/CCApplet.h b/src/Applet/CCApplet.h
index 428f4a9c..86c00efb 100644
--- a/src/Applet/CCApplet.h
+++ b/src/Applet/CCApplet.h
@@ -26,7 +26,7 @@ class CApplet
{
private:
Glib::RefPtr<Gtk::StatusIcon> m_nStatusIcon;
- int m_iPendingEvents;
+ std::map<int, std::string > m_mapEvents;
public:
CApplet();
~CApplet();
@@ -34,9 +34,18 @@ class CApplet
void HideIcon();
//void DisableIcon();
void BlinkIcon(bool pBlink);
- void SetIconToolip(const Glib::ustring& tip);
+ void SetIconTooltip(const char *format, ...);
+ // create some event storage, to let user choose
+ // or ask the daemon every time?
+ // maybe just events which occured during current session
+ // map::
+ int AddEvent(int pUUID, const std::string& pProgname);
+ int RemoveEvent(int pUUID);
protected:
+ //@@TODO applet menus
void OnAppletActivate_CB();
+ void OnMenuPopup_cb(guint button, guint32 activate_time);
+ //menu
Glib::RefPtr<Gtk::UIManager> m_refUIManager;
Glib::RefPtr<Gtk::ActionGroup> m_refActionGroup;
Gtk::Menu* m_pMenuPopup;
diff --git a/src/Applet/Makefile.am b/src/Applet/Makefile.am
index 8500b011..e329accb 100644
--- a/src/Applet/Makefile.am
+++ b/src/Applet/Makefile.am
@@ -2,5 +2,7 @@ bin_PROGRAMS = applet
applet_SOURCES = Applet.cpp CCApplet.cpp CCApplet.h
applet_CPPFLAGS = -I../../lib/DBus \
-DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \
- $(DBUS_GLIB_CFLAGS) $(GTKMM_CFLAGS)
+ $(DBUS_GLIB_CFLAGS) $(GTKMM_CFLAGS) $(DBUSCPP_CFLAGS) \
+ -I../../lib/MiddleWare
+
applet_LDADD = ../../lib/DBus/libDBus.la $(DL_LIBS) $(GTKMM_LIBS)
diff --git a/src/Daemon/CrashWatcher.cpp b/src/Daemon/CrashWatcher.cpp
index 2155b2b7..1474b2f6 100644
--- a/src/Daemon/CrashWatcher.cpp
+++ b/src/Daemon/CrashWatcher.cpp
@@ -36,7 +36,7 @@ void terminate(int signal)
gboolean CCrashWatcher::handle_event_cb(GIOChannel *gio, GIOCondition condition, gpointer daemon){
GIOError err;
char buf[INOTIFY_BUFF_SIZE];
- guint len;
+ gsize len;
int i = 0;
err = g_io_channel_read (gio, buf, INOTIFY_BUFF_SIZE, &len);
if (err != G_IO_ERROR_NONE) {
@@ -55,9 +55,14 @@ gboolean CCrashWatcher::handle_event_cb(GIOChannel *gio, GIOCondition condition,
#ifdef DEBUG
std::cout << "Created file: " << name << std::endl;
#endif /*DEBUG*/
- /* send message to dbus */
+
CCrashWatcher *cc = (CCrashWatcher*)daemon;
- cc->m_nDbus_manager.SendMessage("Crash", name);
+ CMiddleWare::crash_info_t crashinfo;
+ if(cc->m_pMW->SaveDebugDump(std::string(DEBUG_DUMPS_DIR) + "/" + name, crashinfo))
+ {
+ /* send message to dbus */
+ cc->m_pDbusServer->Crash(crashinfo.m_sPackage);
+ }
}
return TRUE;
}
@@ -66,9 +71,18 @@ CCrashWatcher::CCrashWatcher(const std::string& pPath)
{
int watch = 0;
m_sTarget = pPath;
+ // middleware object
+ m_pMW = new CMiddleWare(PLUGINS_CONF_DIR,PLUGINS_LIB_DIR, std::string(CONF_DIR) + "/CrashCatcher.conf");
m_nMainloop = g_main_loop_new(NULL,FALSE);
/* register on dbus */
- m_nDbus_manager.RegisterService();
+ DBus::Glib::BusDispatcher *dispatcher;
+ dispatcher = new DBus::Glib::BusDispatcher();
+ dispatcher->attach(NULL);
+ DBus::default_dispatcher = dispatcher;
+ DBus::Connection conn = DBus::Connection::SystemBus();
+
+ m_pDbusServer = new CDBusServer(conn,CC_DBUS_PATH);
+ conn.request_name(CC_DBUS_NAME);
if((m_nFd = inotify_init()) == -1){
throw std::string("Init Failed");
//std::cerr << "Init Failed" << std::endl;
@@ -76,23 +90,22 @@ CCrashWatcher::CCrashWatcher(const std::string& pPath)
}
if((watch = inotify_add_watch(m_nFd, pPath.c_str(), IN_CREATE)) == -1){
throw std::string("Add watch failed");
- //std::cerr << "Add watch failed: " << pPath << std::endl;
- exit(-1);
}
m_nGio = g_io_channel_unix_new(m_nFd);
}
CCrashWatcher::~CCrashWatcher()
{
+ //delete dispatcher, connection, etc..
}
void CCrashWatcher::Lock()
{
int lfp = open("crashcatcher.lock",O_RDWR|O_CREAT,0640);
if (lfp < 0)
- throw "CCrashWatcher.cpp:can not open lock file";
+ throw std::string("CCrashWatcher.cpp:can not open lock file");
if (lockf(lfp,F_TLOCK,0) < 0)
- throw "CCrashWatcher.cpp:Lock:cannot create lock on lockfile";
+ throw std::string("CCrashWatcher.cpp:Lock:cannot create lock on lockfile");
/* only first instance continues */
//sprintf(str,"%d\n",getpid());
//write(lfp,str,strlen(str)); /* record pid to lockfile */
diff --git a/src/Daemon/CrashWatcher.h b/src/Daemon/CrashWatcher.h
index 1d092cb2..92ef27f9 100644
--- a/src/Daemon/CrashWatcher.h
+++ b/src/Daemon/CrashWatcher.h
@@ -24,7 +24,8 @@
#include <sys/inotify.h>
#include <sys/inotify.h>
#include <glib.h>
-#include "DBusManager.h"
+//#include "DBusManager.h"
+#include "DBusServer.h"
#include "MiddleWare.h"
// 1024 simultaneous actions
@@ -40,11 +41,13 @@ class CCrashWatcher
void GStartWatch();
void Lock();
- CDBusManager m_nDbus_manager;
+ //CDBusManager m_nDbus_manager;
+ CDBusServer *m_pDbusServer;
int m_nFd;
GIOChannel* m_nGio;
GMainLoop *m_nMainloop;
std::string m_sTarget;
+ CMiddleWare *m_pMW;
public:
CCrashWatcher(const std::string& pPath);
//CCrashWatcher();
diff --git a/src/Daemon/Makefile.am b/src/Daemon/Makefile.am
index 32dbab0b..c562bb09 100644
--- a/src/Daemon/Makefile.am
+++ b/src/Daemon/Makefile.am
@@ -2,5 +2,8 @@ bin_PROGRAMS = CrashCatcher
CrashCatcher_SOURCES = CrashWatcher.cpp CrashWatcher.h Daemon.cpp
CrashCatcher_CPPFLAGS = -I../../lib/MiddleWare\
-I../../lib/DBus \
- -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" $(DBUS_GLIB_CFLAGS)
+ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" $(DBUS_GLIB_CFLAGS) $(DBUSCPP_CFLAGS) \
+ -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \
+ -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \
+ -DCONF_DIR=\"$(CONF_DIR)\"
CrashCatcher_LDADD = ../../lib/MiddleWare/libMiddleWare.la ../../lib/DBus/libDBus.la $(DL_LIBS)