// static
void Daemon :: Maintain(int FixP_Time_ToUse)
{
	GLOBALASSERT( NULL == p666_Iteration_Current );
	GLOBALASSERT( NULL == p666_Iteration_Next );

	#if DaemonDiagnostics
	ProfileStart();
	#endif

	p666_Iteration_Current = p666_FirstActive;

	FixP_Time = FixP_Time_ToUse;

	while ( p666_Iteration_Current )
	{
		p666_Iteration_Next = p666_Iteration_Current -> p666_NextActive;

		{
			#if DaemonNaming && DaemonDiagnostics
            char* tempDebugName = p666_Iteration_Current -> GetDebugName();
                // in case it gets deleted during the loop

			ProfileStart();
			#endif

			#if SupportCallbackHooks
			if
			(
				p666_Iteration_Current -> Activity(FixP_Time)
			)
			{
				if ( p666_Iteration_Current )
                {
    				// run the OnActivity() method for all the callback hooks attached to this daemon
    				CallbackHook* pCallbackHook = p666_Iteration_Current -> pFirstHook;
    				while ( pCallbackHook )
    				{
    					CallbackHook* pCallbackHook_Nxt = pCallbackHook -> pNxtHook;
    					
    					pCallbackHook -> OnActivity();
    					
    					pCallbackHook = pCallbackHook_Nxt;
    				}
                }
                // else the iterating daemon got deleted during the call to Activity()
			}
			#else
			{
				#if IndividualTiming
				{
					p666_Iteration_Current -> Activity(FixP_Time);
				}
				#else
				{
					p666_Iteration_Current -> Activity();
				}
				#endif
			}
			#endif

			#if DaemonNaming && DaemonDiagnostics
			ProfileStop
			(
				tempDebugName
			);
			#endif

		}
        /* 
            Advance to the next in the iteration.
            This will be either the next ptr of the current as stored above,
            or one further along the list (since the pNext one itself might
            have got deleted during the call to Activity)
        */
		p666_Iteration_Current = p666_Iteration_Next;
	}

	#if DaemonDiagnostics

	ProfileStop("Daemon :: Maintain()");

	#if CountActiveDaemons
	textprint("Num active daemons:%i\n",GetNumActive());
	#endif

	#endif // #if DaemonDiagnostics

}
ProfileSection::ProfileSection(const std::string& profileName, bool isAutoDestruct):
autoDestruct(isAutoDestruct)
{
	ProfileStart(profileName);
}
Exemple #3
0
int main(int argc, char **argv) {
	int retval = 0;
	char *dparams[2];
	int paramc = 0, params = -1;

	char temp[0x1000];
	int done = 0;
	char *source = NULL;
	int n = 0;

	// Acción a realizar
	int action = ACTION_NONE;

	if (argc <= 1) {
		action = ACTION_HELP;
		setparams(0);
	}

	for (n = 1; n <= argc; n++) {
		char *arg;
		arg = (n < argc) ? argv[n] : "";

		//printf("%s\n", arg);

		// Muestra la ayuda y sale
		if (strcmp(arg, "-?") == 0 || strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) {
			//show_help();
			action = ACTION_HELP;
			setparams(0);
		}

		// Modificadores
		{
			// Modo raw (sin cabeceras de compresión)
			if (strcmp(arg, "-r") == 0 || strcmp(arg, "-raw") == 0) { raw = 1; continue; }

			// Modo silencioso
			if (strcmp(arg, "-s") == 0) { silent = 1; fclose(stdout); continue; }
		}

		// Acciones
		{
			if (arg[0] == '-') {
				int cnt = 1;

				switch (arg[1]) {
					// Codificad
					case 'c': action = ACTION_ENCODE ; setparams(2); break;
					// Decodificia
					case 'd': action = ACTION_DECODE ; setparams(2); break;
					// Comprueba
					case 't': action = ACTION_TEST   ; setparams(1); break;
					// Crea un perfil de compresión
					case 'p': action = ACTION_PROFILE; setparams(1); break;
					// Dumpea el text_buffer inicial
					case 'b': action = ACTION_BDUMP  ; setparams(1); break;
					default:  cnt = 0; break;
				}

				if (cnt) {
					done = 0;
					modifier = (strlen(arg) >= 3) ? atoi(arg + 2) : 3;
					continue;
				}
			}
		}

		if ((n < argc) && (paramc < params)) {
			dparams[paramc++] = arg;
		}

		if (paramc >= params) {
			show_header_once();

			done = 1;
			switch (action) {
				case ACTION_ENCODE:
					if (strcmp(dparams[0], dparams[1]) != 0) {
						retval |= EncodeFile(dparams[0], dparams[1], raw, modifier);
					} else {
						fprintf(stderr, "Can't use same file for input and output\n");
						retval |= -1;
					}
				break;
				case ACTION_DECODE:
					if (strcmp(dparams[0], dparams[1]) != 0) {
						retval |= DecodeFile(dparams[0], dparams[1], raw, modifier);
					} else {
						fprintf(stderr, "Can't use same file for input and output\n");
						retval |= -1;
					}
				break;
				case ACTION_PROFILE:
					if (strlen(arg) < 0x900) {
						sprintf(temp, "%s.profile", arg);
						ProfileStart(temp);
							retval |= DecodeFile(dparams[0], NULL, raw, modifier);
						ProfileEnd();
					}
				break;
				case ACTION_BDUMP:
					DumpTextBuffer(dparams[0]);
				break;
				case ACTION_TEST:
					retval |= CheckCompression(dparams[0], modifier);
				break;
				case ACTION_HELP:
					show_help();
				break;
				default:
					if (n == argc) {
						if (paramc == params || params == 0) exit(retval);
						if (params == -1) show_help();
						fprintf(stderr, "Expected %d params, but %d given\n", params, paramc);
						exit(-1);
					}
					fprintf(stderr, "Unknown parameter '%s'\n", arg);
					exit(-1);
				break;
			}

			paramc = params = 0;
			action = ACTION_NONE;
		}
	}

	show_header_once();

	fprintf(stderr, "Expected %d params, but %d given\n", params, paramc);
	exit(-1);

	return 0;
}