[NeoStats-Devel] [Commits] r2768 - in trunk: include modules/statserv src

[email protected] Tue, 23 Aug 2005 07:31:27 +1000
Newsgroups gmane.comp.neostats.devel
Message-ID <[email protected]>
Author: Mark
Date: Tue Aug 23 05:31:24 2005
New Revision: 2768

Modified:
   trunk/include/neostats.h
   trunk/modules/statserv/stats.c
   trunk/src/bots.c
   trunk/src/commands.c
   trunk/src/modules.c
   trunk/src/nsevents.c
   trunk/src/perl.c
   trunk/src/services.c
   trunk/src/timer.c
Log:
tidy up module status processing

Modified: trunk/include/neostats.h
==============================================================================
--- trunk/include/neostats.h	(original)
+++ trunk/include/neostats.h	Tue Aug 23 05:31:24 2005
@@ -439,8 +439,6 @@
 
 #define IsNeoStatsSynched()		me.synched
 
-#define IsModuleSynched()		GET_CUR_MODULE()->synched
-
 /* Unified return values and error system */
 
 /* NeoStats general success failure return type */
@@ -957,6 +955,10 @@
 
 #endif /* USE_PERL */
 
+#define MODULE_STATUS_SYNCHED	0x00000001
+#define MODULE_STATUS_INSYNCH	0x00000002
+#define MODULE_STATUS_ERROR		0x00000004
+
 /** @brief Module structure
  * 
  */
@@ -974,16 +976,25 @@
 	void *handle;
 	/** index */
 	unsigned int modnum;
-	/** status flags */
-	unsigned int insynch;
-	unsigned int synched;
-	unsigned int error;
+	/** status flag for synch, error, etc */
+	unsigned int status;
 #ifdef USE_PERL
 	MOD_TYPE modtype;
 	struct PerlModInfo *pm;
 #endif /* USE_PERL */
 }_Module;
 
+/* Set module status */
+#define SetModuleSynched( m ) ( ( m )->status |= MODULE_STATUS_SYNCHED )
+#define SetModuleInSynch( m ) ( ( m )->status |= MODULE_STATUS_INSYNCH )
+#define SetModuleError( m ) ( ( m )->status |= MODULE_STATUS_ERROR )
+/* Test module status */
+#define IsModuleSynched( m ) ( ( m )->status & MODULE_STATUS_SYNCHED )
+#define IsModuleInSynch( m ) ( ( m )->status & MODULE_STATUS_INSYNCH )
+#define IsModuleError( m ) ( ( m )->status & MODULE_STATUS_ERROR )
+
+#define ModuleSynched()	( GET_CUR_MODULE()->status & MODULE_STATUS_SYNCHED )
+
 /* Simple stack to manage run level replacing segv_module used in 
  * previous versions. This makes it easier to determine where we are 
  * running and avoids the need for modules to manage this or the core to

Modified: trunk/modules/statserv/stats.c
==============================================================================
--- trunk/modules/statserv/stats.c	(original)
+++ trunk/modules/statserv/stats.c	Tue Aug 23 05:31:24 2005
@@ -290,7 +290,7 @@
 	static time_t lasttime;
 	static int count;
 
-	if( !IsModuleSynched() )
+	if( !ModuleSynched() )
 		return NS_FALSE;
 	if( ( me.now - lasttime ) < StatServ.msginterval  )
 	{

Modified: trunk/src/bots.c
==============================================================================
--- trunk/src/bots.c	(original)
+++ trunk/src/bots.c	Tue Aug 23 05:31:24 2005
@@ -679,9 +679,9 @@
 
 	SET_SEGV_LOCATION();
 	modptr = GET_CUR_MODULE();
-	if( !modptr->insynch ) {
+	if( !IsModuleInSynch( modptr ) ) {
 		nlog( LOG_WARNING, "Module %s attempted to init a bot %s but is not yet synched", modptr->info->name, botinfo->nick );
-		modptr->error = 1;
+		SetModuleError( modptr );
 		return NULL;
 	}
 	/* In single bot mode, just add all commands and settings to main bot */

Modified: trunk/src/commands.c
==============================================================================
--- trunk/src/commands.c	(original)
+++ trunk/src/commands.c	Tue Aug 23 05:31:24 2005
@@ -368,9 +368,9 @@
  */
 int add_services_cmd_list( bot_cmd *bot_cmd_list ) 
 {
-	if( !GET_CUR_MODULE()->insynch )
+	if( !IsModuleInSynch( GET_CUR_MODULE() ) )
 	{
-		GET_CUR_MODULE()->error = 1;
+		SetModuleError( GET_CUR_MODULE() );
 		return NS_FAILURE;
 	}	
 	return add_bot_cmd_list( ns_botptr, bot_cmd_list );

Modified: trunk/src/modules.c
==============================================================================
--- trunk/src/modules.c	(original)
+++ trunk/src/modules.c	Tue Aug 23 05:31:24 2005
@@ -131,7 +131,7 @@
 	/* only standard modules get a sync */
 	if( IS_STD_MOD( module_ptr ) ) {
 #endif
-		module_ptr->insynch = 1;
+		SetModuleInSynch( module_ptr );
 		ModSynch = ns_dlsym( ( int * ) module_ptr->handle, "ModSynch" );
 		if( ModSynch ) {
 			SET_RUN_LEVEL( module_ptr );
@@ -139,7 +139,7 @@
 			RESET_RUN_LEVEL();
 		}
 		SET_SEGV_LOCATION();
-		module_ptr->synched = 1;
+		SetModuleSynched( module_ptr );
 #ifdef USE_PERL
 	} else {
 		err = perl_sync_module( module_ptr );
@@ -342,7 +342,7 @@
 	DBAOpenDatabase();
 	err =( *ModInit )(); 
 	RESET_RUN_LEVEL();
-	if( err < 1 || mod_ptr->error ) {
+	if( err < 1 || IsModuleError( mod_ptr ) ) {
 		load_module_error( u, modfilename, __( "See %s.log for further information.",u ), mod_ptr->info->name );
 		unload_module( mod_ptr->info->name, NULL );
 		return NULL;
@@ -355,7 +355,7 @@
 
 	/* Let this module know we are online if we are! */
 	if( IsNeoStatsSynched() ) {
-		if( SynchModule( mod_ptr ) != NS_SUCCESS || mod_ptr->error )
+		if( SynchModule( mod_ptr ) != NS_SUCCESS || IsModuleError( mod_ptr ) )
 		{
 			load_module_error( u, modfilename, __( "See %s.log for further information.", u ), mod_ptr->info->name );
 			unload_module( mod_ptr->info->name, NULL );

Modified: trunk/src/nsevents.c
==============================================================================
--- trunk/src/nsevents.c	(original)
+++ trunk/src/nsevents.c	Tue Aug 23 05:31:24 2005
@@ -118,7 +118,7 @@
 	{
 		/* If we are not yet synched, check that the module supports 
 			* the event before we are synched. */
-		if( !module_ptr->synched && !( module_ptr->event_list[event]->flags & EVENT_FLAG_IGNORE_SYNCH ) )
+		if( !IsModuleSynched( module_ptr ) && !( module_ptr->event_list[event]->flags & EVENT_FLAG_IGNORE_SYNCH ) )
 		{
 			dlog( DEBUG5, "Skipping module %s for %s since module is not yet synched", module_ptr->info->name, EventStrings[event] );
 			return;

Modified: trunk/src/perl.c
==============================================================================
--- trunk/src/perl.c	(original)
+++ trunk/src/perl.c	Tue Aug 23 05:31:24 2005
@@ -114,11 +114,11 @@
 	return ret_value;
 }
 
-int
-perl_sync_module(Module *mod) {
-	mod->insynch = 1;
+int perl_sync_module(Module *mod)
+{
+	SetModuleInSynch( mod );
 	execute_perl (mod, sv_2mortal (newSVpv ("NeoStats::Embed::sync", 0)),1, mod->pm->filename);
-	mod->synched = 1;
+	SetModuleSynched( mod );
 	return NS_SUCCESS;
 }
 
@@ -1558,7 +1558,6 @@
 	   perl_definition array.
 	 */
 	eval_pv (perl_definitions, TRUE);
-	mod->insynch = 0;
 	if (!execute_perl (mod, sv_2mortal (newSVpv ("NeoStats::Embed::load", 0)),
 								1, (char *)filename)) {
 		/* if we are here, check that pm->mod->info has something, otherwise the script didnt register */
@@ -1599,37 +1598,38 @@
 	return mod;
 }
 
-void PerlModFini(Module *mod) {
-		SET_RUN_LEVEL(mod);
-		if (mod->synched == 1) {
-			/* only execute unload if synced */
-			execute_perl (mod, sv_2mortal (newSVpv ("NeoStats::Embed::unload", 0)), 1, mod->pm->filename);
-		}
-		RESET_RUN_LEVEL();
+void PerlModFini(Module *mod)
+{
+	SET_RUN_LEVEL(mod);
+	if( IsModuleSynched( mod ) )
+	{
+		/* only execute unload if synced */
+		execute_perl (mod, sv_2mortal (newSVpv ("NeoStats::Embed::unload", 0)), 1, mod->pm->filename);
+	}
+	RESET_RUN_LEVEL();
 }
 
-void unload_perlmod(Module *mod) {
-		PERL_SET_CONTEXT((PMI *)mod->pm->my_perl);
-		/* because segv handler doesn't handle perl well yet */
+void unload_perlmod(Module *mod)
+{
+	PERL_SET_CONTEXT((PMI *)mod->pm->my_perl);
+	/* because segv handler doesn't handle perl well yet */
 //		RESET_RUN_LEVEL()
-		PL_perl_destruct_level = 1;
-		perl_destruct ((PMI *)mod->pm->my_perl);
-
-		perl_free ((PMI *)mod->pm->my_perl);
-
-		free((void *)mod->info->name);
+	PL_perl_destruct_level = 1;
+	perl_destruct ((PMI *)mod->pm->my_perl);
 
-		free((void *)mod->info->description);
+	perl_free ((PMI *)mod->pm->my_perl);
 
-		free((void *)mod->info->version);
-		
-		free((void *)mod->info->build_date);
-		
-		free((void *)mod->info->build_time);
+	free((void *)mod->info->name);
 
-		free(mod->info);
-		
-		free(mod->pm);
+	free((void *)mod->info->description);
 
+	free((void *)mod->info->version);
+	
+	free((void *)mod->info->build_date);
+	
+	free((void *)mod->info->build_time);
 
+	free(mod->info);
+	
+	free(mod->pm);
 }

Modified: trunk/src/services.c
==============================================================================
--- trunk/src/services.c	(original)
+++ trunk/src/services.c	Tue Aug 23 05:31:24 2005
@@ -220,11 +220,11 @@
 	ircsnprintf( ns_botinfo.realname, MAXREALNAME, "/msg %s \2HELP\2", ns_botinfo.nick );
 	if( nsconfig.onlyopers ) 
 		ns_botinfo.flags |= BOT_FLAG_ONLY_OPERS;
-	ns_module.insynch = 1;
+	SetModuleInSynch( &ns_module );
 	ns_botptr = AddBot( &ns_botinfo );
 	add_services_set_list (ns_debugsettings);
 	AddEventList( neostats_events );
-	ns_module.synched = 1;
+	SetModuleSynched( &ns_module );
 	me.synched = 1;
 	SynchAllModules();
 	RequestServerUptimes();	

Modified: trunk/src/timer.c
==============================================================================
--- trunk/src/timer.c	(original)
+++ trunk/src/timer.c	Tue Aug 23 05:31:24 2005
@@ -343,7 +343,7 @@
 		SET_SEGV_LOCATION();
 		timer = hnode_get (tn);
 		/* If a module is not yet synched, reset it's lastrun */
-		if (!timer->moduleptr->synched) {
+		if( !IsModuleSynched( timer->moduleptr ) ) {
 			timer->lastrun = (int) me.now;
 		} else {
 			switch (timer->type) {