Esempio n. 1
0
void ClipsSession::initialize(int argc,char *argv, string sessionID, RouterInterface *router)
#endif
{
	cout<<"ClipsSession::initialize 0 sessionID:"<<sessionID<<endl;
	m_sessionID = sessionID;
		cout<<"ClipsSession::initialize 1"<<endl;
	m_theEnv = CreateEnvironment();
	cout<<"ClipsSession::initialize 2"<<endl;
#ifdef _DEBUG_CLIPS_
    cout<<"ClipsSession::initialize 3"<<endl;

	if (ConfigUtil::GetInstance()->GetConfigStr("CLIPSログ出力パス").length() > 0)
	{
		fw.open(ConfigUtil::GetInstance()->GetConfigStr("CLIPSログ出力パス").c_str(), ios::out);
#if 1
		EnvWatch(m_theEnv,"globals");
		EnvWatch(m_theEnv, "rules");
		EnvWatch(m_theEnv, "facts");
		EnvWatch(m_theEnv,"activations");
		EnvWatch(m_theEnv,"focus");
		EnvWatch(m_theEnv,"deffunctions");
		EnvWatch(m_theEnv,"compilations");
#endif
		EnvAddRouter(m_theEnv,"DEBUG",999,queryFunction,printFunction,NULL,NULL,NULL);
		//EnvAddRouter(m_theEnv,"wtrace",1000,queryFunction,printFunction,NULL,NULL,NULL);
		//EnvActivateRouter(m_theEnv,"wdialog");
		EnvActivateRouter(m_theEnv,"DEBUG");
#endif
#ifdef _PERFORMANCE_
		//for performance
		//EnvWatch(m_theEnv,"statistics");
#endif
	}

 #if 0
	char *tmp[1];
	tmp[0] = argv;
	RerouteStdin(m_theEnv,1,tmp);
#else
    if (router != NULL)
    {
        m_router = router;
        //const char *routerName=m_router->getRouterName().c_str();
        string routerName = m_router->getRouterName();
		EnvAddRouter(m_theEnv,routerName.c_str(),30,queryFunction,printFunction,NULL,NULL,NULL);
		EnvActivateRouter(m_theEnv, routerName.c_str());
    }
#endif	
	cout<<"ClipsSession::initialize 4"<<endl;	
	EnvReset(m_theEnv);

	
	cout<<"ClipsSession::initialize 5"<<endl;
	m_ruleMgr = new ClipsRuleMgr();
	if (m_ruleMgr != NULL) 
		m_ruleMgr->initialize(m_theEnv, m_sessionID);
}
Esempio n. 2
0
static int UngetcDribble(
  void *theEnv,
  int ch,
  char *logicalName)
  {
   int rv;

   /*===============================================*/
   /* Remove the character from the dribble buffer. */
   /*===============================================*/

   if (FileCommandData(theEnv)->DribbleCurrentPosition > 0) FileCommandData(theEnv)->DribbleCurrentPosition--;
   FileCommandData(theEnv)->DribbleBuffer[FileCommandData(theEnv)->DribbleCurrentPosition] = EOS;

   /*=============================================*/
   /* Deactivate the dribble router and pass the  */
   /* ungetc request to the other active routers. */
   /*=============================================*/

   EnvDeactivateRouter(theEnv,"dribble");
   rv = EnvUngetcRouter(theEnv,ch,logicalName);
   EnvActivateRouter(theEnv,"dribble");

   /*==========================================*/
   /* Return the result of the ungetc request. */
   /*==========================================*/

   return(rv);
  }
Esempio n. 3
0
static int GetcDribble(
  void *theEnv,
  char *logicalName)
  {
   int rv;

   /*===========================================*/
   /* Deactivate the dribble router and get the */
   /* character from another active router.     */
   /*===========================================*/

   EnvDeactivateRouter(theEnv,"dribble");
   rv = EnvGetcRouter(theEnv,logicalName);
   EnvActivateRouter(theEnv,"dribble");

   /*==========================================*/
   /* Put the character retrieved from another */
   /* router into the dribble buffer.          */
   /*==========================================*/

   PutcDribbleBuffer(theEnv,rv);

   /*=======================*/
   /* Return the character. */
   /*=======================*/

   return(rv);
  }
Esempio n. 4
0
static int PrintDribble(
    void *theEnv,
    char *logicalName,
    char *str)
{
    int i;

    /*======================================*/
    /* Send the output to the dribble file. */
    /*======================================*/

    for (i = 0 ; str[i] != EOS ; i++)
    {
        PutcDribbleBuffer(theEnv,str[i]);
    }

    /*===========================================================*/
    /* Send the output to any routers interested in printing it. */
    /*===========================================================*/

    EnvDeactivateRouter(theEnv,(char*)"dribble");
    EnvPrintRouter(theEnv,logicalName,str);
    EnvActivateRouter(theEnv,(char*)"dribble");

    return(1);
}
Esempio n. 5
0
globle void EnvClear(
  void *theEnv)
  {
   struct callFunctionItem *theFunction;
   
   /*==========================================*/
   /* Activate the watch router which captures */
   /* trace output so that it is not displayed */
   /* during a clear.                          */
   /*==========================================*/

#if DEBUGGING_FUNCTIONS
   EnvActivateRouter(theEnv,WTRACE);
#endif

   /*===================================*/
   /* Determine if a clear is possible. */
   /*===================================*/

   ConstructData(theEnv)->ClearReadyInProgress = TRUE;
   if ((ConstructData(theEnv)->ClearReadyLocks > 0) ||
       (ConstructData(theEnv)->DanglingConstructs > 0) ||
       (ClearReady(theEnv) == FALSE))
     {
      PrintErrorID(theEnv,"CONSTRCT",1,FALSE);
      EnvPrintRouter(theEnv,WERROR,"Some constructs are still in use. Clear cannot continue.\n");
#if DEBUGGING_FUNCTIONS
      EnvDeactivateRouter(theEnv,WTRACE);
#endif
      ConstructData(theEnv)->ClearReadyInProgress = FALSE;
      return;
     }
   ConstructData(theEnv)->ClearReadyInProgress = FALSE;

   /*===========================*/
   /* Call all clear functions. */
   /*===========================*/

   ConstructData(theEnv)->ClearInProgress = TRUE;

   for (theFunction = ConstructData(theEnv)->ListOfClearFunctions;
        theFunction != NULL;
        theFunction = theFunction->next)
     { 
      if (theFunction->environmentAware)
        { (*theFunction->func)(theEnv); }
      else            
        { (* (void (*)(void)) theFunction->func)(); }
     }

   /*=============================*/
   /* Deactivate the watch router */
   /* for capturing output.       */
   /*=============================*/

#if DEBUGGING_FUNCTIONS
   EnvDeactivateRouter(theEnv,WTRACE);
#endif

   /*===========================================*/
   /* Perform periodic cleanup if the clear was */
   /* issued from an embedded controller.       */
   /*===========================================*/

   if ((UtilityData(theEnv)->CurrentGarbageFrame->topLevel) && (! CommandLineData(theEnv)->EvaluatingTopLevelCommand) &&
       (EvaluationData(theEnv)->CurrentExpression == NULL) && (UtilityData(theEnv)->GarbageCollectionLocks == 0))
     {
      CleanCurrentGarbageFrame(theEnv,NULL);
      CallPeriodicTasks(theEnv);
     }

   /*===========================*/
   /* Clear has been completed. */
   /*===========================*/

   ConstructData(theEnv)->ClearInProgress = FALSE;
   
#if DEFRULE_CONSTRUCT
   if ((DefruleData(theEnv)->RightPrimeJoins != NULL) ||
       (DefruleData(theEnv)->LeftPrimeJoins != NULL))
     { SystemError(theEnv,"CONSTRCT",1); }
#endif

   /*============================*/
   /* Perform reset after clear. */
   /*============================*/
   
   EnvReset(theEnv);
  }
Esempio n. 6
0
globle BOOLEAN EnvClear_PY(
  void *theEnv)
  {
   struct callFunctionItem *theFunction;

   /*==========================================*/
   /* Activate the watch router which captures */
   /* trace output so that it is not displayed */
   /* during a clear.                          */
   /*==========================================*/

#if DEBUGGING_FUNCTIONS
   EnvActivateRouter(theEnv,WTRACE);
#endif

   /*===================================*/
   /* Determine if a clear is possible. */
   /*===================================*/

   ConstructData(theEnv)->ClearReadyInProgress = TRUE;
   if (ClearReady(theEnv) == FALSE)
     {
      PrintErrorID(theEnv,"CONSTRCT",1,FALSE);
      EnvPrintRouter(theEnv,WERROR,"Some constructs are still in use. Clear cannot continue.\n");
#if DEBUGGING_FUNCTIONS
      EnvDeactivateRouter(theEnv,WTRACE);
#endif
      ConstructData(theEnv)->ClearReadyInProgress = FALSE;
      return FALSE;
     }
   ConstructData(theEnv)->ClearReadyInProgress = FALSE;

   /*===========================*/
   /* Call all clear functions. */
   /*===========================*/

   ConstructData(theEnv)->ClearInProgress = TRUE;

   for (theFunction = ConstructData(theEnv)->ListOfClearFunctions;
        theFunction != NULL;
        theFunction = theFunction->next)
     {
      if (theFunction->environmentAware)
        { (*theFunction->func)(theEnv); }
      else
        { (* (void (*)(void)) theFunction->func)(); }
     }

   /*=============================*/
   /* Deactivate the watch router */
   /* for capturing output.       */
   /*=============================*/

#if DEBUGGING_FUNCTIONS
   EnvDeactivateRouter(theEnv,WTRACE);
#endif

   /*===========================================*/
   /* Perform periodic cleanup if the clear was */
   /* issued from an embedded controller.       */
   /*===========================================*/

   if ((EvaluationData(theEnv)->CurrentEvaluationDepth == 0) && (! CommandLineData(theEnv)->EvaluatingTopLevelCommand) &&
       (EvaluationData(theEnv)->CurrentExpression == NULL))
     { PeriodicCleanup(theEnv,TRUE,FALSE); }

   /*===========================*/
   /* Clear has been completed. */
   /*===========================*/

   ConstructData(theEnv)->ClearInProgress = FALSE;
   return TRUE;
  }