PageRenderTime 272ms CodeModel.GetById 121ms app.highlight 10ms RepoModel.GetById 81ms app.codeStats 0ms

/indra/linux_crash_logger/llcrashloggerlinux.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 145 lines | 99 code | 20 blank | 26 comment | 10 complexity | c91803c43c5ddcc13d6f846e1e8d0454 MD5 | raw file
  1/** 
  2 * @file llcrashloggerlinux.cpp
  3 * @brief Linux crash logger implementation
  4 *
  5 * $LicenseInfo:firstyear=2003&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llcrashloggerlinux.h"
 28
 29#include <iostream>
 30
 31#include "linden_common.h"
 32
 33#include "indra_constants.h"	// CRASH_BEHAVIOR_ASK, CRASH_SETTING_NAME
 34#include "llerror.h"
 35#include "llfile.h"
 36#include "lltimer.h"
 37#include "llstring.h"
 38#include "lldir.h"
 39#include "llsdserialize.h"
 40
 41#if LL_GTK
 42# include "gtk/gtk.h"
 43#endif // LL_GTK
 44
 45#define MAX_LOADSTRING 100
 46
 47// These need to be localized.
 48static const char dialog_text[] =
 49"Second Life appears to have crashed or frozen last time it ran.\n"
 50"This crash reporter collects information about your computer's hardware, operating system, and some Second Life logs, all of which are used for debugging purposes only.\n"
 51"\n"
 52"Send crash report?";
 53
 54static const char dialog_title[] =
 55"Second Life Crash Logger";
 56
 57#if LL_GTK
 58static void response_callback (GtkDialog *dialog,
 59			       gint       arg1,
 60			       gpointer   user_data)
 61{
 62	gint *response = (gint*)user_data;
 63	*response = arg1;
 64	gtk_widget_destroy(GTK_WIDGET(dialog));
 65	gtk_main_quit();
 66}
 67#endif // LL_GTK
 68
 69static BOOL do_ask_dialog(void)
 70{
 71#if LL_GTK
 72	gtk_disable_setlocale();
 73	if (!gtk_init_check(NULL, NULL)) {
 74		llinfos << "Could not initialize GTK for 'ask to send crash report' dialog; not sending report." << llendl;
 75		return FALSE;
 76	}
 77	
 78	GtkWidget *win = NULL;
 79	GtkDialogFlags flags = GTK_DIALOG_MODAL;
 80	GtkMessageType messagetype = GTK_MESSAGE_QUESTION;
 81	GtkButtonsType buttons = GTK_BUTTONS_YES_NO;
 82	gint response = GTK_RESPONSE_NONE;
 83
 84	win = gtk_message_dialog_new(NULL,
 85				     flags, messagetype, buttons,
 86				     "%s", dialog_text);
 87	gtk_window_set_type_hint(GTK_WINDOW(win),
 88				 GDK_WINDOW_TYPE_HINT_DIALOG);
 89	gtk_window_set_title(GTK_WINDOW(win), dialog_title);
 90	g_signal_connect (win,
 91			  "response", 
 92			  G_CALLBACK (response_callback),
 93			  &response);
 94	gtk_widget_show_all (win);
 95	gtk_main();
 96
 97	return (GTK_RESPONSE_OK == response ||
 98		GTK_RESPONSE_YES == response ||
 99		GTK_RESPONSE_APPLY == response);
100#else
101	return FALSE;
102#endif // LL_GTK
103}
104
105LLCrashLoggerLinux::LLCrashLoggerLinux(void)
106{
107}
108
109LLCrashLoggerLinux::~LLCrashLoggerLinux(void)
110{
111}
112
113void LLCrashLoggerLinux::gatherPlatformSpecificFiles()
114{
115}
116
117bool LLCrashLoggerLinux::mainLoop()
118{
119	bool send_logs = true;
120	if(CRASH_BEHAVIOR_ASK == getCrashBehavior())
121	{
122		send_logs = do_ask_dialog();
123	}
124	else if(CRASH_BEHAVIOR_NEVER_SEND == getCrashBehavior())
125	{
126		send_logs = false;
127	}
128
129	if(send_logs)
130	{
131		sendCrashLogs();
132	}
133	return true;
134}
135
136bool LLCrashLoggerLinux::cleanup()
137{
138	commonCleanup();
139	return true;
140}
141
142void LLCrashLoggerLinux::updateApplication(const std::string& message)
143{
144	LLCrashLogger::updateApplication(message);
145}