Пример #1
0
// static
shared_ptr <SMTPCommand> SMTPCommand::MAIL(const mailbox& mbox, const bool utf8, const size_t size)
{
	std::ostringstream cmd;
	cmd.imbue(std::locale::classic());
	cmd << "MAIL FROM:<";

	if (utf8)
	{
		cmd << mbox.getEmail().toText().getConvertedText(vmime::charsets::UTF_8);
	}
	else
	{
		vmime::utility::outputStreamAdapter cmd2(cmd);
		mbox.getEmail().generate(cmd2);
	}

	cmd << ">";

	if (utf8)
		cmd << " SMTPUTF8";

	if (size != 0)
		cmd << " SIZE=" << size;

	return createCommand(cmd.str());
}
Пример #2
0
void TestPAPageDeleteCommand::redoUndo()
{
    MockDocument doc;

    KoPAMasterPage * master1 = new KoPAMasterPage();
    doc.insertPage( master1, 0 );

    KoPAPage * page1 = new KoPAPage( master1 );
    doc.insertPage( page1, 0 );

    KoPAPage * p1 = dynamic_cast<KoPAPage *>( doc.pageByIndex( 0, false ) );
    KoPAMasterPage * m1 = dynamic_cast<KoPAMasterPage *>( doc.pageByIndex( 0, true ) );

    QVERIFY( p1 != 0 );
    QVERIFY( m1 != 0 );

    KoPAPage * p2 = new KoPAPage( m1 );
    KoPAPage * p3 = new KoPAPage( m1 );
    doc.insertPage( p2, 1 );
    doc.insertPage( p3, 2 );

    KoPAPageDeleteCommand cmd( &doc, p1 );
    KoPAPageDeleteCommand cmd2( &doc, p3 );

    QList<KoPAPage *> pages;
    pages.append( p1 );
    pages.append( p2 );
    pages.append( p3 );

    QList<KoPAPage *> allPages = pages;

    for( int i = 0; i < pages.size(); ++i ) {
        QVERIFY( pages[i] == doc.pageByIndex( i, false ) );
    }

    cmd.redo();

    pages.removeAt( 0 );
    for( int i = 0; i < pages.size(); ++i ) {
        QVERIFY( pages[i] == doc.pageByIndex( i, false ) );
    }

    cmd2.redo();

    pages.removeAt( 1 );
    for( int i = 0; i < pages.size(); ++i ) {
        QVERIFY( pages[i] == doc.pageByIndex( i, false ) );
    }

    for( int i = 0; i < pages.size(); ++i ) {
        QVERIFY( pages[i] == doc.pageByIndex( i, false ) );
    }

    cmd2.undo();
    cmd.undo();

    for( int i = 0; i < allPages.size(); ++i ) {
        QVERIFY( allPages[i] == doc.pageByIndex( i, false ) );
    }
}
Пример #3
0
void TestPAPageDeleteCommand::redoUndoMaster()
{
    MockDocument doc;
    KoPAMasterPage * master1 = new KoPAMasterPage();
    doc.insertPage( master1, 0 );

    KoPAMasterPage * m1 = dynamic_cast<KoPAMasterPage *>( doc.pageByIndex( 0, true ) );

    QVERIFY( m1 != 0 );

    KoPAMasterPage * m2 = new KoPAMasterPage();
    KoPAMasterPage * m3 = new KoPAMasterPage();
    doc.insertPage( m2, 1 );
    doc.insertPage( m3, 2 );

    KoPAPageDeleteCommand cmd( &doc, m1 );
    KoPAPageDeleteCommand cmd2( &doc, m3 );


    QList<KoPAMasterPage *> masterPages;
    masterPages.append( m1 );
    masterPages.append( m2 );
    masterPages.append( m3 );

    QList<KoPAMasterPage *> allMasterPages = masterPages;

    for( int i = 0; i < masterPages.size(); ++i ) {
        QVERIFY( masterPages[i] == doc.pageByIndex( i, true ) );
    }

    cmd.redo();

    masterPages.removeAt( 0 );
    for( int i = 0; i < masterPages.size(); ++i ) {
        QVERIFY( masterPages[i] == doc.pageByIndex( i, true ) );
    }

    cmd2.redo();

    masterPages.removeAt( 1 );
    for( int i = 0; i < masterPages.size(); ++i ) {
        QVERIFY( masterPages[i] == doc.pageByIndex( i, true ) );
    }

    for( int i = 0; i < masterPages.size(); ++i ) {
        QVERIFY( masterPages[i] == doc.pageByIndex( i, true ) );
    }

    cmd2.undo();
    cmd.undo();

    for( int i = 0; i < allMasterPages.size(); ++i ) {
        QVERIFY( allMasterPages[i] == doc.pageByIndex( i, true ) );
    }
}
Пример #4
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")));
}
Пример #5
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")));
}
Пример #6
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")));
}
Пример #7
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;
}
Пример #8
0
// static
shared_ptr <SMTPCommand> SMTPCommand::RCPT(const mailbox& mbox, const bool utf8)
{
	std::ostringstream cmd;
	cmd.imbue(std::locale::classic());
	cmd << "RCPT TO:<";

	if (utf8)
	{
		cmd << mbox.getEmail().toText().getConvertedText(vmime::charsets::UTF_8);
	}
	else
	{
		vmime::utility::outputStreamAdapter cmd2(cmd);
		mbox.getEmail().generate(cmd2);
	}

	cmd << ">";

	return createCommand(cmd.str());
}
Пример #9
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]));
}
Пример #10
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);
}
Пример #11
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;
}
Пример #12
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;
}
Пример #13
0
Worker::Worker(char *parameters[], NoVoHT *novoht) {
	/* set thread detachstate attribute to DETACHED */
	pthread_attr_init(&attr);
	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
	pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
	/* filename definitions */
	set_dir(parameters[9], parameters[10]);
	file_worker_start.append(shared);
	file_worker_start.append("startinfo");
	file_task_fp.append(prefix);
	file_task_fp.append("pkgs");
	file_migrate_fp.append(prefix);
	file_migrate_fp.append("log_migrate");
	file_fin_fp.append(prefix);
	file_fin_fp.append("finish");
	file_log_fp.append(prefix);
	file_log_fp.append("log_worker");

	pmap = novoht;
	Env_var::set_env_var(parameters);
	svrclient.initialize(Env_var::cfgFile, Env_var::membershipFile,
			Env_var::TCP);
	//svrzht.initialize(Env_var::cfgFile, Env_var::membershipFile, Env_var::TCP);
	//svrmig.initialize(Env_var::cfgFile, Env_var::membershipFile, Env_var::TCP);

	if (set_ip(ip)) {
		printf("Could not get the IP address of this machine!\n");
		exit(1);
	}

	for (int i = 0; i < 10; i++) {
		msg_count[i] = 0;
	}

	poll_interval = start_poll;
	poll_threshold = start_thresh;
	num_nodes = svrclient.memberList.size();
	num_cores = atoi(parameters[11]);
	ws_sleep = atoi(parameters[12]);
	num_idle_cores = num_cores;
	neigh_mode = 'd';
	//worker.num_neigh = (int)(sqrt(worker.num_nodes));
	num_neigh = (int) (sqrt(num_nodes));
	neigh_index = new int[num_neigh];
	selfIndex = getSelfIndex(ip, atoi(parameters[1]), svrclient.memberList);// replace "localhost" with proper hostname, host is the IP in C++ string
	ostringstream oss;
	oss << selfIndex;

	printf("<ip:selfIndex>: <%s:%d>\n", ip.c_str(), selfIndex);

	//string f1 = file_fin_fp;
	//f1 = f1 + oss.str();
	//fin_fp.open(f1.c_str(), ios_base::app);

	if (LOGGING) {

		string f2 = file_task_fp;
		f2 = f2 + oss.str();
		task_fp.open(f2.c_str(), ios_base::app);

		string f3 = file_log_fp;
		f3 = f3 + oss.str();
		log_fp.open(f3.c_str(), ios_base::app);

		string f4 = file_migrate_fp;
		f4 = f4 + oss.str();
		migrate_fp.open(f4.c_str(), ios_base::app);
	}

	migratev = bitvec(num_nodes);

	Package loadPackage, tasksPackage;
	string loadmessage("Load Information!");
	loadPackage.set_virtualpath(loadmessage);
	loadPackage.set_operation(13);
	loadstr = loadPackage.SerializeAsString();

	stringstream selfIndexstream;
	selfIndexstream << selfIndex;
	string taskmessage(selfIndexstream.str());
	tasksPackage.set_virtualpath(taskmessage);
	tasksPackage.set_operation(14);
	taskstr = tasksPackage.SerializeAsString();

	srand((selfIndex + 1) * (selfIndex + 5));
	int rand_wait = rand() % 1000000;
	cout << "Worker ip = " << ip << " selfIndex = " << selfIndex << endl;
	//cout << "Worker ip = " << ip << " selfIndex = " << selfIndex << " going to wait for " << rand_wait << " seconds" << endl;
	usleep(rand_wait);

	file_worker_start.append(oss.str());
	string cmd("touch ");
	cmd.append(file_worker_start);
	//executeShell(cmd);
	system(cmd.c_str());

	FILE *fp = fopen(file_worker_start.c_str(), "w+");
	if (fp != NULL) {
		//fputs("fopen example", fp);
		char fbuf[100];
		memset(fbuf, 0, sizeof(fbuf));
		sprintf(fbuf, "%s:%d ", ip.c_str(), selfIndex);
		fwrite(fbuf, sizeof(char), strlen(fbuf), fp);
		fflush(fp);
		fclose(fp);
	}

	/*worker_start.open(file_worker_start.c_str(),
	 std::ofstream::out | ios_base::app);
	 if (worker_start.is_open()) {

	 worker_start << ip << ":" << selfIndex << " ";
	 worker_start.flush();
	 worker_start.close();
	 worker_start.open(file_worker_start.c_str(), ios_base::app);
	 }
	 worker_start.open(file_worker_start.c_str(),
	 std::ofstream::out | ios_base::app);
	 */

	clock_gettime(CLOCK_REALTIME, &poll_start);

	int err;
	/*pthread_t *ready_queue_thread = new pthread_t();//(pthread_t*)malloc(sizeof(pthread_t));
	 pthread_create(ready_queue_thread, &attr, check_ready_queue, NULL);*/
	try {
		pthread_t *ready_queue_thread = new pthread_t[num_cores];
		for (int i = 0; i < num_cores; i++) {
			err = pthread_create(&ready_queue_thread[i], &attr,
					check_ready_queue, (void*) this);
			if (err) {
				printf(
						"work_steal_init: pthread_create: ready_queue_thread: %s\n",
						strerror(errno));
				exit(1);
			}
		}

		pthread_t *wait_queue_thread = new pthread_t();
		err = pthread_create(wait_queue_thread, &attr, check_wait_queue,
				(void*) this);
		if (err) {
			printf("work_steal_init: pthread_create: wait_queue_thread: %s\n",
					strerror(errno));
			exit(1);
		}

		pthread_t *complete_queue_thread = new pthread_t();
		err = pthread_create(complete_queue_thread, &attr, check_complete_queue,
				(void*) this);
		if (err) {
			printf(
					"work_steal_init: pthread_create: complete_queue_thread: %s\n",
					strerror(errno));
			exit(1);
		}

		package_thread_args rq_args, wq_args;
		rq_args.source = &insertq_new;
		wq_args.source = &waitq;
		rq_args.dest = &rqueue;
		wq_args.dest = &wqueue;
		rq_args.slock = &iq_new_lock;
		wq_args.slock = &waitq_lock;
		rq_args.dlock = &lock;
		wq_args.dlock = &w_lock;
		rq_args.worker = this;
		wq_args.worker = this;
		pthread_t *waitq_thread = new pthread_t();
		err = pthread_create(waitq_thread, &attr, HB_insertQ_new,
				(void*) &wq_args);
		if (err) {
			printf("work_steal_init: pthread_create: waitq_thread: %s\n",
					strerror(errno));
			exit(1);
		}

		pthread_t *readyq_thread = new pthread_t();
		err = pthread_create(readyq_thread, &attr, HB_insertQ_new,
				(void*) &rq_args);
		if (err) {
			printf("work_steal_init: pthread_create: ready_thread: %s\n",
					strerror(errno));
			exit(1);
		}

		pthread_t *migrateq_thread = new pthread_t();
		err = pthread_create(migrateq_thread, &attr, migrateTasks,
				(void*) this);
		if (err) {
			printf("work_steal_init: pthread_create: migrateq_thread: %s\n",
					strerror(errno));
			exit(1);
		}

		pthread_t *notq_thread = new pthread_t();
		err = pthread_create(notq_thread, &attr, notQueue, (void*) this);
		if (err) {
			printf("work_steal_init: pthread_create: notq_thread: %s\n",
					strerror(errno));
			exit(1);
		}

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

		string cmd2("ls -l ");
		cmd2.append(shared);
		cmd2.append("startinfo*");
		cmd2.append(" | wc -l");
		string result = executeShell(cmd2);
		//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(cmd2);
		}
		//cout << "server: " << selfIndex << " minlines = " << min_lines << " cmd = " << cmd2 << " result = " << result << endl;

		/*int num = min_lines - 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) {
		 sleep(2);
		 result1 = executeShell(cmd1);
		 }
		 cout << "worksteal started: server: " << selfIndex << " minlines = " << 1 << " cmd = " << cmd1 << " result = " << result1 << endl;*/

		pthread_t *work_steal_thread = new pthread_t(); //(pthread_t*)malloc(sizeof(pthread_t));
		err = pthread_create(work_steal_thread, &attr, worksteal, (void*) this);
		if (err) {
			printf("work_steal_init: pthread_create: work_steal_thread: %s\n",
					strerror(errno));
			exit(1);
		}

		delete ready_queue_thread;
		delete wait_queue_thread;
		delete complete_queue_thread;
		delete work_steal_thread;
		delete readyq_thread;
		delete waitq_thread;
		delete migrateq_thread;
		delete notq_thread;
	} catch (std::bad_alloc& exc) {
		cout
				<< "work_steal_init: failed to allocate memory while creating threads"
				<< endl;
		exit(1);
	}
}
Пример #14
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;
        }
Пример #15
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;
        }
Пример #16
0
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;
}
Пример #17
0
bool CClient::Cmd_SecureTrade( CChar *pChar, CItem *pItem )
{
	ADDTOCALLSTACK("CClient::Cmd_SecureTrade");
	// Begin secure trading with a char. (Make the initial offer)
	if ( !pChar || pChar == m_pChar )
		return false;

	// Make sure both clients can see each other, because trade window is an container
	// and containers can be opened only after the object is already loaded on screen
	if ( !m_pChar->CanSee(pChar) || !pChar->CanSee(m_pChar) )
		return false;

	if ( pItem && (IsTrigUsed(TRIGGER_DROPON_CHAR) || IsTrigUsed(TRIGGER_ITEMDROPON_CHAR)) )
	{
		CScriptTriggerArgs Args(pChar);
		if ( pItem->OnTrigger(ITRIG_DROPON_CHAR, m_pChar, &Args) == TRIGRET_RET_TRUE )
			return false;
	}

	if ( pChar->m_pNPC )		// NPC's can't use trade windows
		return pItem ? pChar->NPC_OnItemGive(m_pChar, pItem) : false;
	if ( !pChar->m_pClient )	// and also offline players
		return false;

	if ( pChar->GetDefNum("REFUSETRADES") )
	{
		SysMessagef(g_Cfg.GetDefaultMsg(DEFMSG_MSG_TRADE_REFUSE), pChar->GetName());
		return false;
	}

	// Check if the trade window is already open
	for ( CItem *pItemCont = m_pChar->GetContentHead(); pItemCont != NULL; pItemCont = pItemCont->GetNext() )
	{
		if ( !pItemCont->IsType(IT_EQ_TRADE_WINDOW) )
			continue;

		CItem *pItemPartner = pItemCont->m_uidLink.ItemFind();
		if ( !pItemPartner )
			continue;

		CChar *pCharPartner = dynamic_cast<CChar *>(pItemPartner->GetParent());
		if ( pCharPartner != pChar )
			continue;

		if ( pItem )
		{
			if ( IsTrigUsed(TRIGGER_DROPON_TRADE) )
			{
				CScriptTriggerArgs Args1(pChar);
				if ( pItem->OnTrigger(ITRIG_DROPON_TRADE, this, &Args1) == TRIGRET_RET_TRUE )
					return false;
			}
			CItemContainer *pCont = dynamic_cast<CItemContainer *>(pItemCont);
			if ( pCont )
				pCont->ContentAdd(pItem);
		}
		return true;
	}

	// Open new trade window
	if ( IsTrigUsed(TRIGGER_TRADECREATE) )
	{
		CScriptTriggerArgs Args(pItem);
		if ( (m_pChar->OnTrigger(CTRIG_TradeCreate, pChar, &Args) == TRIGRET_RET_TRUE) || (pChar->OnTrigger(CTRIG_TradeCreate, m_pChar, &Args) == TRIGRET_RET_TRUE) )
			return false;
	}

	if ( IsTrigUsed(TRIGGER_DROPON_TRADE) && pItem )
	{
		CScriptTriggerArgs Args1(pChar);
		if ( pItem->OnTrigger(ITRIG_DROPON_TRADE, this, &Args1) == TRIGRET_RET_TRUE )
			return false;
	}

	CItem *pItem1 = CItem::CreateBase(ITEMID_Bulletin1);
	if ( !pItem1 )
		return false;

	CItemContainer *pCont1 = static_cast<CItemContainer *>(pItem1);
	if ( !pCont1 )
	{
		DEBUG_ERR(("Item 0%x must be a container type to enable player trading.\n", ITEMID_Bulletin1));
		pItem1->Delete();
		return false;
	}

	CItemContainer *pCont2 = static_cast<CItemContainer *>(CItem::CreateBase(ITEMID_Bulletin1));
	ASSERT(pCont2);

	pCont1->SetName("Trade Window");
	pCont1->SetType(IT_EQ_TRADE_WINDOW);
	pCont1->m_itEqTradeWindow.m_iWaitTime = 0;
	pCont1->m_itEqTradeWindow.m_bCheck = 0;
	pCont1->m_uidLink = pCont2->GetUID();
	m_pChar->LayerAdd(pCont1, LAYER_SPECIAL);

	pCont2->SetName("Trade Window");
	pCont2->SetType(IT_EQ_TRADE_WINDOW);
	pCont2->m_itEqTradeWindow.m_iWaitTime = 0;
	pCont2->m_itEqTradeWindow.m_bCheck = 0;
	pCont2->m_uidLink = pCont1->GetUID();
	pChar->LayerAdd(pCont2, LAYER_SPECIAL);

	PacketTradeAction cmd(SECURE_TRADE_OPEN);
	cmd.prepareContainerOpen(pChar, pCont1, pCont2);
	cmd.send(this);
	cmd.prepareContainerOpen(m_pChar, pCont2, pCont1);
	cmd.send(pChar->m_pClient);

	if ( g_Cfg.m_iFeatureTOL & FEATURE_TOL_VIRTUALGOLD )
	{
		PacketTradeAction cmd2(SECURE_TRADE_UPDATELEDGER);
		if ( m_NetState->isClientVersion(MINCLIVER_TOL) )
		{
			cmd2.prepareUpdateLedger(pCont1, static_cast<DWORD>(m_pChar->m_virtualGold % 1000000000), static_cast<DWORD>(m_pChar->m_virtualGold / 1000000000));
			cmd2.send(this);
		}
		if ( pChar->m_pClient->m_NetState->isClientVersion(MINCLIVER_TOL) )
		{
			cmd2.prepareUpdateLedger(pCont2, static_cast<DWORD>(pChar->m_virtualGold % 1000000000), static_cast<DWORD>(pChar->m_virtualGold / 1000000000));
			cmd2.send(pChar->m_pClient);
		}
	}

	LogOpenedContainer(pCont2);
	pChar->m_pClient->LogOpenedContainer(pCont1);

	if ( pItem )
	{
		if ( IsTrigUsed(TRIGGER_DROPON_TRADE) )
		{
			CScriptTriggerArgs Args1(pChar);
			if ( pItem->OnTrigger(ITRIG_DROPON_TRADE, this, &Args1) == TRIGRET_RET_TRUE )
			{
				pCont1->Delete();
				pCont2->Delete();
				return false;
			}
		}
		pCont1->ContentAdd(pItem, pCont1->GetTopPoint());
	}
	return true;
}
Пример #18
0
void cmd4(int i, int j)
{
    if (i > j) return;
    cmd4(i + 1, j);
    cmd2(i, j, 1);
}