Пример #1
0
ccsCOMPL_STAT wsf2ex1APPLICATION::Run()
{
    wsf2libLOG_TRACE();
    ErrReset();

    ccsCOMPL_STAT stat = SUCCESS;

    eccsLOG_1(("wsf2ex1 - Entering the main loop."));
    while(IsRunning() == ccsTRUE)
	{
	// I can return on request, such as with EXIT command 
	// (stat == SUCCESS) or because of an error (stat == FAILURE)
	stat = evhHandler->MainLoop();

	// In case of error, I try to recover before exiting
	if (stat == FAILURE) 
	    {
	    eccsLOG_1(("A fatal error occurred, try to recover!"));
#if 0
	    wsf2libASSERTPTR(mEventMgr);
	    if (mEventMgr->Init() == FAILURE) stat = FAILURE;

	    wsf2libASSERTPTR(mActionMgr);
	    if (mActionMgr->Init() == FAILURE) stat = FAILURE;

	    wsf2libASSERTPTR(mFsm);
	    if (mFsm->Init() ==  FAILURE) stat = FAILURE;
#endif
	    errAdd(wsf2ex1MOD, wsf2ex1ERR_FATAL, __FILE_LINE__, GetProcName());
	    errCloseStack();

	    if (stat == FAILURE)
		{
		eccsLOG_1(("Cannot recover. Application aborted!"));
		errAdd(wsf2ex1MOD, wsf2ex1ERR_FATAL, __FILE_LINE__, GetProcName());
		errCloseStack();
		logData(wsf2ex1MOD, "%s - Application aborted!", GetProcName());
		Quit();
		}
	    }
	else
	    {
	    eccsLOG_1(("wsf2ex1 - Exiting from the main loop. Application quits."));
	    logData(wsf2ex1MOD, "%s - Application quits.", GetProcName());
	    Quit();
	    break;
	    }
	}

    return stat;
} 
Пример #2
0
static void RainFreeStopped()
{
    int i;
    for(i=0;i<sounds;i++)
        if(!soundGetStatus(&sound[i]))
        {
            _bprintf(errBuf,errBufLen,"end of %i",sound[i].rainhandle);
            errAdd(errBuf);
            soundStop(&sound[i]);
            sound[i--]=sound[--sounds];
        }
}
Пример #3
0
static void soundSetPanning(struct Sound *s,int panning)
{
    if (panning<-64) panning=-64; else if (panning>64) panning=64;
    if (s->playhandle)
    switch (s->type)
    {
        case Module:
            break;
        case Sample:
            MIDASsetSamplePanning((MIDASsamplePlayHandle)s->playhandle,panning);
            break;
        case Stream:
            MIDASsetStreamPanning((MIDASstreamHandle)s->playhandle,panning);
            break;
#ifdef DEBUG
        default:
            errAdd(" Set panning: Unknown type.");
#endif
    }
    MIDASreportErr();
}
Пример #4
0
wsf2ex1APPLICATION::wsf2ex1APPLICATION() :
    wsf2libAPPLICATION(),
    mActionMgr(NULL)
{
    wsf2libLOG_TRACE();
    
    /*
     * Set the module name used by the logging
     */
    wsf2libLOG_SETMODNAME(wsf2ex1MOD);
        
    /*
     * Check base class construction
     */
    if (wsf2libHELPER::ObjectOk(this, "APPLICATION") == ccsFALSE)
	{
	errAdd(wsf2ex1MOD, wsf2ex1ERR_CREATE, __FILE_LINE__, "wsf2libAPPLICATION");
	ObjStatus(FAILURE);	
	return;	
	}
}
Пример #5
0
static void soundSetVolume(struct Sound *s,int volume)
{
    if (volume<0) volume=0; else if (volume>64) volume=64;
    if (s->playhandle)
    switch (s->type)
    {
        case Module:
            MIDASsetMusicVolume((MIDASmodulePlayHandle)s->playhandle,volume/AMPLIFY_MP3);
            break;
        case Sample:
            MIDASsetSampleVolume((MIDASsamplePlayHandle)s->playhandle,volume/AMPLIFY_MP3);
            break;
        case Stream:
            MIDASsetStreamVolume((MIDASstreamHandle)s->playhandle,volume);
            break;
#ifdef DEBUG
        default:
            errAdd(" Set volume: Unknown type.");
#endif
    }
    MIDASreportErr();
}
Пример #6
0
static int soundGetStatus(struct Sound *s)
{
    int result=0;
    if (s->playhandle)
    switch (s->type)
    {
        case Module:
            {
            MIDASplayStatus status;
            MIDASgetPlayStatus((MIDASmodulePlayHandle)s->playhandle,&status);
            result=s->loop?1:1-status.songLoopCount;
            }
            break;
        case Sample:
            result=MIDASgetSamplePlayStatus((MIDASsamplePlayHandle)s->playhandle);
            break;
        case Stream:
            {
            int buffered=MIDASgetStreamBytesBuffered((MIDASstreamHandle)s->playhandle);
            result=1;
            #define BUFLEN 4608
            if ( buffered+2*BUFLEN<=s->bufferbytes )
            {
                unsigned char buf[BUFLEN];
                int decoded=MP3read((void *)s->datahandle,s->loop,buf,BUFLEN);
                if ( !decoded ) result=buffered/8;
                MIDASfeedStreamData((MIDASstreamHandle)s->playhandle,buf,decoded,1/*feedAll*/);
            }
            }
            break;
#ifdef DEBUG
        default:
            errAdd(" Get status: Unknown type.");
#endif
    }
    MIDASreportErr();
    return result;
}
Пример #7
0
static void soundStop(struct Sound *s)
{
    if (s->datahandle)
    switch (s->type)
    {
        case Module:
            if (s->playhandle)
            {
                MIDASstopModule((MIDASmodulePlayHandle)s->playhandle);
                MIDASreportErr();
            }
            MIDASfreeModule((MIDASmodule)s->datahandle);
            break;
        case Sample:
            if (s->playhandle)
            {
                MIDASstopSample((MIDASsamplePlayHandle)s->playhandle);
                MIDASreportErr();
            }
            MIDASfreeSample((MIDASsample)s->datahandle);
            break;
        case Stream:
            if (s->playhandle)
            {
                MIDASstopStream((MIDASstreamHandle)s->playhandle);
                MIDASreportErr();
            }
            MP3close((void *)s->datahandle);
            break;
#ifdef DEBUG
        default:
            errAdd(" Stop: Unknown type.");
#endif
    }
    MIDASreportErr();
}
Пример #8
0
static void reportErr(int err)
{
    _bprintf(errBuf,errBufLen," %s: %s",hint,MIDASgetErrorMessage(err));
    errAdd(errBuf);
}
Пример #9
0
int RainCommand(int command,int param1,int param2,int param3,
                 char *filename,int fileofs,int filesize)
{
    int result=0;
    int i;
    if (command==CMD_PLAY)
        _bprintf(hint,hintlen,"%s,%i,%i",filename,fileofs,filesize);
    else
        _bprintf(hint,hintlen,"%i(%i,%i)",command,param1,param2);
    switch (command)
    {
        case CMD_NONE:
            RainFreeStopped();
            MIDASpoll();
            break;
        case CMD_PLAY:
            rainhandles++;
            if (sounds<SOUNDS)
            {
                sound[sounds].type=None;
                sound[sounds].rainhandle=rainhandles;
                sound[sounds].datahandle=0;
                sound[sounds].playhandle=0;
                soundPlay(&sound[sounds],filename,fileofs,filesize,param1);
                soundSetVolume(&sound[sounds],param2);
                soundSetPanning(&sound[sounds],param3);
                sounds++;
            }
            result=rainhandles;
            break;
        case CMD_VOL:
            for(i=0;i<sounds;i++)
              if(sound[i].rainhandle==param1)
              {
                  soundSetVolume(&sound[i],param2);
              }
            break;
        case CMD_PAN:
            for(i=0;i<sounds;i++)
              if(sound[i].rainhandle==param1)
              {
                  soundSetPanning(&sound[i],param2);
              }
            break;
        case CMD_STOP:
            for(i=0;i<sounds;i++)
              if(sound[i].rainhandle==param1)
              {
                  soundStop(&sound[i]);
                  sound[i--]=sound[--sounds];
              }
            break;
        case CMD_AMPLIFY:
            MIDASsetAmplification(AMPLIFY_ALL*AMPLIFY_MP3*param1);
            break;
        default:
            _bprintf(errBuf,errBufLen," Unknown command %i.",command);
            errAdd(errBuf);
    }
    MIDASreportErr();
    return result;
}
Пример #10
0
ccsCOMPL_STAT wsf2ex1APPLICATION::Init(int argCount, char *arg[])
{
    wsf2libLOG_TRACE();
    ErrReset();


    // Turn off logging of warning on EXIT command
    evhTASK::LogExitWarning(FALSE);

    // Parses the command line arguments
    // and extract the configuration parameters
    // for ENV NAME, DB POINT and PROC NAME from the
    // command line or from the enviroment variables
    if (EvaluateArgs(argCount, arg, wsf2ex1DB_ROOT_POINT) == FAILURE)
	{
	errAdd(wsf2ex1MOD, wsf2ex1ERR_INIT, __FILE_LINE__, "wrong argument(s)");
	return FAILURE;
	}

    // Initialize CCS and connect to database
    if(InitCCS() == FAILURE)
	{
	errAdd(wsf2ex1MOD, wsf2ex1ERR_INIT, __FILE_LINE__, "cannot init CCS");
	return FAILURE;      
	}

    // Logs current startup configuration
    eccsLOG_1(("%s - Application started (proc name: %s, DB root point: %s)", 
	       GetProcName(), GetProcName(), GetDbRoot()));
    logData(wsf2ex1MOD,"%s - Application started (proc name: %s, DB root point: %s)", 
	    GetProcName(), GetProcName(), GetDbRoot());

   /*
    * Create factory for ACTIONS, DATA, CONFIG and CONTROL
    */
    wsf2libASSERT(mActionMgr == NULL);
    mActionMgr = new wsf2ex1ACTION_MGR(GetDbRoot(), argCount, arg, GetEventMgr());
    if (mActionMgr == NULL)
	{
	errAdd(wsf2ex1MOD, wsf2ex1ERR_FATAL, __FILE_LINE__, "no memory for allocating wsf2ex1ACTION_MGR");
	return FAILURE;
	}
    if (wsf2libHELPER::ObjectOk(mActionMgr, "ACTION_MGR") == ccsFALSE)
	{
	errAdd(wsf2ex1MOD, wsf2ex1ERR_CREATE, __FILE_LINE__, "wsf2ex1ACTION_MGR");
	return FAILURE;	
	}

    /*
     * Set FSM context
     * TBD: rename method
     */
    SetControl(mActionMgr->GetControl());

    /*
     * Instantiate events and actions
     */
    if (CreateEvents(wsf2ex1EVENTS_FILENAME) == FAILURE)
	{
	errAdd(wsf2ex1MOD, wsf2ex1ERR_CREATE, __FILE_LINE__, "Events");
	return FAILURE;	
	}
    if (mActionMgr->CreateActions() == FAILURE)
	{
	errAdd(wsf2ex1MOD, wsf2ex1ERR_CREATE, __FILE_LINE__, "Actions");
	return FAILURE;	
	}
    /*
     * Load SCXML Model
     */
    if (LoadModel(wsf2ex1MODEL_FILENAME, mActionMgr->SCXMLGetActions(), mActionMgr->SCXMLGetActivities()) == FAILURE)
	{
	errAdd(wsf2ex1MOD, wsf2ex1ERR_FATAL, __FILE_LINE__, "cannot load SCXML model");
	return FAILURE;
	}

    /*
     * Initialize all events and actions and data structures
     */
    if (mActionMgr->Init() == FAILURE)
	{
	errAdd(wsf2ex1MOD, wsf2ex1ERR_FATAL, __FILE_LINE__, "initializing actions and data structures");
	return FAILURE;
	}

    /*
     * Start the execution of SCXML model
     */
    if (StartModel() == FAILURE)
	{
	errAdd(wsf2ex1MOD, wsf2ex1ERR_FATAL, __FILE_LINE__, "cannot start SCXML model execution");
	return FAILURE;
	}

    return SUCCESS;
}