Esempio n. 1
0
void tst_IrcCommand::testQuote()
{
    QScopedPointer<IrcCommand> cmd1(IrcCommand::createQuote("CUSTOM"));
    QVERIFY(cmd1.data());

    QCOMPARE(cmd1->type(), IrcCommand::Quote);
    QVERIFY(cmd1->toString().contains(QRegExp("\\bCUSTOM\\b")));

    QScopedPointer<IrcCommand> cmd2(IrcCommand::createQuote(QStringList() << "FOO" << "BAR"));
    QVERIFY(cmd2.data());

    QCOMPARE(cmd2->type(), IrcCommand::Quote);
    QVERIFY(cmd2->toString().contains(QRegExp("\\bFOO\\b")));
    QVERIFY(cmd2->toString().contains(QRegExp("\\bBAR\\b")));
}
Esempio n. 2
0
void tst_IrcCommand::testPart()
{
    QScopedPointer<IrcCommand> cmd1(IrcCommand::createPart("chan"));
    QVERIFY(cmd1.data());

    QCOMPARE(cmd1->type(), IrcCommand::Part);
    QVERIFY(cmd1->toString().contains(QRegExp("\\bPART\\b")));
    QVERIFY(cmd1->toString().contains(QRegExp("\\bchan\\b")));

    QScopedPointer<IrcCommand> cmd2(IrcCommand::createPart(QStringList() << "chan1" << "chan2"));
    QVERIFY(cmd2.data());

    QCOMPARE(cmd2->type(), IrcCommand::Part);
    QVERIFY(cmd2->toString().contains(QRegExp("\\bPART\\b")));
    QVERIFY(cmd2->toString().contains(QRegExp("\\bchan1\\b")));
    QVERIFY(cmd2->toString().contains(QRegExp("\\bchan2\\b")));
}
Esempio n. 3
0
int main()
{
    int i, j, k, n, m, ins;
    scanf("%d %d", &n, &m);
    scanf("%s", s);
    while (m--)
    {
        scanf("%s %d", cmd, &ins);
        switch (ins)
        {
        case 1: scanf("%d %d %c", &i, &j, &c); cmd1(i, j, c); break;
        case 2: scanf("%d %d %d", &i, &j, &k); cmd2(i, j, k); break;
        case 3: scanf("%d", &k);               cmd3(k, n);    break;
        case 4: scanf("%d %d", &i, &j);        cmd4(i, j);    break;
        }
    }
    printf("%s\n", s);
    return 0;
}
Esempio n. 4
0
void tst_IrcCommand::testCapability()
{
    QScopedPointer<IrcCommand> cmd1(IrcCommand::createCapability("sub", QString("cap")));
    QVERIFY(cmd1.data());

    QCOMPARE(cmd1->type(), IrcCommand::Capability);
    QVERIFY(cmd1->toString().contains(QRegExp("\\bCAP\\b")));
    QVERIFY(cmd1->toString().contains(QRegExp("\\bsub\\b")));
    QVERIFY(cmd1->toString().contains(QRegExp("\\bcap\\b")));

    QScopedPointer<IrcCommand> cmd2(IrcCommand::createCapability("sub", QStringList() << "cap1" << "cap2"));
    QVERIFY(cmd2.data());

    QCOMPARE(cmd2->type(), IrcCommand::Capability);
    QVERIFY(cmd2->toString().contains(QRegExp("\\bCAP\\b")));
    QVERIFY(cmd2->toString().contains(QRegExp("\\bsub\\b")));
    QVERIFY(cmd2->toString().contains(QRegExp("\\bcap1\\b")));
    QVERIFY(cmd2->toString().contains(QRegExp("\\bcap2\\b")));
}
Esempio n. 5
0
TEST(IndexUpdateCommandTest, TestParseArgs) {
  IndexUpdateCommand cmd(IndexUpdateCommand::IndexOp::UPDATE);
  vector<string> strargs = {"insert", "--stdin", "energy"};
  auto args = create_args(strargs);
  EXPECT_EQ(0, cmd.parse_args(args.size(), &args[0]));
  EXPECT_TRUE(cmd.use_stdin_);
  EXPECT_EQ("energy", cmd.name_);
  EXPECT_EQ(IndexUpdateCommand::IndexOp::UPDATE, cmd.op_);

  IndexUpdateCommand cmd1(IndexUpdateCommand::IndexOp::UPDATE);
  strargs = {"insert", "energy", "file0", "key0", "file1", "key1"};
  args = create_args(strargs);
  EXPECT_EQ(0, cmd1.parse_args(args.size(), &args[0]));
  EXPECT_EQ("energy", cmd1.name_);
  EXPECT_EQ(2, cmd1.index_data_.size());

  // Missing file,key pair.
  IndexUpdateCommand cmd2(IndexUpdateCommand::IndexOp::UPDATE);
  strargs = {"insert", "energy", "file0", "key0", "file1", "key1", "file2"};
  args = create_args(strargs);
  EXPECT_EQ(-1, cmd2.parse_args(args.size(), &args[0]));
}
Esempio n. 6
0
File: test.cpp Progetto: esohns/ATCD
int ACE_TMAIN (int argc, ACE_TCHAR** argv)
{
  Kokyu::ConfigInfoSet config_info(3);

  int  hi_prio, me_prio, lo_prio;
  int sched_policy=ACE_SCHED_FIFO;

  Kokyu::Dispatcher_Attributes attrs;

  if (parse_args (argc, argv) == -1)
    return 0;

  if (ACE_OS::strcasecmp(sched_policy_str.c_str(), "fifo") == 0)
    {
      sched_policy = ACE_SCHED_FIFO;
    }
  else if (ACE_OS::strcasecmp(sched_policy_str.c_str(), "other") == 0)
    {
      sched_policy = ACE_SCHED_OTHER;
    }
  else if (ACE_OS::strcasecmp(sched_policy_str.c_str(), "rr") == 0)
    {
      sched_policy = ACE_SCHED_RR;
    }

  attrs.sched_policy (sched_policy);

  hi_prio = ACE_Sched_Params::priority_max (sched_policy);
  me_prio = ACE_Sched_Params::previous_priority (sched_policy,
                                                 hi_prio);
  lo_prio = ACE_Sched_Params::previous_priority (sched_policy,
                                                 me_prio);

  config_info[0].preemption_priority_ = 1;
  config_info[0].thread_priority_ = hi_prio ;
  config_info[0].dispatching_type_ = Kokyu::FIFO_DISPATCHING;

  config_info[1].preemption_priority_ = 2;
  config_info[1].thread_priority_ = me_prio;
  config_info[1].dispatching_type_ = Kokyu::FIFO_DISPATCHING;

  config_info[2].preemption_priority_ = 3;
  config_info[2].thread_priority_ = lo_prio;
  config_info[2].dispatching_type_ = Kokyu::FIFO_DISPATCHING;

  attrs.config_info_set_ = config_info;

  ACE_DEBUG ((LM_DEBUG, "before create_dispatcher\n" ));
  auto_ptr<Kokyu::Dispatcher>
    disp (Kokyu::Dispatcher_Factory::create_dispatcher (attrs));

  ACE_ASSERT (disp.get() != 0);

  MyCommand cmd1(1), cmd2(2), cmd3(3);

  Kokyu::QoSDescriptor qos1, qos2, qos3;

  qos1.preemption_priority_ = 2;
  ACE_DEBUG ((LM_DEBUG, "Priority of command1 is %d\n",
              qos1.preemption_priority_));

  qos2.preemption_priority_ = 3;
  ACE_DEBUG ((LM_DEBUG, "Priority of command2 is %d\n",
              qos2.preemption_priority_));

  qos3.preemption_priority_ = 1;
  ACE_DEBUG ((LM_DEBUG, "Priority of command3 is %d\n",
              qos3.preemption_priority_));

  if (disp->dispatch (&cmd1, qos1) == -1 ||
      disp->dispatch (&cmd2, qos2) == -1 ||
      disp->dispatch (&cmd3, qos3) == -1)
    ACE_ERROR_RETURN ((LM_ERROR, "Error in dispatching command object\n"), -1);

  if (disp->activate () == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("Error activating dispatcher. ")
                         ACE_TEXT ("You might not have superuser privileges ")
                         ACE_TEXT ("to run FIFO class. Try \"-p other\"\n")), -1);
    }

  disp->shutdown ();

  ACE_DEBUG ((LM_DEBUG, "after shutdown\n"));
  return 0;
}
void TestPageCommands::testMakePageSpread()
{
    KWDocument document;
    KWPageManager *manager = document.pageManager();

    KWPageStyle style("pagestyle1");
    const KoPageLayout oldLayout = style.pageLayout();
    KoPageLayout layout = style.pageLayout();

    manager->addPageStyle(style);
    KWPage page1 = manager->appendPage(style);
    QCOMPARE(page1.width(), layout.width);
    QCOMPARE(page1.pageNumber(), 1);
    QCOMPARE(page1.pageSide(), KWPage::Right);
    QCOMPARE(manager->pageCount(), 1);

    // make it a pagespread
    KWPageStyle pageSpread = style;
    pageSpread.detach("dummy");
    layout.leftMargin = -1;
    layout.rightMargin = -1;
    layout.pageEdge = 7;
    layout.bindingSide = 13;
    pageSpread.setPageLayout(layout);

    KWPageStylePropertiesCommand cmd1(&document, style, pageSpread);
    cmd1.redo();
    QCOMPARE(page1.pageNumber(), 1);
    QCOMPARE(page1.pageSide(), KWPage::Right);
    QCOMPARE(page1.width(), style.pageLayout().width);
    QCOMPARE(manager->pageCount(), 1);
    KoPageLayout newLayout = style.pageLayout();
    QCOMPARE(newLayout.width, layout.width);
    QCOMPARE(newLayout.leftMargin, layout.leftMargin);
    QCOMPARE(newLayout.rightMargin, layout.rightMargin);
    QCOMPARE(newLayout.pageEdge, layout.pageEdge);
    QCOMPARE(newLayout.bindingSide, layout.bindingSide);

    cmd1.undo();
    QCOMPARE(page1.width(), oldLayout.width);
    QCOMPARE(page1.pageNumber(), 1);
    QCOMPARE(page1.pageSide(), KWPage::Right);
    QCOMPARE(manager->pageCount(), 1);

    // create another page. So we have 2 single sided pages. (Right/Left)
    KWPage page2 = manager->appendPage(style);
    QCOMPARE(page2.width(), oldLayout.width);
    QCOMPARE(page2.pageNumber(), 2);
    QCOMPARE(page2.pageSide(), KWPage::Left);
    QCOMPARE(manager->pageCount(), 2);

    // avoid reusing cmd1 as that assumes the constructor doesn't do anything. Which is
    // not a restriction we put on the command. (i.e. that doesn't *have* to work)
    KWPageStylePropertiesCommand cmd2(&document, style, pageSpread);
    cmd2.redo();

    QCOMPARE(page1.width(), style.pageLayout().width);
    QCOMPARE(page1.pageNumber(), 1);
    QCOMPARE(page1.pageSide(), KWPage::Right);
    QCOMPARE(page2.pageNumber(), 2);
QEXPECT_FAIL("", "Not done yet", Abort);
    QCOMPARE(page2.pageSide(), KWPage::PageSpread);
    QCOMPARE(page2.width(), style.pageLayout().width * 2);
    QCOMPARE(manager->pageCount(), 3);

    cmd2.undo();
    // test for page side etc.
    QCOMPARE(page1.width(), oldLayout.width);
    QCOMPARE(page1.pageNumber(), 1);
    QCOMPARE(page1.pageSide(), KWPage::Right);
    QCOMPARE(page2.pageNumber(), 2);
    QCOMPARE(page2.pageSide(), KWPage::Left);
    QCOMPARE(page2.width(), oldLayout.width);
    QCOMPARE(manager->pageCount(), 2);
}
Esempio n. 8
0
void CCmd_ListOpStat::PreProcess(BOOL& done)
{
	int i;
	POSITION pos;

	CCmd_ListOp cmd1(m_pClient);
	
	// Set up and run ListOp synchronously
	cmd1.Init(NULL, RUN_SYNC);
	cmd1.SetChkForSyncs(m_ChkForSyncs);
	cmd1.SetWarnIfLocked(m_WarnIfLocked);
	if(cmd1.Run(m_pFileSpecs, m_Command, m_ChangeNumber, m_NewType))
	{
		m_FatalError= cmd1.GetError();
		done=TRUE;
		if (m_ChkForSyncs)
		{
			CStringList * pSyncList = cmd1.GetSyncList();
			if (!pSyncList->IsEmpty())
			{
				for( pos= pSyncList->GetHeadPosition(); pos!= NULL; )
					m_Unsynced.AddHead( pSyncList->GetNext(pos) );
				
				CStringList * pEditList = cmd1.GetList();
				for( pos= pEditList->GetHeadPosition(); pos!= NULL; )
				{
					CString txt = pEditList->GetNext(pos);
					if ((i = txt.Find(_T('#'))) != -1)
						txt = txt.Left(i);
					m_RevertIfCancel.AddHead( txt );
				}
			}
			else m_ChkForSyncs = FALSE;
		}
	}
	else
	{
		m_ErrorTxt= _T("Unable to Run ListOp");
		m_FatalError=TRUE;
	}
	// Extract the CStringList from ListOp, which has filtered
	// results for the command. Note that Errors, warnings and 
	// gee-whiz info have been thrown to the status window and 
	// are not in the list
	CStringList *strList= cmd1.GetList();

	// Check for huge file sets, where incremental screen update can take
	// a very looong time to complete.  We are more tolerant for repoens,
	// because they involve updates in only one pane
	if(!m_FatalError && m_Command== P4REOPEN && strList->GetCount() > (3 * MAX_FILESEEKS))
	{
		m_HitMaxFileSeeks= TRUE;
		TheApp()->StatusAdd(_T("CCmd_ListOpStat/P4REOPEN hit MAX_FILESEEKS - blowing off incremental update"), SV_DEBUG);
	}
	else if(!m_FatalError && m_Command!= P4REOPEN && strList->GetCount() > MAX_FILESEEKS)
	{
		m_HitMaxFileSeeks= TRUE;
		TheApp()->StatusAdd(_T("CCmd_ListOpStat hit MAX_FILESEEKS - blowing off incremental update"), SV_DEBUG);
	}

	// In the usual case of zero to a few hundred files, gather ostat-like info
	// for each file so that screen updates can be completed
	else if(!m_FatalError && strList->GetCount() > 0)
	{
		// Save a copy of the stringlist.
		for( pos= strList->GetHeadPosition(); pos!= NULL; )
			m_StrListOut.AddHead( strList->GetNext(pos) );

		// See if we need to run Ostat 
		if(m_Command==P4EDIT || m_Command==P4DELETE)
		{
			// Set up and run ostat synchronously
        	CCmd_Ostat cmd2(m_pClient);
			cmd2.Init(NULL, RUN_SYNC);
			if(cmd2.Run(FALSE, m_ChangeNumber))
				m_FatalError= cmd2.GetError();
			else
			{
				m_ErrorTxt= _T("Unable to Run Ostat");
				m_FatalError=TRUE;
			}
			
			CObArray const *array= cmd2.GetArray();	
			if(!m_FatalError && array->GetSize() > 0)
			{
				// Save a copy of the oblist.
				for( int i=0; i < array->GetSize(); i++ )
					m_StatList.AddHead( array->GetAt(i) );
			}
		}
		else
			PrepareStatInfo();
	}

	// Post the completion message
	if(!m_FatalError)
	{
		CString message;
		int already = 0;
		int reopened = 0;
		switch(m_Command)
		{
		case P4EDIT:
			for( pos= strList->GetHeadPosition(); pos!= NULL; )
			{
				CString str = strList->GetNext(pos);
				if (str.Find(_T(" - currently opened ")) != -1)
					already++;
				else if (str.Find(_T(" - reopened ")) != -1)
					reopened++;
			}
			message.FormatMessage(IDS_OPENED_n_FILES_FOR_EDIT, 
									strList->GetCount() - already - reopened);
			if (reopened)
				message.FormatMessage(IDS_s_n_FILES_REOPENED, message, reopened);
			if (already)
				message.FormatMessage(IDS_s_n_FILES_ALREADY_OPENED, message, already);
			break;
		
		case P4REOPEN:
			message.FormatMessage(IDS_REOPENED_n_FILES, strList->GetCount());
			break;

		case P4REVERT:
		case P4VIRTREVERT:
			m_OutputError = cmd1.GetOutputErrFlag();
			message.FormatMessage(m_OutputError 
				? IDS_ERROR_REVERTING_n_FILES : IDS_REVERTED_n_FILES, strList->GetCount());
			break;

		case P4REVERTUNCHG:
			m_OutputError = cmd1.GetOutputErrFlag();
			if (m_OutputError)
				message.FormatMessage(IDS_ERROR_REVERTING_n_FILES, strList->GetCount());
			else if (m_NbrChgedFilesReverted)
				message.FormatMessage(IDS_REVERTED_n_FILES_n_CHG_n_UNCHG, 
					m_NbrChgedFilesReverted + strList->GetCount(), 
					m_NbrChgedFilesReverted, strList->GetCount());
			else
				message.FormatMessage(IDS_REVERTED_n_FILES, strList->GetCount());
			break;

		case P4LOCK:
			message.FormatMessage(IDS_LOCKED_n_FILES, strList->GetCount());
			break;

		case P4UNLOCK:	
			message.FormatMessage(IDS_UNLOCKED_n_FILES, strList->GetCount());
			break;

		case P4DELETE:
			for( pos= strList->GetHeadPosition(); pos!= NULL; )
			{
				CString str = strList->GetNext(pos);
				if (str.Find(_T(" - currently opened ")) != -1)
					already++;
				else if (str.Find(_T(" - reopened ")) != -1)
					reopened++;
			}
			message.FormatMessage(IDS_OPENED_n_FILES_FOR_DELETE,
									strList->GetCount() - already - reopened);
			if (reopened)
				message.FormatMessage(IDS_s_n_FILES_REOPENED, message, reopened);
			if (already)
				message.FormatMessage(IDS_s_n_FILES_ALREADY_OPENED, message, already);
			break;

		case P4ADD:
			message.FormatMessage(IDS_OPENED_n_FILES_FOR_ADD, strList->GetCount());
			break;

		default:
			ASSERT(0);
		}
		if(!message.IsEmpty())
			TheApp()->StatusAdd( message, SV_COMPLETION );
	}
	
	done=TRUE;
}
Esempio n. 9
0
int main(int argc, char* argv[])
{
	ExplorationShared shared;
	EBehavior behavior(&shared);
	EBWaitIdle waitStart("Start");
	EBWaitIdle waitMotion1("ArmPositioning");
	EBWaitIdle waitMotion2("Turn1");
	EBWaitIdle waitMotion3("Turn2");
	EBWaitIdle waitMotion4("Turn3");
	EBWaitIdle waitMotion5("Turn4");
	EBWaitIdle waitMotion6("Turn5");
	EBWaitIdle waitMotion7("Final pos");
	EBWaitIdle waitMotion8("Going back to rest");
	EBWaitIdle endState1("end1");
	EBWaitIdle endState2("end2");

	EBWaitIdle stateInhibitHandTracking("Inhibit hand tracking");
	EBWaitIdle stateEnableHandTracking("Enable hand tracking");

	EBWaitIdle position1Wait("Position1 done");
	EBWaitIdle position2Wait("Position2 done");
	EBWaitIdle position3Wait("Position3 done");
	
	EBWaitDeltaT position2Train(6);
	EBWaitDeltaT position3Train(6);
	EBWaitDeltaT position4Train(6);

	EBWaitIdle position2("Waiting arm done");
	EBWaitIdle position3("Waiting arm done");
	EBWaitIdle position4("Waiting arm done");

	EBWaitIdle waitArmAck("Wait armAck");

	EBWaitDeltaT dT1(6);
	EBWaitDeltaT dT2(0.2);
	EBWaitDeltaT dT3OneSecond(3);

	EBWaitDeltaT dTHandClosing(0.1);
	EBWaitDeltaT waitArmSeemsToRest(5);
	EBBehaviorOutput	startTrain(YBVKFTrainStart);
	EBBehaviorOutput	startSequence(YBVKFStart);
	EBBehaviorOutput    stopTrain(YBVKFTrainStop);
	EBBehaviorOutput    stop(YBVKFStop);
	EBSimpleOutput	forceOpen(YBVGraspRflxForceOpen);
	EBSimpleOutput  parkArm(YBVArmForceRestingTrue);
	
	// output: enable and disable hand tracking system
	EBEnableTracker		enableHandTracking;
	EBInhibitTracker	inhibitHandTracking;
		
	EBOutputCommand cmd1(YBVArmForceNewCmd, YVector(_nJoints, pos1));
	EBOutputCommand cmd2(YBVArmForceNewCmd, YVector(_nJoints, pos2));
	EBOutputCommand cmd3(YBVArmForceNewCmd, YVector(_nJoints, pos3));
	// EBOutputCommand cmd4(YBVArmForceNewCmd, YVector(_nJoints, pos4));
	// EBOutputCommand cmd5(YBVArmForceNewCmd, YVector(_nJoints, pos5));
//	EBOutputCommand cmd6(YBVArmForceNewCmd, YVector(_nJoints, pos6));
	EBOutputCommand cmd7(YBVArmForceNewCmd, YVector(_nJoints, pos7));
	EBOutputCommand cmd8(YBVArmForceNewCmd, YVector(_nJoints, pos8));
	EBOutputCommand cmd9(YBVArmForceNewCmd, YVector(_nJoints, pos9));
	EBOutputCommand cmd10(YBVArmForceNewCmd, YVector(_nJoints, pos10));

	EBSimpleInput armDone(YBVArmDone);
	EBSimpleInput handDone(YBVHandDone);
	EBSimpleInput start(YBVKFExplorationStart);
	EBSimpleInput start2(YBVGraspRflxClutch);
	EBSimpleInput armAck(YBVArmIssuedCmd);
	EBSimpleInput armNAck(YBVArmIsBusy);

	behavior.setInitialState(&waitStart);
	behavior.add(&start, &waitStart, &waitMotion1, &cmd1);
	behavior.add(&start2, &waitStart, &dTHandClosing, &enableHandTracking);
	behavior.add(NULL, &dTHandClosing, &waitArmAck, &cmd1);

	behavior.add(&armAck, &waitArmAck, &stateEnableHandTracking, &startSequence);
	behavior.add(&armNAck, &waitArmAck, &waitArmSeemsToRest, &inhibitHandTracking);
	behavior.add(NULL, &waitArmSeemsToRest, &waitStart, &forceOpen);
	behavior.add(NULL, &stateEnableHandTracking, &waitMotion1, &enableHandTracking);

	behavior.add(&armDone, &waitMotion1, &dT3OneSecond);
	// wait some extra time before issueing the startKF signal
	behavior.add(NULL, &dT3OneSecond, &dT1, &startTrain);
	
	// july 21/04
	behavior.add(NULL, &dT1, &waitMotion6);
	behavior.add(NULL, &waitMotion6, &position1Wait, &stopTrain);
	// position2
	behavior.add(NULL, &position1Wait, &position2, &cmd7);
	behavior.add(&armDone, &position2, &position2Train, &startTrain);
	behavior.add(NULL, &position2Train, &position2Wait, &stopTrain);
	//position3
	behavior.add(NULL, &position2Wait, &position3, &cmd8);
	behavior.add(&armDone, &position3, &position3Train, &startTrain);
	behavior.add(NULL, &position3Train, &position3Wait, &stopTrain);
	//position 4
	behavior.add(NULL, &position3Wait, &position4, &cmd9);
	behavior.add(&armDone, &position4, &position4Train, &startTrain);
	behavior.add(NULL, &position4Train, &stateInhibitHandTracking, &stopTrain);

	behavior.add(NULL, &stateInhibitHandTracking, &dT2);

	/*
	behavior.add(NULL, &dT1, &waitMotion2, &cmd2);
	// behavior.add(&armDone, &waitMotion1, &waitMotion2, &cmd2);
	behavior.add(&armDone, &waitMotion2, &waitMotion3, &cmd3);
	behavior.add(&armDone, &waitMotion3, &waitMotion4, &cmd4);
	behavior.add(&armDone, &waitMotion4, &waitMotion5, &cmd5);
	behavior.add(&armDone, &waitMotion5, &waitMotion6, &cmd6);

	behavior.add(&armDone, &waitMotion6, &dT2, &stopKF);
	*/
	behavior.add(NULL, &dT2, &waitMotion7, &cmd10);
	behavior.add(&armDone, &waitMotion7, &waitMotion8, &forceOpen);
	behavior.add(&handDone, &waitMotion8, &endState1, &parkArm);
	behavior.add(NULL, &endState1, &endState2, &inhibitHandTracking);
	behavior.add(NULL, &endState2, &waitStart, &stop);

	behavior.Begin();
	behavior.loop();

	return 0;
}
Esempio n. 10
0
// ----------------------------------------------------------------------------
int main()
{
    send_to_venue_command_ptr cmd1( new send_to_venue_command );
    pass_thru_stage stage;
    stage.process( cmd1 );
}
Esempio n. 11
0
// thread to steal tasks it ready queue length becomes zero
void* worksteal(void* args) {
	//cout << "entered worksteal thread" << endl;
	Worker *worker = (Worker*) args;

	/*int min_lines = worker->svrclient.memberList.size();
	 //min_lines++;
	 string filename(file_worker_start);
	 //string cmd("wc -l ");
	 //cmd = cmd + filename + " | awk {\'print $1\'}";

	 string cmd("ls -l "); 	cmd.append(shared);	cmd.append("startinfo*");	cmd.append(" | wc -l");
	 string result = executeShell(cmd);
	 //cout << "server: minlines = " << min_lines << " cmd = " << cmd << " result = " << result << endl;
	 while(atoi(result.c_str()) < min_lines) {
	 sleep(2);
	 //cout << "server: " << worker.selfIndex << " minlines = " << min_lines << " cmd = " << cmd << " result = " << result << endl;
	 result = executeShell(cmd);
	 }
	 cout << "server: " << worker->selfIndex << " minlines = " << min_lines << " cmd = " << cmd << " result = " << result << endl;*/

	int num = worker->svrclient.memberList.size() - 1;
	stringstream num_ss;
	num_ss << num;
	//min_lines++;
	string cmd1("cat ");
	cmd1.append(shared);
	cmd1.append("startinfo");
	cmd1.append(num_ss.str());
	cmd1.append(" | wc -l");
	string result1 = executeShell(cmd1);
	//cout << "server: minlines = " << min_lines << " cmd = " << cmd << " result = " << result << endl;
	while (atoi(result1.c_str()) < 1) {
		usleep(ws_sleep);
		result1 = executeShell(cmd1);
	}
	//cout << "worksteal started: server: " << worker->selfIndex << " minlines = " << 1 << " cmd = " << cmd1 << " result = " << result1 << endl;

	while (work_steal_signal) {
		//while(ready_queue->get_length() > 0) { }
		while (rqueue.size() > 0) {
		}
		usleep(1000);
		// If there are no waiting ready tasks, do work stealing
		//if (worker.num_nodes > 1 && ready_queue->get_length() < 1)
		if (worker->num_nodes > 1 && rqueue.size() < 1) {
			int32_t success = worker->steal_task();
			// Do work stealing until succeed
			while (success == 0) {
				failed_attempts++;
				if (failed_attempts >= fail_threshold) {
					work_steal_signal = 0;
					cout << worker->selfIndex << " stopping worksteal" << endl;
					break;
				}
				usleep(worker->poll_interval);
				success = worker->steal_task();
			}
			failed_attempts = 0;
			//cout << "Received " << success << " tasks" << endl;
		}
	}
}
Esempio n. 12
0
MpodCrate::MpodCrate(string ip, string name) {

    // first check connection by trying to get MAC address from frontend board
    string cmd0("snmpget -Oqv -v 2c -m +WIENER-CRATE-MIB -c public ");
    string cmd1("snmpwalk -Oqv -v 2c -m +WIENER-CRATE-MIB -c public ");
    string cmd(cmd0+ip+" macAddress.0");
    FILE *io;
    char buff[512];
    int MakeConnection = 0;
    int Tries=0;
    while (!MakeConnection && Tries<10) {
        Tries++;
        if( (io = popen(cmd.c_str(),"r")) ) {
            MakeConnection = 1;
        }
    }

    if (MakeConnection) {
        fgets(buff, sizeof(buff), io);
        string res(buff);
        res.erase(0,1);
        res.erase(res.size()-1,1);
        res.erase(res.size()-1,1);
        MacAddress = res.c_str();
        if (DEBUG) {
            cout<<"MAC address is "<<res<<endl;
        }
        pclose(io);
    } else {
        cout<<"MpodCrate:: Error make connection to "<<ip<<endl;
    }

    Name = name;

    cmd = cmd0+ip+" ipDynamicAddress.0";
    io = popen(cmd.c_str(),"r");
    fgets(buff, sizeof(buff), io);
    pclose(io);
    string res(buff);
    res.erase(res.size()-1);
    IP = res;
    if (DEBUG) {
        cout<<"Dynamic IP address is "<<IP<<endl;
    }

    cmd = cmd0+ip+" psSerialNumber.0";
    io = popen(cmd.c_str(),"r");
    fgets(buff, sizeof(buff), io);
    pclose(io);
    res = buff;
    SerialNumber = atoi(res.c_str());
    if (DEBUG) {
        cout<<"Crate Serial Number is "<<SerialNumber<<endl;
    }
    cmd = cmd0+ip+" outputNumber.0";
    io = popen(cmd.c_str(),"r");
    fgets(buff, sizeof(buff), io);
    pclose(io);
    res = buff;
    Nchannels = atoi(res.c_str());
    if (DEBUG) {
        cout<<"Number of channels found in crate: "<<Nchannels<<endl;
    }
    cmd = cmd1+ip+" outputName";
    io = popen(cmd.c_str(),"r");

    // initialize counters and channel name list

    for (int i=0; i<10; i++) {
        NChanMod[i]=0;
    }
    if (!ChannelNames.empty()) {
        ChannelNames.clear();
    }
    while(fgets(buff, sizeof(buff), io)) {

        string res(buff);
        res.erase(res.size()-1);
        ChannelNames.push_back(res);

        if (DEBUG>2) {
            cout<<"Channel Name: "<<res<<endl;
        }

        res.erase(0,1);
        int ChanNum = atoi(res.c_str());
        if (ChanNum<100) {
            NChanMod[0]++;
        } else if  (ChanNum<200) {
            NChanMod[1]++;
        } else if  (ChanNum<300) {
            NChanMod[2]++;
        } else if  (ChanNum<400) {
            NChanMod[3]++;
        } else if  (ChanNum<500) {
            NChanMod[4]++;
        } else if  (ChanNum<600) {
            NChanMod[5]++;
        } else if  (ChanNum<700) {
            NChanMod[6]++;
        } else if  (ChanNum<800) {
            NChanMod[7]++;
        } else if  (ChanNum<900) {
            NChanMod[8]++;
        } else if (ChanNum<1000) {
            NChanMod[9]++;
        }

    }

    Nmodules=0;
    for (int i=0; i<10; i++) {
        if (NChanMod[i]>0) {
            Nmodules++;
            ModuleNames[i] = GetModuleType(i);
        }
    }

    if (DEBUG==9) {
        cout<<"Crate has Serial Number "<<SerialNumber<<endl;
        cout<<"Total Number of Channels "<<Nchannels<<endl;
        cout<<"Total Number of Modules "<<Nmodules<<endl;

    }


    CrateVector.push_back(this);
}
Esempio n. 13
0
        boost::system::error_code Connector::connect(
            SocketType & peer1, 
            NetName const & netname, 
            boost::system::error_code & ec)
        {
            typedef typename SocketType::protocol_type::socket socket;
            typedef typename socket::endpoint_type endpoint_type;

            socket & peer(peer1); // we should use the real socket type, not the child type

            if (netname.is_digit()) {
                return connect(peer, netname.endpoint(), ec);
            }
            if (!started_) {
                canceled_ = canceled_forever_;
                stat_.reset();
                connect_started_ = false;
                boost::asio::detail::mutex::scoped_lock lock(mutex_);
                if (canceled_) {
                    ec = boost::asio::error::operation_aborted;
                    canceled_ = false;
                } else {
                    lock.unlock();
                    resolver_iterator_ = resolver_.resolve(netname, ec);
                    lock.lock();
                }
                stat_.resolve_time = stat_.elapse();
                if (ec) {
                    return ec;
                } else if (canceled_) {
                    canceled_ = false;
                    return ec = boost::asio::error::operation_aborted;
                }
                started_ = true;
            }
            ResolverIterator end;
            for (; resolver_iterator_ != end; ++resolver_iterator_) {
                if (!connect_started_) {
                    Endpoint const & e = *resolver_iterator_;
                    {
                        boost::asio::detail::mutex::scoped_lock lock(mutex_);
                        if (canceled_) {
                            ec = boost::asio::error::operation_aborted;
                            canceled_ = false;
                        } else {
                            if (peer.is_open()) {
                                peer.close(ec);
                            }
                            boost::asio::socket_base::non_blocking_io cmd1(non_block_);
#ifndef UNDER_CE
                            boost::asio::socket_base::receive_time_out cmd2(time_out_);
#endif
                            ec || peer.open(endpoint_type(e).protocol(), ec) 
                                || peer.io_control(cmd1, ec) 
#ifndef UNDER_CE
                                || peer.set_option(cmd2, ec)
#endif
                                ;
                        }
                    }
                    if (ec) {
                        break;
                    }
                    LOG_TRACE("[connect] try server, ep: " << e.to_string());
                    start_connect(peer, e, ec);
                } else {
                    ec = boost::asio::error::would_block;
                }
                if (ec == boost::asio::error::would_block) {
                    pool_connect(peer, ec);
                }
                if (ec != boost::asio::error::would_block) {
                    if (!ec) {
                        post_connect(peer, ec);
                    } else {
                        boost::system::error_code ec1;
                        post_connect(peer, ec1);
                    }
                }
                if (!ec || ec == boost::asio::error::would_block || canceled_) {
                    break;
                }
                LOG_DEBUG("[connect] failed, ep: " << 
                    resolver_iterator_->to_string() << ",ec: " << ec.message());
            } // for
            if ((!ec || ec == boost::asio::error::would_block) && canceled_) {
                ec = boost::asio::error::operation_aborted;
            }
            if (ec != boost::asio::error::would_block) {
                stat_.connect_time = stat_.elapse();
                started_ = false;
                canceled_ = false;
            }
            return ec;
        }
Esempio n. 14
0
        boost::system::error_code Connector::connect(
            SocketType & peer1, 
            Endpoint const & endpoint, 
            boost::system::error_code & ec)
        {
            typedef typename SocketType::protocol_type::socket socket;
            typedef typename socket::endpoint_type endpoint_type;

            socket & peer(peer1); // we should use the real socket type, not the child type

            if (!started_) {
                canceled_ = canceled_forever_;
                stat_.reset();
                stat_.resolve_time = 0;
                if (ec) {
                    return ec;
                }
                {
                    boost::asio::detail::mutex::scoped_lock lock(mutex_);
                    if (canceled_) {
                        ec = boost::asio::error::operation_aborted;
                        canceled_ = false;
                    } else if (peer.is_open()) {
                        peer.close(ec);
                    }
                    boost::asio::socket_base::non_blocking_io cmd1(non_block_);
#ifndef UNDER_CE
                    boost::asio::socket_base::receive_time_out cmd2(time_out_);
#endif
                    ec || peer.open(endpoint_type(endpoint).protocol(), ec) 
                        || peer.io_control(cmd1, ec)
#ifndef UNDER_CE
                        || peer.set_option(cmd2, ec)
#endif
                        ;
                    started_ = true;
                }
                connect_started_ = false;
                if (ec)
                    return ec;
                start_connect(peer, endpoint, ec);
            } else {
                ec = boost::asio::error::would_block;
            }
            if (ec == boost::asio::error::would_block) {
                pool_connect(peer, ec);
            }
            if (ec == boost::asio::error::would_block) {
                if (time_out_ && stat_.elapse() > time_out_) {
                    ec = boost::asio::error::timed_out;
                }
            }
            if (ec != boost::asio::error::would_block) {
                if (!ec) {
                    post_connect(peer, ec);
                } else {
                    boost::system::error_code ec1;
                    post_connect(peer, ec1);
                }
                stat_.connect_time = stat_.elapse();
                started_ = false;
                canceled_ = false;
            } 
            return ec;
        }