示例#1
0
main()
{
  vector<FSM::SEAEdge> eventArray;
  for(unsigned i=0; eventsExpected[i].eventId!=-1; i++)
  {
    eventArray.push_back(eventsExpected[i]); 
  }

  FSM::SEAFSM fsm(eventArray);
  fsm.print();

  int evtId;
  while(1) {
    cout << "eventId(-1 means end): ";
    cin >> evtId;
    if(evtId == -1)  {
      break;
    }
    fsm.processEvent(evtId);
  }

  if(!fsm.isInFinalState()) 
  {
    list<int> nextPossibleEvents = fsm.suggestNextEvents();
    list<int>::const_iterator cit= nextPossibleEvents.begin();
    cout << "Next possible events:" << endl;
    for( ; cit!=nextPossibleEvents.end(); cit++) {
      cout << "eventId:" << *cit << endl;
    }
  }
}
示例#2
0
int main(int argc, char *argv[])
{
  list<int> finalStates;
  finalStates.push_back(5);
  finalStates.push_back(4);

  FSM::GraphFSM fsm(stateTransitions,finalStates);
  fsm.print();

  int evtId;
  while(1) {
    cout << "eventId(-1 means end): ";
    cin >> evtId;
    if(evtId == -1)  {
      break;
    }
    fsm.processEvent(evtId);
  }

  if(!fsm.isInFinalState()) 
  {
    list<int> nextPossibleEvents = fsm.suggestNextEvents();
    list<int>::const_iterator cit= nextPossibleEvents.begin();
    cout << "Next possible events:" << endl;
    for( ; cit!=nextPossibleEvents.end(); cit++) {
      cout << "eventId:" << *cit << endl;
    }
  }

  return 0;
}
示例#3
0
static void listenTimeout(void *arg)
{
	bcm_p2p_discovery_t *disc = (bcm_p2p_discovery_t *)arg;

	WL_TRACE(("listenTimeout callback\n"));
	fsm(disc, EVENT_LISTEN_TIMEOUT);
}
示例#4
0
文件: core.c 项目: bobbens/LACE
/**
 * @brief Main entry point.
 */
int main (void)
{
   event_t evt;

   /* Disable watchdog timer since it doesn't always get reset on restart. */
   wdt_disable();     

   /* Initialize the MCU. */
   init();

   /* Online. */
   printf( "Exocore Apollo online...\n" );

   /* Start fsm. */
   fsm_start();

   for (;;) {
      /* Atomic test to see if has anything to do. */
      cli();

      /* Handle events. */
      while (event_poll(&evt)) {
         sei(); /* Reenable interrupts. */
         fsm( &evt );
         cli(); /* Disable for next check. */
      }

      /* Atomic sleep as specified on the documentation. */
      sleep_enable();
      sei();
      sleep_cpu();
      sleep_disable();
   }
}
SIPTransaction::Ptr SIPTransaction::findBranch(const SIPMessage::Ptr& pRequest)
{
  //
  // Only a parent transaction can have branches
  //
  if(!isParent())
    return SIPTransaction::Ptr();

  OSS::mutex_critic_sec_lock lock(_branchesMutex);
  SIPTransaction::Ptr foundBranch;
  std::string branch = pRequest->getToTag();
  if (branch.empty())
    return SIPTransaction::Ptr();

  Branches::iterator pBranch = _branches.find(branch);
  
  //
  // Branch is non-existent.  Create a new one and attach a new FSM to it
  //
  if (pBranch == _branches.end())
  {
    foundBranch = SIPTransaction::Ptr(new SIPTransaction(shared_from_this()));
    _owner->onAttachFSM(foundBranch);
    foundBranch->fsm()->setRequest(fsm()->getRequest());
    foundBranch->_owner = _owner;
    foundBranch->_responseTU = _responseTU;
    _branches[branch] = foundBranch;
  }
  else
  {
    foundBranch = pBranch->second;
  }
  return foundBranch;
}
TEST(TlMatrix_RLHD_file, constructer_by_existed) {
  TlMatrix_RLHD sm(100);
  {
    sm(3, 17) = 51.0;
    sm(0, 28) = -1.0;
    sm.save(mat_path);
  }

  TlMatrix_RLHD_file fsm(mat_path);
}
示例#7
0
static void start_discovery_handler(bcm_p2p_discovery_t *disc,
	int reqLength, bcm_p2p_discovery_req_t *req, void *rspNull)
{
	(void)rspNull;
	if (disc == 0 || reqLength != sizeof(bcm_p2p_discovery_req_t) || req == 0) {
		WL_ERROR(("invalid parameter\n"));
		return;
	}
	WL_TRACE(("start_discovery_handler\n"));
	fsm(disc, EVENT_START_DISCOVERY);
}
示例#8
0
void NavigationState::execute( float timeElapsed )
{
   if ( !m_waitingForQueryResults && m_uic->isKeyPressed( VK_LBUTTON ) )
   {
      TamySceneWidget& sceneWidget = fsm().getSceneWidget();

      // issue an object selection command
      sceneWidget.localToViewport( sceneWidget.getMousePos(), m_queryPos );
      sceneWidget.queryScene( *this );
      m_waitingForQueryResults = true;
   }
}
示例#9
0
static void start_ext_listen_handler(bcm_p2p_discovery_t *disc,
	int reqLength, bcm_p2p_discovery_req_t *req, void *rspNull)
{
	(void)rspNull;
	if (disc == 0 || reqLength != sizeof(bcm_p2p_discovery_req_t) || req == 0) {
		WL_ERROR(("invalid parameter\n"));
		return;
	}
	WL_TRACE(("start_ext_listen_handler %d %d\n",
		req->startExtListen.listenOnTimeout,
		req->startExtListen.listenOffTimeout));
	disc->extListenOnTimeout = req->startExtListen.listenOnTimeout;
	disc->extListenOffTimeout = req->startExtListen.listenOffTimeout;
	fsm(disc, EVENT_START_EXT_LISTEN);
}
TEST(TlMatrix_RLHD_file, get) {
  TlMatrix_RLHD sm(100);
  sm(3, 17) = 51.0;
  sm(0, 28) = -1.0;
  sm.save(mat_path);

  TlMatrix_RLHD_file fsm(mat_path);

  EXPECT_DOUBLE_EQ(0.0, fsm.get(0, 0));
  EXPECT_DOUBLE_EQ(0.0, fsm.get(0, 99));
  EXPECT_DOUBLE_EQ(0.0, fsm.get(99, 0));
  EXPECT_DOUBLE_EQ(0.0, fsm.get(99, 99));
  EXPECT_DOUBLE_EQ(51.0, fsm.get(3, 17));
  EXPECT_DOUBLE_EQ(-1.0, fsm.get(0, 28));
}
TEST(TlMatrix_RLHD_file, constructer) {
  {
    cleanup();
    TlMatrix_RLHD_file fsm(mat_path, 100);
  }

  {
    TlMatrix_RLHD a;
    a.load(mat_path);
    EXPECT_EQ(100, a.getNumOfRows());
    EXPECT_EQ(100, a.getNumOfCols());
    for (int r = 0; r < 100; ++r) {
      for (int c = 0; c <= r; ++c) {
        EXPECT_DOUBLE_EQ(0.0, a.get(r, c));
      }
    }
  }
}
示例#12
0
文件: rfc3986.hpp 项目: semenovf/pfs
bool uri<StringT>::parse (typename string_type::const_iterator first
            , typename string_type::const_iterator last)
{
    typedef uri_grammar<StringT>   grammar_type;
    typedef typename grammar_type::fsm_type fsm_type;

    // Initialize grammar's static members
    static grammar_type grammar;

    _d.clear();

    fsm_type fsm(grammar.p_uri_tr, & _d);
    typename fsm_type::result_type r = fsm.exec(0, first, last);

    if (r.first && r.second == last)
        return true;

    return false;
}
示例#13
0
int sc_main(int ac, char **av)
{
  sc_signal<bool> handshake ("HS");
  sc_signal<bool> found;
  sc_signal<char> stream ("ST");

  sc_clock clk("Clock", 20, SC_NS, 0.5, 0.0, SC_NS);

  counter cnt("COUNTER", clk, found);
  fsm_recognizer fsm("Recog", clk, stream, handshake, found);
  stimgen chargen("TESTB", clk, stream, handshake);

  // initialize signals - ali
  handshake = false;
  found = false;

  sc_start();
  return 0;
}
/**
* ====================================================================
* get_direction fn:
*   assigns state based on sentinel var and calls the fsm to determine
*   direction. This function calls back to Java with an int
*   (direction) which will allow java to broadcast the input to other
*   apps.
* ====================================================================
* authors(s): Stephan Greto-McGrath
* ====================================================================
*/
void get_direction(char buf1[8], char buf2[8], JNIEnv *newEnv, jobject obj, jmethodID mid){
    if (sentinel != true) {  /* we already have a prev state */
        previousState = currentState;
        currentState = concantenate(atoi(buf1), atoi(buf2));
        /* In case poll returns constantly, this statement below
         * ensures that we only consider a change in state.
         * Unnecessary if poll() is working properly with interrupts
         */
        if (previousState != currentState) {
            int direction = fsm(currentState, previousState);
            LOGD("direction: %d\n", direction);
            /* call back to java to broadcast state change*/
            (*newEnv)->CallVoidMethod(newEnv, obj, mid, (jint)direction);
        }
    } else { /* just starting -> need prev state */
        currentState = concantenate(atoi(buf1), atoi(buf2));
        sentinel = false;
    }
}
TEST(TlMatrix_RLHD_file, set) {
  cleanup();
  {
    TlMatrix_RLHD_file fsm(mat_path, 100);

    fsm.set(3, 17, 51.0);
    fsm.set(0, 28, -1.0);
  }

  TlMatrix_RLHD sm;
  sm.load(mat_path);

  EXPECT_EQ(100, sm.getNumOfRows());
  EXPECT_EQ(100, sm.getNumOfCols());
  EXPECT_DOUBLE_EQ(0.0, sm(0, 0));
  EXPECT_DOUBLE_EQ(0.0, sm(0, 99));
  EXPECT_DOUBLE_EQ(0.0, sm(99, 0));
  EXPECT_DOUBLE_EQ(0.0, sm(99, 99));
  EXPECT_DOUBLE_EQ(51.0, sm(3, 17));
  EXPECT_DOUBLE_EQ(-1.0, sm(0, 28));
}
示例#16
0
bool parse (json & result, string const & s)
{
	user_context userContext;
	notification nx;

	parse_context ctx = {
		  & userContext
		, & nx
		, true // isBeginJson
		, string() // memberName
		, stack<string>() // objects
		, stack<string>() // arrays;
		, on_begin_json
		, on_end_json
		, on_begin_object
		, on_end_object
		, on_begin_array
		, on_end_array
		, on_null_value
		, on_boolean_value
		, on_number_value
		, on_string_value
	};

	userContext.ptr_stack.push(& result);

	fsm::fsm<string> fsm(json_fsm, & ctx);
	fsm::fsm<string>::result_type r = fsm.exec(s.cbegin(), s.cend());

	if (r.first && r.second == s.cend()) {
		;
	} else {
		result.clear();
        return false;
	}

	return true;
}
示例#17
0
void NavigationState::commitSelectdEntities( const Array< Entity* >& selectedEntities )
{
   SelectionManager& selectionMgr = fsm().getSceneEditor().getSelectionMgr();

   uint count = selectedEntities.size();
   bool somethingSelected = false;
   for( uint i = 0; i < count; ++i )
   {
      // we want the manipulator to select only the scene nodes it can actually manipulate afterwards
      Entity* entity = selectedEntities[i];
      if ( entity )
      {
         // got a node to select
         selectionMgr.selectEntity( *entity );
         somethingSelected = true;
         break;
      }
   }

   if ( !somethingSelected )
   {
      selectionMgr.resetSelection();
   }
}
TEST(TlMatrix_RLHD_file, add) {
  {
    TlMatrix_RLHD sm(100);
    sm(3, 17) = 51.0;
    sm(0, 28) = -1.0;
    sm.save(mat_path);
  }

  {
    TlMatrix_RLHD_file fsm(mat_path);
    fsm.add(3, 17, 12.3);
  }

  TlMatrix_RLHD sm;
  sm.load(mat_path);
  EXPECT_EQ(100, sm.getNumOfRows());
  EXPECT_EQ(100, sm.getNumOfCols());
  EXPECT_DOUBLE_EQ(0.0, sm(0, 0));
  EXPECT_DOUBLE_EQ(0.0, sm(0, 99));
  EXPECT_DOUBLE_EQ(0.0, sm(99, 0));
  EXPECT_DOUBLE_EQ(0.0, sm(99, 99));
  EXPECT_DOUBLE_EQ(63.3, sm(3, 17));
  EXPECT_DOUBLE_EQ(-1.0, sm(0, 28));
}
示例#19
0
bool Abnf::parse(const String & abnf, AbnfRuleList & rulelist)
{
	CWT_UNUSED(abnf);
	AbnfParseContext ctx = {
		  & rulelist
		, Stack<AbnfElement *>()
		, 10  // numValBase
		, 0   // numValMin
		, 0   // numValMax
	};

/*
	AbnfContext abnfContext;
	abnfContext.isIncrementalAlternation = false;
*/
	/*
	AbnfParseContext ctx = {
		  & abnfContext
		, String()
		, {CWT_INT_MIN, CWT_INT_MIN}
		, api
	};
*/
	Fsm<String> fsm(rulelist_fsm, & ctx);

	String s(abnf);

	if (!s.endsWith(String::EndOfLine))
		s.append(String::EndOfLine);

	if (fsm.exec(0, s.begin(), s.end()) >= 0) {
		return true;
	}

	return false;
}
示例#20
0
static void create_handler(bcm_p2p_discovery_t *discNull,
	int reqLength, bcm_p2p_discovery_req_t *req, void *rspData)
{
	bcm_p2p_discovery_t *disc;
	create_rsp_t *rsp = (create_rsp_t *)rspData;

	(void)discNull;
	if (reqLength != sizeof(bcm_p2p_discovery_req_t) || req == 0 || rspData == 0) {
		WL_ERROR(("invalid parameter\n"));
		return;
	}
	WL_TRACE(("create_handler\n"));

#ifndef BCMDRIVER
	/* seed the random generator */
	srand((unsigned)time(NULL));
#endif /* BCMDRIVER */

	rsp->disc = 0;
	disc = &gDisc;
	memset(disc, 0, sizeof(*disc));

	disc->drv = req->create.drv;

	disc->listenChannel = req->create.listenChannel;

	/* initialize social channels */
	disc->socialChannel[0] = 1;
	disc->socialChannel[1] = 6;
	disc->socialChannel[2] = 11;

#ifdef BCM_P2P_DISCOVERY_CREATE_DISCOVERY_BSSCFG
	/* disable P2P discovery - to ensure bsscfg does not exist */
	wl_p2p_disc(disc->drv, FALSE);
	/* enable P2P discovery */
	wl_p2p_disc(disc->drv, TRUE);
#endif	/* BCM_P2P_DISCOVERY_CREATE_DISCOVERY_BSSCFG */

	if (wl_p2p_dev(disc->drv, &disc->bsscfgIndex) < 0) {
		WL_ERROR(("failed to get bsscfg index\n"));
	}
	WL_P2PO(("bsscfg index=%d\n", disc->bsscfgIndex));
#ifdef BCM_P2P_DISCOVERY_ADD_DELETE_IES
	wl_cur_etheraddr(disc->drv, disc->bsscfgIndex, &disc->addr);
	WL_PRMAC("discovery MAC address", &disc->addr);
#endif /* BCM_P2P_DISCOVERY_ADD_DELETE_IES */

#ifdef BCM_P2P_DISCOVERY_ADD_DELETE_IES
	addIes(disc);
#endif	/* BCM_P2P_DISCOVERY_ADD_DELETE_IES */

	/* create timers */
	disc->listenTimer = tmrCreate(
#ifndef BCMDRIVER
		dsp(),
#else
		disc->drv,
#endif	/* BCMDRIVER */
		listenTimeout, disc, "listenTimer");
	if (disc->listenTimer == 0) {
		WL_ERROR(("failed to create timer\n"));
		goto fail;
	}

	/* reset state machine */
	fsm(disc, EVENT_RESET);

	/* return created instance */
	rsp->disc = disc;
	return;

fail:
	memset(disc, 0, sizeof(*disc));
}
示例#21
0
int main(int argc, char *argv[])
{
    argumentNumberMessage(argc);
    fsm(argv[1]);
    return 0;
}
示例#22
0
void NavigationState::setResult( const Array< Entity* >& foundEntities )
{
   m_waitingForQueryResults = false;

   // analyze the found entities and determine what ( if any ) spatial entities were found,
   // and whether a gizmo axis was selected
   GizmoAxis* selectedGizmoAxis = NULL;
   Array< Entity* > selectedEntities;

   {
      uint count = foundEntities.size();
      for ( uint i = 0; i < count; ++i )
      {
         Entity* foundEntity = foundEntities[i];
         if ( !foundEntity )
         {
            continue;
         }

         // first a quick test to see if the selected entity is a gizmo axis
         if ( foundEntity->isA< GizmoAxis >() )
         {
            ASSERT_MSG( selectedGizmoAxis == NULL, "Only one scene with gizmo is allowed with this query listener, and here we've found the second gizmo axis already" );

            // yup - memorize it and go to the next one
            selectedGizmoAxis = DynamicCast< GizmoAxis >( foundEntity );

            // and go to the next item on the list
            continue;
         }

         // next - determine if the entity is a spatial entity
         {
            Entity* spatialEntityCandidate = foundEntity;
            while( spatialEntityCandidate && !spatialEntityCandidate->isA< SpatialEntity >() )
            {
               // find a parent of the entity that's a node
               spatialEntityCandidate = spatialEntityCandidate->getParent();
            }

            if ( spatialEntityCandidate != NULL )
            {
               // we found it
               SpatialEntity* node = DynamicCast< SpatialEntity >( spatialEntityCandidate );
               selectedEntities.push_back( node );
            }
         }
      }
   }

 
   if ( selectedGizmoAxis && m_uic->isKeyPressed( VK_LBUTTON ) )
   {
      // if a gizmo axis was selected ( and the selection button is still pressed ) then it means we want to manipulate the selected object.
      // At this point we're no longer interested in any other selected objects
      ASSERT_MSG( fsm().areNodesSelected(), "There are no selected nodes, and yet we managed to select a manipulation gizmo somehow. Check it!" );
      transitionTo< GizmoNodeManipulationState >().setGizmoAxis( *selectedGizmoAxis );
   }
   else
   {
      // analyze the selected spatial entities
      SelectionManager& selectionMgr = fsm().getSceneEditor().getSelectionMgr();
      const std::vector< Entity* >& currentlySelectedEntities = selectionMgr.getSelectedEntities();
  
      // if both selections were exactly the same ( meaning that we clicked on one of the previously selected
      // vehicles, then instead of committing the selection, transition to a planar node movement mode
      if ( CollectionUtils::containsAll( currentlySelectedEntities, selectedEntities ) )
      {
         transitionTo< PlanarNodeManipulationState >();
      }
      else
      {
         // the selection has changed - commit the nnew one
         commitSelectdEntities( selectedEntities );
      }
   }
}
示例#23
0
void NavigationState::deactivate()
{
   fsm().setController( NULL );
}
示例#24
0
void NavigationState::activate()
{
   fsm().setController( new CameraMovementController() ); 
}
示例#25
0
int
main(int cc, char **vv)
{
     int	ch, disco;
     char	*pname, *pidfile, *p, *q, *ta, *kw, *v;
     isc_opt_t	*op;
     FILE	*fd;
     size_t	n;

     op = &opvals;
     iscsidev = "/dev/"ISCSIDEV;
     fd = NULL;
     pname = vv[0];
     if ((pname = basename(pname)) == NULL)
	  err(1, "basename");

     kw = ta = 0;
     disco = 0;
     pidfile = NULL;
     /*
      | check for driver & controller version match
      */
     n = 0;
#define VERSION_OID_S	"net.iscsi_initiator.driver_version"
     if (sysctlbyname(VERSION_OID_S, 0, &n, 0, 0) != 0) {
	  if (errno == ENOENT)
		errx(1, "sysctlbyname(\"" VERSION_OID_S "\") "
			"failed; is the iscsi driver loaded?");
	  err(1, "sysctlbyname(\"" VERSION_OID_S "\")");
     }
     v = malloc(n+1);
     if (v == NULL)
	  err(1, "malloc");
     if (sysctlbyname(VERSION_OID_S, v, &n, 0, 0) != 0)
	  err(1, "sysctlbyname");

     if (strncmp(version, v, 3) != 0)
	  errx(1, "versions mismatch");

     while((ch = getopt(cc, vv, OPTIONS)) != -1) {
	  switch(ch) {
	  case 'v':
	       vflag++;
	       break;
	  case 'c':
	       fd = fopen(optarg, "r");
	       if (fd == NULL)
		    err(1, "fopen(\"%s\")", optarg);
	       break;
	  case 'd':
	       disco = 1;
	       break;
	  case 't':
	       ta = optarg;
	       break;
	  case 'n':
	       kw = optarg;
	       break;
	  case 'p':
	       pidfile = optarg;
	       break;
	  default:
	       usage(pname);
	  }
     }
     if(fd == NULL)
	  fd = fopen("/etc/iscsi.conf", "r");

     if(fd != NULL) {
	  parseConfig(fd, kw, op);
	  fclose(fd);
     }
     cc -= optind;
     vv += optind;
     if(cc > 0) {
	  if(vflag)
	       printf("adding '%s'\n", *vv);
	  parseArgs(cc, vv, op);
     }
     if(ta)
	  op->targetAddress = ta;

     if(op->targetAddress == NULL) {
	  warnx("no target specified!");
	  usage(pname);
     }
     q = op->targetAddress;
     if(*q == '[' && (q = strchr(q, ']')) != NULL) {
	  *q++ = '\0';
	  op->targetAddress++;
     } else
	  q = op->targetAddress;
     if((p = strchr(q, ':')) != NULL) {
	  *p++ = 0;
	  op->port = atoi(p);
	  p = strchr(p, ',');
     }
     if(p || ((p = strchr(q, ',')) != NULL)) {
	  *p++ = 0;
	  op->targetPortalGroupTag = atoi(p);
     }
     if(op->initiatorName == 0) {
	  char	hostname[MAXHOSTNAMELEN];

	  if(op->iqn) {
	       if(gethostname(hostname, sizeof(hostname)) == 0)
		    asprintf(&op->initiatorName, "%s:%s", op->iqn, hostname);
	       else
		    asprintf(&op->initiatorName, "%s:%d", op->iqn, (int)time(0) & 0xff); // XXX:
	  }
	  else {
	       if(gethostname(hostname, sizeof(hostname)) == 0)
		    asprintf(&op->initiatorName, "%s", hostname);
	       else
		    asprintf(&op->initiatorName, "%d", (int)time(0) & 0xff); // XXX:
	  }
     }
     if(disco) {
	  op->sessionType = "Discovery";
	  op->targetName = 0;
     }
     op->pidfile = pidfile;
     fsm(op);

     exit(0);
}
示例#26
0
int
main(int cc, char **vv)
{
     int	ch, disco;
     char	*pname, *p, *q, *ta, *kw;
     isc_opt_t	*op;
     FILE	*fd;

     /* Try to load iscsi_initiator module before starting its operation */
     if (modfind(INITIATORMOD) < 0) {
	     if (kldload(INITIATORMOD) < 0 || modfind(INITIATORMOD) < 0) {
		     perror(INITIATORMOD ": Error while handling kernel module");
		     return 1;
	     }
     }

     op = &opvals;
     iscsidev = "/dev/"ISCSIDEV;
     fd = NULL;
     pname = vv[0];
     if((p = strrchr(pname, '/')) != NULL)
	  pname = p + 1;

     kw = ta = NULL;
     disco = 0;

     while((ch = getopt(cc, vv, OPTIONS)) != -1) {
	  switch(ch) {
	  case 'v':
	       vflag++;
	       break;
	  case 'c':
	       fd = fopen(optarg, "r");
	       if(fd == NULL) {
		    perror(optarg);
		    exit(1);
	       }
	       break;
	  case 'd':
	       disco = 1;
	       break;
	  case 't':
	       ta = optarg;
	       break;
	  case 'n':
	       kw = optarg;
	       break;
	  default:
	  badu:
	       fprintf(stderr, "Usage: %s %s\n", pname, USAGE);
	       exit(1);
	  }
     }
     if(fd == NULL)
	  fd = fopen("/etc/iscsi.conf", "r");

     if(fd != NULL) {
	  parseConfig(fd, kw, op);
	  fclose(fd);
     }
     cc -= optind;
     vv += optind;
     if(cc > 0) {
	  if(vflag)
	       printf("adding '%s'\n", *vv);
	  parseArgs(cc, vv, op);
     }
     if(ta)
	  op->targetAddress = ta;

     if(op->targetAddress == NULL) {
	  fprintf(stderr, "No target!\n");
	  goto badu;
     }
     q = op->targetAddress;
     if(*q == '[' && (q = strchr(q, ']')) != NULL) {
	  *q++ = '\0';
	  op->targetAddress++;
     } else
	  q = op->targetAddress;
     if((p = strchr(q, ':')) != NULL) {
	  *p++ = 0;
	  op->port = atoi(p);
	  p = strchr(p, ',');
     }
     if(p || ((p = strchr(q, ',')) != NULL)) {
	  *p++ = 0;
	  op->targetPortalGroupTag = atoi(p);
     }
     if(op->initiatorName == 0) {
	  char	hostname[256];

	  if(op->iqn) {
	       if(gethostname(hostname, sizeof(hostname)) == 0)
		    asprintf(&op->initiatorName, "%s:%s", op->iqn, hostname);
	       else
		    asprintf(&op->initiatorName, "%s:%d", op->iqn, (int)time(0) & 0xff); // XXX:
	  }
	  else {
	       if(gethostname(hostname, sizeof(hostname)) == 0)
		    asprintf(&op->initiatorName, "%s", hostname);
	       else
		    asprintf(&op->initiatorName, "%d", (int)time(0) & 0xff); // XXX:
	  }
     }
     if(disco) {
	  op->sessionType = "Discovery";
	  op->targetName = 0;
     }

     fsm(op);

     exit(0);
}
示例#27
0
文件: syntax.cpp 项目: djdron/zxtune
 void ParseFormatNotation(const std::string& notation, FormatTokensVisitor& visitor)
 {
   ParseFSM fsm(visitor);
   CreateFormatGrammar()->Analyse(notation, fsm);
 }
示例#28
0
void bcm_p2p_discovery_process_wlan_event(void * context, uint32 eventType,
	wl_event_msg_t *wlEvent, uint8 *data, uint32 length)
{
	bcm_p2p_discovery_t *disc = &gDisc;
	(void)context;
#ifndef BCMDBG_ESCAN
	(void)data;
	(void)length;
#endif

#ifdef BCMDBG
	{
		int i;
		char *event_name = "UNKNOWN";

		for (i = 0; i < bcmevent_names_size; i++)
			if (bcmevent_names[i].event == eventType)
				event_name = (char *)bcmevent_names[i].name;

		WL_P2PO(("WLAN event %s (%d)\n", event_name, eventType));
	}
#endif	/* BCMDBG */

	if (eventType == WLC_E_ESCAN_RESULT) {
		if (wlEvent->status == WLC_E_STATUS_PARTIAL) {
#ifdef BCMDBG_ESCAN
			wl_escan_result_t *escan_data = (wl_escan_result_t *)data;

			if (length >= sizeof(*escan_data)) {
				wl_bss_info_t *bi = &escan_data->bss_info[0];
				bcm_decode_probe_response_t pr;
				struct ether_addr *addr;

				if (!bcm_decode_ie_probe_response(bi, &pr)) {
					return;
				}

				/* default address */
				addr = &bi->BSSID;

				/* P2P not supported */
				if (!pr.isP2P) {
					char ssidbuf[4*32+1];
					wl_format_ssid(ssidbuf, bi->SSID, bi->SSID_len);
					dbg(" AP   %-20.20s   %s   %d\n", ssidbuf,
						wl_ether_etoa(addr), pr.channel);
					return;
				}

				if (pr.isP2PDeviceInfoDecoded) {
					/* use device address */
					addr = &pr.p2pDeviceInfo.deviceAddress;
					dbg("P2P   %-20.20s   %s   %d\n",
						pr.p2pDeviceInfo.deviceName,
						wl_ether_etoa(addr), pr.channel);
				}
			}
#endif /* BCMDBG_ESCAN */
		}
		else if (wlEvent->status == WLC_E_STATUS_SUCCESS) {
			WL_P2PO(("WLC_E_ESCAN_RESULT status=WLC_E_STATUS_SUCCESS\n"));
			fsm(disc, EVENT_SCAN_COMPLETE);
		}
		else {
			WL_P2PO(("WLC_E_ESCAN_RESULT status=%d\n", wlEvent->status));
			/* escan may have failed/restarted but keep state machine running */
			fsm(disc, EVENT_SCAN_COMPLETE);
		}
	}
}
示例#29
0
void STest::init(const std::vector<Pattern>& pats) {
  std::unique_ptr<PatternHandle,void(*)(PatternHandle*)> pat(
    lg_create_pattern(),
    lg_destroy_pattern
  );

  PMap = std::unique_ptr<PatternMapHandle,void(*)(PatternMapHandle*)>(
    lg_create_pattern_map(pats.size()),
    lg_destroy_pattern_map
  );

  std::unique_ptr<FSMHandle,void(*)(FSMHandle*)> fsm(
    lg_create_fsm(0),
    lg_destroy_fsm
  );

  LG_KeyOptions keyOpts;

  size_t i = 0, numErrors = 0;
  for (const Pattern& p : pats) {
    LG_Error* err = nullptr;

    keyOpts.CaseInsensitive = p.CaseInsensitive;
    keyOpts.FixedString = p.FixedString;

    lg_parse_pattern(pat.get(), p.Expression.c_str(), &keyOpts, &err);

    if (!err) {
      lg_add_pattern(
        fsm.get(), PMap.get(), pat.get(), p.Encoding.c_str(), &err
      );

      if (!err) {
        // pack the user pattern number into the void*, oh the horror
        LG_PatternInfo* pinfo = lg_pattern_info(PMap.get(), i - numErrors);
        pinfo->UserData = reinterpret_cast<void*>(i);
      }
    }

    if (err) {
      lg_free_error(err);
      ++numErrors;
    }

    ++i;
  }

  LG_ProgramOptions progOpts{1};

  Prog = std::unique_ptr<ProgramHandle,void(*)(ProgramHandle*)>(
    lg_create_program(fsm.get(), &progOpts),
    lg_destroy_program
  );

  if (Prog) {
    LG_ContextOptions ctxOpts;

    Ctx = std::unique_ptr<ContextHandle,void(*)(ContextHandle*)>(
      lg_create_context(Prog.get(), &ctxOpts),
      lg_destroy_context
    );
  }
}
示例#30
0
int main() {
  std::string input ("0110100010010001101001000111110010011001");
  std::for_each(input.begin(), input.end(), fsm());
  std::cout <<"\n";
}