summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJiri Moskovcak <jmoskovc@redhat.com>2009-07-20 17:01:01 +0200
committerJiri Moskovcak <jmoskovc@redhat.com>2009-07-20 17:01:01 +0200
commitc581668d59fc839f42a9e42ff4b371b02789aaa3 (patch)
tree7191f4085b1763b01dd4f813caedd93bae157ba8 /src
parentede175cb92ada7e1235b9b1ee8777d7d1ad32613 (diff)
downloadabrt-c581668d59fc839f42a9e42ff4b371b02789aaa3.tar.gz
abrt-c581668d59fc839f42a9e42ff4b371b02789aaa3.tar.xz
abrt-c581668d59fc839f42a9e42ff4b371b02789aaa3.zip
Daemon: added threaded CreateReport -> breaks CLI!
Diffstat (limited to 'src')
-rw-r--r--src/Daemon/CrashWatcher.cpp109
-rw-r--r--src/Daemon/CrashWatcher.h18
-rw-r--r--src/Gui/CCDBusBackend.py37
-rw-r--r--src/Gui/CCMainWindow.py15
-rw-r--r--src/Gui/ccgui.glade64
5 files changed, 175 insertions, 68 deletions
diff --git a/src/Daemon/CrashWatcher.cpp b/src/Daemon/CrashWatcher.cpp
index 9a14967..1a87f8d 100644
--- a/src/Daemon/CrashWatcher.cpp
+++ b/src/Daemon/CrashWatcher.cpp
@@ -133,6 +133,60 @@ gboolean CCrashWatcher::handle_event_cb(GIOChannel *gio, GIOCondition condition,
return TRUE;
}
+void *CCrashWatcher::CreateReport_t(void *arg){
+ thread_data_t *thread_data = (thread_data_t *) arg;
+ map_crash_info_t crashReport;
+ thread_data->daemon->Debug("Creating report...");
+ try
+ {
+ CMiddleWare::mw_result_t res;
+ res = thread_data->daemon->m_pMW->CreateCrashReport(thread_data->UUID,thread_data->UID,crashReport);
+ switch (res)
+ {
+ case CMiddleWare::MW_OK:
+ break;
+ case CMiddleWare::MW_IN_DB_ERROR:
+ thread_data->daemon->Warning(std::string("Did not find crash with UUID ")+thread_data->UUID+ " in database.");
+ thread_data->daemon->Status(std::string("Did not find crash with UUID ")+thread_data->UUID+" in database.");
+ break;
+ case CMiddleWare::MW_CORRUPTED:
+ case CMiddleWare::MW_FILE_ERROR:
+ default:
+ {
+ std::string debugDumpDir;
+ thread_data->daemon->Warning(std::string("Corrupted crash with UUID ")+thread_data->UUID+", deleting.");
+ thread_data->daemon->Status(std::string("Corrupted crash with UUID ")+thread_data->UUID+", deleting.");
+ debugDumpDir = thread_data->daemon->m_pMW->DeleteCrashInfo(thread_data->UUID, thread_data->UID);
+ thread_data->daemon->m_pMW->DeleteDebugDumpDir(debugDumpDir);
+ }
+ break;
+ }
+ thread_data->daemon->pending_jobs[thread_data->thread_id] = crashReport;
+ thread_data->daemon->m_pCommLayer->JobDone(thread_data->thread_id);
+ }
+ catch (CABRTException& e)
+ {
+ if (e.type() == EXCEP_FATAL)
+ {
+ /* free strduped strings */
+ free(thread_data->UUID);
+ free(thread_data->UID);
+ free(thread_data);
+ throw e;
+ }
+ /* free strduped strings */
+ free(thread_data->UUID);
+ free(thread_data->UID);
+ free(thread_data);
+ thread_data->daemon->Warning(e.what());
+ thread_data->daemon->Status(e.what());
+ }
+ /* free strduped strings */
+ free(thread_data->UUID);
+ free(thread_data->UID);
+ free(thread_data);
+}
+
gboolean CCrashWatcher::cron_activation_periodic_cb(gpointer data)
{
cron_callback_data_t* cronPeriodicCallbackData = static_cast<cron_callback_data_t*>(data);
@@ -320,6 +374,9 @@ void CCrashWatcher::SetUpCron()
void CCrashWatcher::Status(const std::string& pMessage)
{
std::cout << "Update: " + pMessage << std::endl;
+ //FIXME: add some ID
+ if(m_pCommLayer != NULL)
+ m_pCommLayer->Update("0",pMessage);
}
void CCrashWatcher::Warning(const std::string& pMessage)
@@ -372,6 +429,7 @@ CCrashWatcher::CCrashWatcher(const std::string& pPath)
// TODO: initialize object according parameters -w -d
// status has to be always created.
+ m_pCommLayer = NULL;
m_pCommLayerInner = new CCommLayerInner(this, true, true);
comm_layer_inner_init(m_pCommLayerInner);
@@ -634,46 +692,14 @@ vector_crash_infos_t CCrashWatcher::GetCrashInfos(const std::string &pUID)
return retval;
}
-map_crash_report_t CCrashWatcher::CreateReport(const std::string &pUUID,const std::string &pUID)
+uint64_t CCrashWatcher::CreateReport_t(const std::string &pUUID,const std::string &pUID)
{
- map_crash_report_t crashReport;
- Debug("Creating report...");
- try
- {
- CMiddleWare::mw_result_t res;
- res = m_pMW->CreateCrashReport(pUUID,pUID,crashReport);
- switch (res)
- {
- case CMiddleWare::MW_OK:
- break;
- case CMiddleWare::MW_IN_DB_ERROR:
- Warning("Did not find crash with UUID "+pUUID+" in database.");
- Status("Did not find crash with UUID "+pUUID+" in database.");
- break;
- case CMiddleWare::MW_CORRUPTED:
- case CMiddleWare::MW_FILE_ERROR:
- default:
- {
- std::string debugDumpDir;
- Warning("Corrupted crash with UUID "+pUUID+", deleting.");
- Status("Corrupted crash with UUID "+pUUID+", deleting.");
- debugDumpDir = m_pMW->DeleteCrashInfo(pUUID, pUID);
- m_pMW->DeleteDebugDumpDir(debugDumpDir);
- }
- break;
- }
- m_pCommLayer->AnalyzeComplete(crashReport);
- }
- catch (CABRTException& e)
- {
- if (e.type() == EXCEP_FATAL)
- {
- throw e;
- }
- Warning(e.what());
- Status(e.what());
- }
- return crashReport;
+ thread_data_t * thread_data = (thread_data_t *)calloc(1, sizeof(thread_data_t));
+ thread_data->UUID = strdup(pUUID.c_str());
+ thread_data->UID = strdup(pUID.c_str());
+ thread_data->daemon = this;
+ pthread_create(&(thread_data->thread_id), NULL, CreateReport_t, (void *)thread_data);
+ return (uint64_t) thread_data->thread_id;
}
bool CCrashWatcher::Report(map_crash_report_t pReport, const std::string& pUID)
@@ -739,3 +765,8 @@ bool CCrashWatcher::DeleteDebugDump(const std::string& pUUID, const std::string&
}
return true;
}
+
+map_crash_report_t CCrashWatcher::GetJobResult(uint64_t pJobID, const std::string& pDBusSender)
+{
+ return pending_jobs[pJobID];
+}
diff --git a/src/Daemon/CrashWatcher.h b/src/Daemon/CrashWatcher.h
index e512478..23322d8 100644
--- a/src/Daemon/CrashWatcher.h
+++ b/src/Daemon/CrashWatcher.h
@@ -24,6 +24,7 @@
#include <sys/inotify.h>
#include <sys/inotify.h>
#include <glib.h>
+#include <pthread.h>
//#include "DBusManager.h"
//#include "DBusServerProxy.h"
#include "MiddleWare.h"
@@ -49,7 +50,7 @@ class CCrashWatcher
: public CObserver
{
private:
-
+ //FIXME: add some struct to be able to join all threads!
typedef struct SCronCallbackData
{
CCrashWatcher* m_pCrashWatcher;
@@ -68,8 +69,18 @@ class CCrashWatcher
{}
} cron_callback_data_t;
+
+ typedef struct SThreadData{
+ pthread_t thread_id;
+ char* UUID;
+ char* UID;
+ CCrashWatcher *daemon;
+ } thread_data_t;
+
+ std::map <int, map_crash_report_t> pending_jobs;
static gboolean handle_event_cb(GIOChannel *gio, GIOCondition condition, gpointer data);
+ static void *CreateReport_t(void *arg);
static gboolean cron_activation_periodic_cb(gpointer data);
static gboolean cron_activation_one_cb(gpointer data);
static gboolean cron_activation_reshedule_cb(gpointer data);
@@ -105,9 +116,12 @@ class CCrashWatcher
/* methods exported on dbus */
public:
virtual vector_crash_infos_t GetCrashInfos(const std::string &pUID);
- virtual map_crash_report_t CreateReport(const std::string &pUUID,const std::string &pUID);
+ /*FIXME: fix CLI and remove this stub*/
+ virtual map_crash_report_t CreateReport(const std::string &pUUID,const std::string &pUID){map_crash_report_t retval; return retval;};
+ uint64_t CreateReport_t(const std::string &pUUID,const std::string &pUID);
virtual bool Report(map_crash_report_t pReport, const std::string &pUID);
virtual bool DeleteDebugDump(const std::string& pUUID, const std::string& pUID);
+ virtual map_crash_report_t GetJobResult(uint64_t pJobID, const std::string& pDBusSender);
/* Observer methods */
void Status(const std::string& pMessage);
diff --git a/src/Gui/CCDBusBackend.py b/src/Gui/CCDBusBackend.py
index 12326c7..21d2425 100644
--- a/src/Gui/CCDBusBackend.py
+++ b/src/Gui/CCDBusBackend.py
@@ -13,6 +13,8 @@ APP_NAME = 'com.redhat.abrt.gui'
class DBusManager(gobject.GObject):
""" Class to provide communication with daemon over dbus """
# and later with policyKit
+ uniq_name = None
+ pending_jobs = []
def __init__(self):
session = None
try:
@@ -23,7 +25,7 @@ class DBusManager(gobject.GObject):
if session:
if session.request_name(APP_NAME, dbus.bus.NAME_FLAG_DO_NOT_QUEUE) != dbus.bus.REQUEST_NAME_REPLY_PRIMARY_OWNER:
raise Exception("Name %s is taken,\nanother instance is already running." % APP_NAME)
-
+
gobject.GObject.__init__(self)
# signal emited when new crash is detected
gobject.signal_new ("crash", self ,gobject.SIGNAL_RUN_FIRST,gobject.TYPE_NONE,())
@@ -31,6 +33,8 @@ class DBusManager(gobject.GObject):
gobject.signal_new ("analyze-complete", self ,gobject.SIGNAL_RUN_FIRST,gobject.TYPE_NONE,(gobject.TYPE_PYOBJECT,))
# signal emited when smth fails
gobject.signal_new ("error", self ,gobject.SIGNAL_RUN_FIRST,gobject.TYPE_NONE,(gobject.TYPE_PYOBJECT,))
+ # signal emited to update gui with current status
+ gobject.signal_new ("update", self ,gobject.SIGNAL_RUN_FIRST,gobject.TYPE_NONE,(gobject.TYPE_PYOBJECT,))
# binds the dbus to glib mainloop
DBusGMainLoop(set_as_default=True)
self.proxy = None
@@ -44,6 +48,10 @@ class DBusManager(gobject.GObject):
self.acconnection = self.proxy.connect_to_signal("AnalyzeComplete",self.analyze_complete_cb,dbus_interface=CC_IFACE)
# Catch Errors
self.acconnection = self.proxy.connect_to_signal("Error",self.error_handler_cb,dbus_interface=CC_IFACE)
+ # watch for updates
+ self.acconnection = self.proxy.connect_to_signal("Update",self.update_cb,dbus_interface=CC_IFACE)
+ # watch for job-done signals
+ self.acconnection = self.proxy.connect_to_signal("JobDone",self.jobdone_cb,dbus_interface=CC_IFACE)
else:
raise Exception("Please check if abrt daemon is running.")
@@ -69,16 +77,23 @@ class DBusManager(gobject.GObject):
#emit a signal
#print "crash"
self.emit("crash")
+
+ def update_cb(self, dest, message):
+ # FIXME: use dest instead of 0 once we implement it in daemon
+ #if self.uniq_name == dest:
+ self.emit("update", message)
def analyze_complete_cb(self,dump):
#for arg in args:
# print "Analyze complete for: %s" % arg
# emit signal to let clients know that analyze has been completed
# FIXME - rewrite with CCReport class
- self.emit("analyze-complete", dump)
-
+ # self.emit("analyze-complete", dump)
+ pass
+
def connect_to_daemon(self):
bus = dbus.SystemBus()
+ self.uniq_name = bus.get_unique_name()
if not bus:
raise Exception("Can't connect to dbus")
try:
@@ -88,11 +103,25 @@ class DBusManager(gobject.GObject):
except Exception, e:
raise Exception(e.message + "\nCannot create a proxy object!")
+ def addJob(self, job_id):
+ self.pending_jobs.append(job_id)
+
+ def jobdone_cb(self, job_id):
+ #if self.uniq_name == client_id:
+ try:
+ self.pending_jobs.index(job_id)
+ except:
+ return
+ dump = self.cc.GetJobResult(job_id)
+ if dump:
+ self.emit("analyze-complete", dump)
+
def getReport(self, UUID):
try:
# let's try it async
# even if it's async it timeouts, so let's try to set the timeout to 60sec
- self.cc.CreateReport(UUID, reply_handler=self.dummy, error_handler=self.error_handler, timeout=60)
+ #self.cc.CreateReport(UUID, reply_handler=self.addJob, error_handler=self.error_handler, timeout=60)
+ self.addJob(self.cc.CreateReport(UUID, timeout=60))
except dbus.exceptions.DBusException, e:
raise Exception(e.message)
diff --git a/src/Gui/CCMainWindow.py b/src/Gui/CCMainWindow.py
index 5a92b9f..6e378fc 100644
--- a/src/Gui/CCMainWindow.py
+++ b/src/Gui/CCMainWindow.py
@@ -93,6 +93,7 @@ class MainWindow():
self.ccdaemon.connect("crash", self.on_data_changed_cb, None)
self.ccdaemon.connect("analyze-complete", self.on_analyze_complete_cb, self.pBarWindow)
self.ccdaemon.connect("error", self.error_cb)
+ self.ccdaemon.connect("update", self.update_cb)
# load data
#self.load()
@@ -110,12 +111,15 @@ class MainWindow():
except Exception, e:
pass
gui_error_message("Unable to get report!\n%s" % message)
+
+ def update_cb(self, daemon, message):
+ self.wTree.get_widget("lStatus").set_text(message)
# call to update the progressbar
def progress_update_cb(self, *args):
self.pBar.pulse()
return True
-
+
def hydrate(self):
n = None
self.dumpsListStore.clear()
@@ -185,7 +189,10 @@ class MainWindow():
self.dlist.set_cursor(path[0])
def on_analyze_complete_cb(self, daemon, report, pBarWindow):
- gobject.source_remove(self.timer)
+ try:
+ gobject.source_remove(self.timer)
+ except:
+ pass
self.pBarWindow.hide()
#FIXME - why we need this?? -> timeout warnings
# try:
@@ -213,8 +220,8 @@ class MainWindow():
if not path:
return
self.update_pBar = False
- self.pBar.show()
- self.pBarWindow.show()
+ #self.pBar.show()
+ self.pBarWindow.show_all()
self.timer = gobject.timeout_add (100,self.progress_update_cb)
dump = dumpsListStore.get_value(dumpsListStore.get_iter(path[0]), dumpsListStore.get_n_columns()-1)
diff --git a/src/Gui/ccgui.glade b/src/Gui/ccgui.glade
index 56ab653..53da45b 100644
--- a/src/Gui/ccgui.glade
+++ b/src/Gui/ccgui.glade
@@ -1,10 +1,10 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.5 on Fri Mar 13 14:32:54 2009 -->
+<?xml version="1.0"?>
<glade-interface>
+ <!-- interface-requires gtk+ 2.16 -->
+ <!-- interface-naming-policy toplevel-contextual -->
<widget class="GtkWindow" id="main_window2">
<property name="title" translatable="yes">Automatic Bug Reporting Tool</property>
- <property name="window_position">GTK_WIN_POS_CENTER</property>
+ <property name="window_position">center</property>
<child>
<widget class="GtkVBox" id="vbox4">
<property name="visible">True</property>
@@ -21,8 +21,8 @@
<property name="visible">True</property>
<child>
<widget class="GtkImageMenuItem" id="miQuit">
+ <property name="label">gtk-quit</property>
<property name="visible">True</property>
- <property name="label" translatable="yes">gtk-quit</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</widget>
@@ -41,8 +41,8 @@
<property name="visible">True</property>
<child>
<widget class="GtkImageMenuItem" id="miAbout">
+ <property name="label">gtk-about</property>
<property name="visible">True</property>
- <property name="label" translatable="yes">gtk-about</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</widget>
@@ -54,6 +54,7 @@
</widget>
<packing>
<property name="expand">False</property>
+ <property name="position">0</property>
</packing>
</child>
<child>
@@ -67,6 +68,7 @@
<property name="stock_id">gtk-delete</property>
</widget>
<packing>
+ <property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
@@ -78,6 +80,7 @@
<property name="stock_id">gtk-save</property>
</widget>
<packing>
+ <property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
@@ -86,6 +89,7 @@
<property name="visible">True</property>
</widget>
<packing>
+ <property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
@@ -99,8 +103,8 @@
<widget class="GtkScrolledWindow" id="swDumps">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
- <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+ <property name="hscrollbar_policy">automatic</property>
+ <property name="vscrollbar_policy">automatic</property>
<child>
<widget class="GtkTreeView" id="tvDumps">
<property name="visible">True</property>
@@ -133,18 +137,18 @@
<widget class="GtkScrolledWindow" id="swDesscription">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
- <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+ <property name="hscrollbar_policy">automatic</property>
+ <property name="vscrollbar_policy">automatic</property>
<child>
<widget class="GtkViewport" id="vDescription">
<property name="visible">True</property>
- <property name="resize_mode">GTK_RESIZE_QUEUE</property>
+ <property name="resize_mode">queue</property>
<child>
<widget class="GtkLabel" id="lDescription">
<property name="visible">True</property>
<property name="xalign">0.10000000149011612</property>
<property name="yalign">0.20000000298023224</property>
- <property name="justify">GTK_JUSTIFY_FILL</property>
+ <property name="justify">fill</property>
<property name="selectable">True</property>
</widget>
</child>
@@ -171,7 +175,7 @@
<widget class="GtkWindow" id="pBarWindow">
<property name="title" translatable="yes">Please wait..</property>
<property name="modal">True</property>
- <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
+ <property name="window_position">center-on-parent</property>
<property name="default_width">270</property>
<child>
<widget class="GtkVBox" id="vbox1">
@@ -183,6 +187,7 @@
</widget>
<packing>
<property name="expand">False</property>
+ <property name="position">0</property>
</packing>
</child>
<child>
@@ -195,12 +200,32 @@
</packing>
</child>
<child>
- <widget class="GtkStatusbar" id="statusbar2">
+ <widget class="GtkHBox" id="hbox1">
<property name="visible">True</property>
- <property name="spacing">2</property>
+ <child>
+ <widget class="GtkArrow" id="arrow1">
+ <property name="visible">True</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="lStatus">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes"> </property>
+ </widget>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
+ <property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
@@ -211,8 +236,8 @@
<property name="border_width">5</property>
<property name="title" translatable="yes">About ABRT</property>
<property name="resizable">False</property>
- <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
- <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+ <property name="window_position">center-on-parent</property>
+ <property name="type_hint">dialog</property>
<property name="has_separator">False</property>
<property name="program_name">ABRT</property>
<property name="copyright" translatable="yes">(C) 2009 Red Hat, Inc.</property>
@@ -235,11 +260,12 @@ Zdenek Prikryl &lt;zprikryl@redhat.com&gt;</property>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area3">
<property name="visible">True</property>
- <property name="layout_style">GTK_BUTTONBOX_END</property>
+ <property name="layout_style">end</property>
</widget>
<packing>
<property name="expand">False</property>
- <property name="pack_type">GTK_PACK_END</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
</packing>
</child>
</widget>