// monitoring window for running BSP processes (and possibly various other stuff)
#include "watchbsp.h"
+#include "globaldefs.h"
#include <algorithm>
-#include <gtk/gtkmain.h>
#include "cmdlib.h"
#include "convert.h"
}
-#include <glib/gtimer.h>
-#include <glib/garray.h>
+#include <glib.h>
+#include <uilib/uilib.h>
#include "xmlstuff.h"
class CWatchBSP
{
private:
-// a flag we have set to true when using an external BSP plugin
-// the resulting code with that is a bit dirty, cleaner solution would be to seperate the succession of commands from the listening loop
-// (in two seperate classes probably)
-bool m_bBSPPlugin;
-
-// EIdle: we are not listening
-// DoMonitoringLoop will change state to EBeginStep
-// EBeginStep: the socket is up for listening, we are expecting incoming connection
-// incoming connection will change state to EWatching
-// EWatching: we have a connection, monitor it
-// connection closed will see if we start a new step (EBeginStep) or launch Quake3 and end (EIdle)
-enum EWatchBSPState { EIdle, EBeginStep, EWatching } m_eState;
-socket_t *m_pListenSocket;
-socket_t *m_pInSocket;
-netmessage_t msg;
-GPtrArray *m_pCmd;
-// used to timeout EBeginStep
-GTimer *m_pTimer;
-std::size_t m_iCurrentStep;
-// name of the map so we can run the engine
-char *m_sBSPName;
-// buffer we use in push mode to receive data directly from the network
-xmlParserInputBufferPtr m_xmlInputBuffer;
-xmlParserInputPtr m_xmlInput;
-xmlParserCtxtPtr m_xmlParserCtxt;
-// call this to switch the set listening mode
-bool SetupListening();
-// start a new EBeginStep
-void DoEBeginStep();
-// the xml and sax parser state
-char m_xmlBuf[MAX_NETMESSAGE];
-bool m_bNeedCtxtInit;
-message_info_t m_message_info;
+ // a flag we have set to true when using an external BSP plugin
+ // the resulting code with that is a bit dirty, cleaner solution would be to seperate the succession of commands from the listening loop
+ // (in two seperate classes probably)
+ bool m_bBSPPlugin;
+
+ // EIdle: we are not listening
+ // DoMonitoringLoop will change state to EBeginStep
+ // EBeginStep: the socket is up for listening, we are expecting incoming connection
+ // incoming connection will change state to EWatching
+ // EWatching: we have a connection, monitor it
+ // connection closed will see if we start a new step (EBeginStep) or launch Quake3 and end (EIdle)
+ enum EWatchBSPState { EIdle, EBeginStep, EWatching } m_eState;
+ socket_t *m_pListenSocket;
+ socket_t *m_pInSocket;
+ netmessage_t msg;
+ GPtrArray *m_pCmd;
+ // used to timeout EBeginStep
+ GTimer *m_pTimer;
+ std::size_t m_iCurrentStep;
+ // name of the map so we can run the engine
+ char *m_sBSPName;
+ // buffer we use in push mode to receive data directly from the network
+ xmlParserInputBufferPtr m_xmlInputBuffer;
+ xmlParserInputPtr m_xmlInput;
+ xmlParserCtxtPtr m_xmlParserCtxt;
+ // call this to switch the set listening mode
+ bool SetupListening();
+ // start a new EBeginStep
+ void DoEBeginStep();
+ // the xml and sax parser state
+ char m_xmlBuf[MAX_NETMESSAGE];
+ bool m_bNeedCtxtInit;
+ message_info_t m_message_info;
public:
-CWatchBSP(){
- m_pCmd = 0;
- m_bBSPPlugin = false;
- m_pListenSocket = NULL;
- m_pInSocket = NULL;
- m_eState = EIdle;
- m_pTimer = g_timer_new();
- m_sBSPName = NULL;
- m_xmlInputBuffer = NULL;
- m_bNeedCtxtInit = true;
-}
-virtual ~CWatchBSP(){
- EndMonitoringLoop();
- Net_Shutdown();
-
- g_timer_destroy( m_pTimer );
-}
-
-bool HasBSPPlugin() const
-{ return m_bBSPPlugin; }
+ CWatchBSP(){
+ m_pCmd = 0;
+ m_bBSPPlugin = false;
+ m_pListenSocket = NULL;
+ m_pInSocket = NULL;
+ m_eState = EIdle;
+ m_pTimer = g_timer_new();
+ m_sBSPName = NULL;
+ m_xmlInputBuffer = NULL;
+ m_bNeedCtxtInit = true;
+ }
+ virtual ~CWatchBSP(){
+ EndMonitoringLoop();
+ Net_Shutdown();
-// called regularly to keep listening
-void RoutineProcessing();
-// start a monitoring loop with the following steps
-void DoMonitoringLoop( GPtrArray *pCmd, const char *sBSPName );
-void EndMonitoringLoop(){
- Reset();
- if ( m_sBSPName ) {
- string_release( m_sBSPName, string_length( m_sBSPName ) );
- m_sBSPName = 0;
+ g_timer_destroy( m_pTimer );
}
- if ( m_pCmd ) {
- g_ptr_array_free( m_pCmd, TRUE );
- m_pCmd = 0;
+
+ bool HasBSPPlugin() const
+ { return m_bBSPPlugin; }
+
+ // called regularly to keep listening
+ void RoutineProcessing();
+ // start a monitoring loop with the following steps
+ void DoMonitoringLoop( GPtrArray *pCmd, const char *sBSPName );
+ void EndMonitoringLoop(){
+ Reset();
+ if ( m_sBSPName ) {
+ string_release( m_sBSPName, string_length( m_sBSPName ) );
+ m_sBSPName = 0;
+ }
+ if ( m_pCmd ) {
+ g_ptr_array_free( m_pCmd, TRUE );
+ m_pCmd = 0;
+ }
}
-}
-// close everything - may be called from the outside to abort the process
-void Reset();
-// start a listening loop for an external process, possibly a BSP plugin
-void ExternalListen();
+ // close everything - may be called from the outside to abort the process
+ void Reset();
+ // start a listening loop for an external process, possibly a BSP plugin
+ void ExternalListen();
};
CWatchBSP* g_pWatchBSP;
void Build_constructPreferences( PreferencesPage& page ){
- GtkWidget* monitorbsp = page.appendCheckBox( "", "Enable Build Process Monitoring", g_WatchBSP_Enabled );
- GtkWidget* leakstop = page.appendCheckBox( "", "Stop Compilation on Leak", g_WatchBSP_LeakStop );
- GtkWidget* runengine = page.appendCheckBox( "", "Run Engine After Compile", g_WatchBSP_RunQuake );
- GtkWidget* sleep = page.appendCheckBox ( "", "Sleep When Running the Engine", g_WatchBSP_DoSleep );
+ ui::CheckButton monitorbsp = page.appendCheckBox( "", "Enable Build Process Monitoring", g_WatchBSP_Enabled );
+ ui::CheckButton leakstop = page.appendCheckBox( "", "Stop Compilation on Leak", g_WatchBSP_LeakStop );
+ ui::CheckButton runengine = page.appendCheckBox( "", "Run Engine After Compile", g_WatchBSP_RunQuake );
+ ui::CheckButton sleep = page.appendCheckBox ( "", "Sleep When Running the Engine", g_WatchBSP_DoSleep );
Widget_connectToggleDependency( leakstop, monitorbsp );
Widget_connectToggleDependency( runengine, monitorbsp );
Widget_connectToggleDependency( sleep, runengine );
Build_constructPreferences( page );
}
void Build_registerPreferencesPage(){
- PreferencesDialog_addSettingsPage( FreeCaller1<PreferenceGroup&, Build_constructPage>() );
+ PreferencesDialog_addSettingsPage( makeCallbackF(Build_constructPage) );
}
#include "preferencesystem.h"
g_WatchBSP_Enabled = !string_equal( g_pGameDescription->getKeyValue( "no_bsp_monitor" ), "1" );
- GlobalPreferenceSystem().registerPreference( "WatchBSP", BoolImportStringCaller( g_WatchBSP_Enabled ), BoolExportStringCaller( g_WatchBSP_Enabled ) );
- GlobalPreferenceSystem().registerPreference( "RunQuake2Run", BoolImportStringCaller( g_WatchBSP_RunQuake ), BoolExportStringCaller( g_WatchBSP_RunQuake ) );
- GlobalPreferenceSystem().registerPreference( "LeakStop", BoolImportStringCaller( g_WatchBSP_LeakStop ), BoolExportStringCaller( g_WatchBSP_LeakStop ) );
- GlobalPreferenceSystem().registerPreference( "SleepMode", BoolImportStringCaller( g_WatchBSP_DoSleep ), BoolExportStringCaller( g_WatchBSP_DoSleep ) );
+ GlobalPreferenceSystem().registerPreference( "WatchBSP", make_property_string( g_WatchBSP_Enabled ) );
+ GlobalPreferenceSystem().registerPreference( "RunQuake2Run", make_property_string( g_WatchBSP_RunQuake ) );
+ GlobalPreferenceSystem().registerPreference( "LeakStop", make_property_string( g_WatchBSP_LeakStop ) );
+ GlobalPreferenceSystem().registerPreference( "SleepMode", make_property_string( g_WatchBSP_DoSleep ) );
Build_registerPreferencesPage();
}
else if ( strcmp( reinterpret_cast<const char*>( attrs[1] ), Q3MAP_STREAM_VERSION ) != 0 ) {
message_flush( data );
globalErrorStream() <<
- "This version of Radiant reads version " Q3MAP_STREAM_VERSION " debug streams, I got an incoming connection with version " << reinterpret_cast<const char*>( attrs[1] ) << "\n"
- "Please make sure your versions of Radiant and q3map are matching.\n";
+ "This version of " RADIANT_NAME " reads version " Q3MAP_STREAM_VERSION " debug streams, I got an incoming connection with version " << reinterpret_cast<const char*>( attrs[1] ) << "\n"
+ "Please make sure your versions of " RADIANT_NAME " and q3map are matching.\n";
abortStream( data );
return;
}
}
if ( data->recurse == data->stop_depth ) {
message_flush( data );
-#ifdef _DEBUG
+#if GDEF_DEBUG
globalOutputStream() << "Received error msg .. shutting down..\n";
#endif
GetWatchBSP()->EndMonitoringLoop();
class MessageOutputStream : public TextOutputStream
{
-message_info_t* m_data;
+ message_info_t* m_data;
public:
-MessageOutputStream( message_info_t* data ) : m_data( data ){
-}
-std::size_t write( const char* buffer, std::size_t length ){
- if ( m_data->pGeometry != 0 ) {
- m_data->pGeometry->saxCharacters( m_data, reinterpret_cast<const xmlChar*>( buffer ), int(length) );
+ MessageOutputStream( message_info_t* data ) : m_data( data ){
}
- else
- {
- if ( m_data->ignore_depth == 0 ) {
- // output the message using the level
- message_print( m_data, buffer, length );
- // if this message has error level flag, we mark the depth to stop the compilation when we get out
- // we don't set the msg level if we don't stop on leak
- if ( m_data->msg_level == 3 ) {
- m_data->stop_depth = m_data->recurse - 1;
+
+ std::size_t write( const char* buffer, std::size_t length ){
+ if ( m_data->pGeometry != 0 ) {
+ m_data->pGeometry->saxCharacters( m_data, reinterpret_cast<const xmlChar*>( buffer ), int(length) );
+ }
+ else
+ {
+ if ( m_data->ignore_depth == 0 ) {
+ // output the message using the level
+ message_print( m_data, buffer, length );
+ // if this message has error level flag, we mark the depth to stop the compilation when we get out
+ // we don't set the msg level if we don't stop on leak
+ if ( m_data->msg_level == 3 ) {
+ m_data->stop_depth = m_data->recurse - 1;
+ }
}
}
- }
- return length;
-}
+ return length;
+ }
};
template<typename T>
}
m_eState = EIdle;
if ( s_routine_id ) {
- gtk_timeout_remove( s_routine_id );
+ g_source_remove( s_routine_id );
}
}
bool CWatchBSP::SetupListening(){
-#ifdef _DEBUG
+#if GDEF_DEBUG
if ( m_pListenSocket ) {
globalOutputStream() << "ERROR: m_pListenSocket != NULL in CWatchBSP::SetupListening\n";
return false;
if ( SetupListening() == false ) {
const char* msg = "Failed to get a listening socket on port 39000.\nTry running with Build monitoring disabled if you can't fix this.\n";
globalOutputStream() << msg;
- gtk_MessageBox( GTK_WIDGET( MainFrame_getWindow() ), msg, "Build monitoring", eMB_OK, eMB_ICONERROR );
+ ui::alert( MainFrame_getWindow(), msg, "Build monitoring", ui::alert_type::OK, ui::alert_icon::Error );
return;
}
// set the timer for timeouts and step cancellation
msg << reinterpret_cast<const char*>( g_ptr_array_index( m_pCmd, m_iCurrentStep ) );
msg << "\nCheck that the file exists and that you don't run out of system resources.\n";
globalOutputStream() << msg.c_str();
- gtk_MessageBox( GTK_WIDGET( MainFrame_getWindow() ), msg.c_str(), "Build monitoring", eMB_OK, eMB_ICONERROR );
+ ui::alert( MainFrame_getWindow(), msg.c_str(), "Build monitoring", ui::alert_type::OK, ui::alert_icon::Error );
return;
}
// re-initialise the debug window
}
}
m_eState = EBeginStep;
- s_routine_id = gtk_timeout_add( 25, watchbsp_routine, this );
+ s_routine_id = g_timeout_add( 25, watchbsp_routine, this );
}
-#if defined( WIN32 )
-#define ENGINE_ATTRIBUTE "engine_win32"
-#define MP_ENGINE_ATTRIBUTE "mp_engine_win32"
-#elif defined( __linux__ ) || defined ( __FreeBSD__ )
-#define ENGINE_ATTRIBUTE "engine_linux"
-#define MP_ENGINE_ATTRIBUTE "mp_engine_linux"
-#elif defined( __APPLE__ )
-#define ENGINE_ATTRIBUTE "engine_macos"
-#define MP_ENGINE_ATTRIBUTE "mp_engine_macos"
+#if GDEF_OS_WINDOWS
+const char *ENGINE_ATTRIBUTE = "engine_win32";
+const char *MP_ENGINE_ATTRIBUTE = "mp_engine_win32";
+#elif GDEF_OS_LINUX || GDEF_OS_BSD
+const char *ENGINE_ATTRIBUTE = "engine_linux";
+const char *MP_ENGINE_ATTRIBUTE = "mp_engine_linux";
+#elif GDEF_OS_MACOS
+const char *ENGINE_ATTRIBUTE = "engine_macos";
+const char *MP_ENGINE_ATTRIBUTE = "mp_engine_macos";
#else
#error "unsupported platform"
#endif
class RunEngineConfiguration
{
public:
-const char* executable;
-const char* mp_executable;
-bool do_sp_mp;
-
-RunEngineConfiguration() :
- executable( g_pGameDescription->getRequiredKeyValue( ENGINE_ATTRIBUTE ) ),
- mp_executable( g_pGameDescription->getKeyValue( MP_ENGINE_ATTRIBUTE ) ){
- do_sp_mp = !string_empty( mp_executable );
-}
+ const char* executable;
+ const char* mp_executable;
+ bool do_sp_mp;
+
+ RunEngineConfiguration() :
+ executable( g_pGameDescription->getRequiredKeyValue( ENGINE_ATTRIBUTE ) ),
+ mp_executable( g_pGameDescription->getKeyValue( MP_ENGINE_ATTRIBUTE ) ){
+ do_sp_mp = !string_empty( mp_executable );
+ }
};
inline void GlobalGameDescription_string_write_mapparameter( StringOutputStream& string, const char* mapname ){
case EBeginStep:
// timeout: if we don't get an incoming connection fast enough, go back to idle
if ( g_timer_elapsed( m_pTimer, NULL ) > g_WatchBSP_Timeout ) {
- gtk_MessageBox( GTK_WIDGET( MainFrame_getWindow() ), "The connection timed out, assuming the build process failed\nMake sure you are using a networked version of Q3Map?\nOtherwise you need to disable BSP Monitoring in prefs.", "BSP process monitoring", eMB_OK );
+ ui::alert( MainFrame_getWindow(), "The connection timed out, assuming the build process failed\nMake sure you are using a networked version of Q3Map?\nOtherwise you need to disable BSP Monitoring in prefs.", "BSP process monitoring", ui::alert_type::OK );
EndMonitoringLoop();
#if 0
if ( m_bBSPPlugin ) {
#endif
return;
}
-#ifdef _DEBUG
+#if GDEF_DEBUG
// some debug checks
if ( !m_pListenSocket ) {
globalErrorStream() << "ERROR: m_pListenSocket == NULL in CWatchBSP::RoutineProcessing EBeginStep state\n";
break;
case EWatching:
{
-#ifdef _DEBUG
+#if GDEF_DEBUG
// some debug checks
if ( !m_pInSocket ) {
globalErrorStream() << "ERROR: m_pInSocket == NULL in CWatchBSP::RoutineProcessing EWatching state\n";
StringOutputStream msg;
msg << "Failed to execute the following command: " << cmd.c_str() << cmdline.c_str();
globalOutputStream() << msg.c_str();
- gtk_MessageBox( GTK_WIDGET( MainFrame_getWindow() ), msg.c_str(), "Build monitoring", eMB_OK, eMB_ICONERROR );
+ ui::alert( MainFrame_getWindow(), msg.c_str(), "Build monitoring", ui::alert_type::OK, ui::alert_icon::Error );
}
}
EndMonitoringLoop();
if ( m_eState != EIdle ) {
globalOutputStream() << "WatchBSP got a monitoring request while not idling...\n";
// prompt the user, should we cancel the current process and go ahead?
- if ( gtk_MessageBox( GTK_WIDGET( MainFrame_getWindow() ), "I am already monitoring a Build process.\nDo you want me to override and start a new compilation?",
- "Build process monitoring", eMB_YESNO ) == eIDYES ) {
+ if ( ui::alert( MainFrame_getWindow(), "I am already monitoring a Build process.\nDo you want me to override and start a new compilation?",
+ "Build process monitoring", ui::alert_type::YESNO ) == ui::alert_response::YES ) {
// disconnect and set EIdle state
Reset();
}