void
JXFSBindingTable::HandleTypeMenu
	(
	const JIndex index
	)
{
	JPoint cell;
	const JBoolean ok = (GetTableSelection()).GetFirstSelectedCell(&cell);
	assert( ok );

	const JFSBinding::CommandType newType = kMenuIndexToCmdType [ index-1 ];
	if (itsBindingList->SetCommandType(cell.y, newType))
		{
		TableRefreshRow(cell.y);
		Broadcast(DataChanged());
		}
}
void
JXFSBindingTable::AddPattern()
{
	if (EndEditing())
		{
		const JFSBinding* b = itsBindingList->GetDefaultCommand();
		JFSBinding::CommandType type;
		JBoolean singleFile;
		const JString& cmd = b->GetCommand(&type, &singleFile);

		const JIndex rowIndex =
			itsBindingList->AddBinding("", cmd, type, singleFile);
		InsertRows(rowIndex, 1);
		BeginEditing(JPoint(kPatternColumn, rowIndex));
		Broadcast(DataChanged());
		}
}
예제 #3
0
void Switchboard::Update(float dt)
{
	std::vector<MessageTimer>::iterator it = _delayedMessages.begin();
	while (it != _delayedMessages.end())
	{
		(*it)._timeRemaining -= dt;
		if ((*it)._timeRemaining <= 0.0f)
		{
			Broadcast((*it)._message);
			it = _delayedMessages.erase(it);
		}
		else
		{
			it++;
		}
	}
}
void
JXFSBindingTable::Receive
	(
	JBroadcaster*	sender,
	const Message&	message
	)
{
	if (sender == itsAddButton && message.Is(JXButton::kPushed))
		{
		AddPattern();
		}
	else if (sender == itsRemoveButton && message.Is(JXButton::kPushed))
		{
		RemovePattern();
		}
	else if (sender == itsDuplicateButton && message.Is(JXButton::kPushed))
		{
		DuplicatePattern();
		}

	else if (sender == itsTypeMenu && message.Is(JXMenu::kNeedsUpdate))
		{
		UpdateTypeMenu();
		}
	else if (sender == itsTypeMenu && message.Is(JXMenu::kItemSelected))
		{
		const JXMenu::ItemSelected* selection =
			dynamic_cast<const JXMenu::ItemSelected*>(&message);
		assert( selection != NULL );
		HandleTypeMenu(selection->GetIndex());
		}

	else
		{
		if (sender == &(GetTableSelection()))
			{
			UpdateButtons();
			}
		else if (message.Is(JTextEditor::kTextChanged))
			{
			Broadcast(DataChanged());
			}

		JXEditTable::Receive(sender, message);
		}
}
예제 #5
0
void ShuffleRound::Shuffle()
{
    qDebug() << _group.GetIndex(_local_id) << ": shuffling";
    _state = Shuffling;

    for(int idx = 0; idx < _shuffle_data.count(); idx++) {
        for(int jdx = 0; jdx < _shuffle_data.count(); jdx++) {
            if(idx == jdx) {
                continue;
            }
            if(_shuffle_data[idx] != _shuffle_data[jdx]) {
                continue;
            }
            qWarning() << "Found duplicate cipher texts... blaming";
            // blame ?
            return;
        }
    }

    QVector<QByteArray> out_data;
    int blame = OnionEncryptor::GetInstance().Decrypt(_outer_key, _shuffle_data, out_data);
    if (blame != -1) {
        qWarning() << _group.GetIndex(_local_id) << _local_id.ToString() <<
                   ": failed to decrypt layer due to block at index" << blame;
        // blame ?
        return;
    }

    const Id &next = _group.Next(_local_id);
    MessageType mtype = (next == Id::Zero) ? EncryptedData : ShuffleData;

    QByteArray msg;
    QDataStream out_stream(&msg, QIODevice::WriteOnly);
    out_stream << mtype << GetId().GetByteArray() << out_data;

    _state = ShuffleDone;

    if(mtype == EncryptedData) {
        Broadcast(msg);
        _encrypted_data = out_data;
        Verify();
    } else {
        Send(msg, next);
    }
}
void
GRaggedFloatTableData::SetRow
	(
	const JIndex				index,
	const JArray<JFloat>&	rowData
	)
{
	const JSize colCount = GetDataColCount();
	assert( rowData.GetElementCount() == colCount );

	for (JIndex i=1; i<=colCount; i++)
		{
		JArray<JFloat>* dataCol = itsCols->NthElement(i);
		dataCol->SetElement(index, rowData.GetElement(i));
		}

	Broadcast(JTableData::RectChanged(JRect(index, 1, index+1, colCount+1)));
}
void
JXColorWheel::SetColor
	(
	const JHSB& hsb
	)
{
	if (itsColor != hsb)
		{
		itsColor = hsb;

		StopListening(itsBrightnessSlider);
		itsBrightnessSlider->SetValue(itsColor.brightness);
		ListenTo(itsBrightnessSlider);

		Broadcast(ColorChanged());
		Refresh();
		}
}
void
JXColorWheel::Receive
	(
	JBroadcaster*	sender,
	const Message&	message
	)
{
	if (sender == itsBrightnessSlider && message.Is(JSliderBase::kMoved))
		{
		itsColor.brightness = JRound(itsBrightnessSlider->GetValue());
		Broadcast(ColorChanged());
		Refresh();
		}
	else
		{
		JXWidget::Receive(sender, message);
		}
}
예제 #9
0
void ShuffleRound::BroadcastPrivateKey()
{
    qDebug() << _group.GetIndex(_local_id) << _local_id.ToString() <<
             ": received sufficient go messages, broadcasting private key.";

    int idx = _group.GetIndex(_local_id);
    _private_inner_keys[idx] = new CppPrivateKey(_inner_key->GetByteArray());

    QByteArray msg;
    QDataStream stream(&msg, QIODevice::WriteOnly);
    stream << PrivateKey << GetId().GetByteArray() << _inner_key->GetByteArray();

    Broadcast(msg);

    if(++_keys_received == _group.GetSize()) {
        Decrypt();
    }
}
예제 #10
0
void VisionApp::SetString(const char* stringName, int32 index, const char* value)
{
	BAutolock stringLock(const_cast<BLocker*>(&fSettingsLock));

	if (!stringLock.IsLocked()) return;

	if (!strcmp(stringName, "timestamp_format")) {
		BMessage msg(M_STATE_CHANGE);
		msg.AddBool("string", true);
		msg.AddString("which", stringName);
		Broadcast(&msg);
	}

	BString tmp;
	tmp = value;

	fVisionSettings->ReplaceString(stringName, index, tmp);
}
예제 #11
0
/* tests wait, signal, and broadcast syscalls  */
void CVTest2()
{
    int i;

    /*will be used later  to test ownership condition */
    Exec("../test/lock_help", 17);

    /* testing lock id range check */
    PrintF("\nTest 2 - Accessing invalid cv ID (both below and above valid range):\n", 
        sizeof("\nTest 2 - Accessing invalid cv ID (both below and above valid range):\n"), 0, 0);
    Wait(-1, myLock);
    Wait(100, myLock);

    /* testing trying to acquire a cv that doesn't exit */
    PrintF("Trying to acquire cv that was deleted: \n", sizeof("Trying to acquire cv that was deleted: \n"), 0, 0);
    Wait(myCV2, myLock);

    PrintF("\nTesting signal, wait, broadcast\n", sizeof("\nTesting signal, wait, broadcast\n"), 0, 0);

    /*fork threads to test signal */
    Fork(threadTest2_1);
    Yield();
    Acquire(myLock);
    PrintF("Before signal\n", sizeof("Before signal\n"), 0, 0);
    Signal(myCV, myLock);
    PrintF("After signal\n", sizeof("After signal\n"), 0, 0);
    Release(myLock);

    /*fork threads to test broadcast*/
    Fork(threadTest2_2);
    Fork(threadTest2_2);
    Fork(threadTest2_2);
    for (i = 0; i < 50; i++)
        Yield();
    Acquire(myLock);
    PrintF("Before broadcast\n", sizeof("Before broadcast\n"), 0, 0);
    Broadcast(myCV, myLock);
    PrintF("After broadcast\n", sizeof("After broadcast\n"), 0, 0);
    Release(myLock);

    /* tries to access cv created by another process */
    PrintF("\nTrying to acquire cv created in another process: \n", sizeof("\nTrying to acquire cv created in another process: \n"), 0, 0);
    Wait(4, myLock);
}
JError
JDirInfo::SetContentFilter
	(
	const JCharacter* regexStr
	)
{
	if (itsContentRegex != NULL && regexStr == itsContentRegex->GetPattern())
		{
		return JNoError();
		}

	JBoolean hadFilter = kJTrue;
	JString prevPattern;
	if (itsContentRegex == NULL)
		{
		hadFilter       = kJFalse;
		itsContentRegex = new JRegex;
		assert( itsContentRegex != NULL );
		itsContentRegex->SetSingleLine();
		}
	else
		{
		prevPattern = itsContentRegex->GetPattern();
		}

	JError err = itsContentRegex->SetPattern(regexStr);
	if (err.OK())
		{
		ForceUpdate();
		Broadcast(SettingsChanged());
		}
	else if (hadFilter)
		{
		err = itsContentRegex->SetPattern(prevPattern);
		assert_ok( err );
		}
	else
		{
		delete itsContentRegex;
		itsContentRegex = NULL;
		}
	return err;
}
예제 #13
0
void
GFGLink::ParseClass
	(
	GFGClass* 		  list,
	const JCharacter* filename, 
	const JCharacter* classname
	)
{
	JBoolean ok	= kJTrue;
	if (itsCTagsProcess == NULL)
		{
		ok = StartCTags();
		}

	if (ok)
		{
		itsClassList	= list;
		itsCurrentClass	= classname;
		itsCurrentFile	= filename;

		JConvertToAbsolutePath(filename, "", &itsCurrentFile);

		itsCurrentFile.Print(*itsOutputLink);
		*itsOutputLink << std::endl;
		itsOutputLink->flush();

		JBoolean found = kJFalse;
		JString result = JReadUntil(itsInputFD, kDelimiter, &found);

		if (found)
			{
			JIndex findex;
			while (	result.LocateSubstring("\n", &findex) &&
					findex > 1)
				{
				JString line	= result.GetSubstring(1, findex - 1);
				result.RemoveSubstring(1, findex);
				ParseLine(line);
				}
			Broadcast(FileParsed());
			}
		}
}
예제 #14
0
void CScriptDebugging::LogError ( SString strFile, int iLine, SString strMsg )
{
    SString strText = SString ( "ERROR: %s:%d: %s", strFile.c_str (), iLine, strMsg.c_str () );

    if ( !m_bTriggeringOnDebugMessage )
    {
        m_bTriggeringOnDebugMessage = true;

        // Prepare onDebugMessage
        CLuaArguments Arguments;
        Arguments.PushString ( strMsg.c_str ( ) );
        Arguments.PushNumber ( 1 );

        // Push the file name (if any)
        if ( strFile.length ( ) > 0 )
            Arguments.PushString ( strFile.c_str ( ) );
        else
            Arguments.PushNil ( );

        // Push the line (if any)
        if ( iLine > -1 )
            Arguments.PushNumber ( iLine );
        else
            Arguments.PushNil ( );
        
        // Call onDebugMessage
        g_pGame->GetMapManager ( )->GetRootElement ( )->CallEvent ( "onDebugMessage", Arguments );

        m_bTriggeringOnDebugMessage = false;
    }

    // Log it to the file if enough level
    if ( m_uiLogFileLevel >= 1 )
    {
        PrintLog ( strText );
    }

    // Log to console
    CLogger::LogPrintf( "%s\n", strText.c_str () );

    // Tell the players
    Broadcast ( CDebugEchoPacket ( strText, 1, 255, 255, 255 ), 1 );
}
예제 #15
0
void
SMTPMessage::BlockUntilOkOrFail()
{
	if (itsIsFinished)
		{
		return;
		}

	if (itsTimeoutTask != NULL)
		{
		JGetUserNotification()->ReportError("Connection to SMTP server timed out.");
		Broadcast(SendFailure());
//		itsLink = NULL;
		delete this;
		return;
		}

	JBoolean success	= kJFalse;
	itsIsFinished		= kJFalse;
	itsIsTryingToQuit	= kJTrue;

	JSize i = 1;
	while((i <= 30) && !itsIsFinished)
		{
		do
			{
			itsSomethingRead = kJFalse;
			ACE_Time_Value timeout(0);
			(ACE_Reactor::instance())->handle_events(timeout);
			ACE_Reactor::check_reconfiguration(NULL);

//			itsLink->handle_input(0);
			}
		while (itsSomethingRead);// && !itsIsFinished);

		JWait(2);
		i++;
		}
	if (itsIsFinished)
		{
		delete this;
		}
}
void
JXFSBindingTable::DuplicatePattern()
{
	JPoint cell;
	if ((GetTableSelection()).GetFirstSelectedCell(&cell) && EndEditing())
		{
		const JFSBinding* b = itsBindingList->GetBinding(cell.y);

		JFSBinding::CommandType type;
		JBoolean singleFile;
		const JString& cmd = b->GetCommand(&type, &singleFile);

		const JIndex rowIndex =
			itsBindingList->AddBinding("", cmd, type, singleFile);
		InsertRows(rowIndex, 1);
		BeginEditing(JPoint(kPatternColumn, rowIndex));
		Broadcast(DataChanged());
		}
}
void
GPrefsMgr::SetInboxes
	(
	const JPtrArray<JString>& inboxes
	)
{
	const JSize count = inboxes.GetElementCount();

	std::ostringstream data;
	data << count;

	for (JIndex i=1; i<=count; i++)
		{
		data << ' ' << *(inboxes.NthElement(i));
		}

	SetData(kGInboxesID, data);
	Broadcast(InboxesChanged());
}
예제 #18
0
void
JXRadioGroup::NewSelection
	(
	JXRadioButton* button
	)
{
	assert( button != NULL );

	if (itsSelection != button)
		{
		if (itsSelection != NULL)
			{
			itsSelection->Deselect();
			}
		itsSelection = button;
		itsSelection->Select();
		Broadcast(SelectionChanged(itsSelection->GetID()));
		}
}
예제 #19
0
void ShuffleRound::BroadcastPublicKeys()
{
    _state = KeySharing;
    int idx = _group.GetIndex(_local_id);
    int kidx = _group.GetSize() - 1 - idx;
    _public_inner_keys[kidx] = _inner_key->GetPublicKey();
    _public_outer_keys[kidx] = _outer_key->GetPublicKey();
    QByteArray inner_key = _public_inner_keys[kidx]->GetByteArray();
    QByteArray outer_key = _public_outer_keys[kidx]->GetByteArray();

    QByteArray msg;
    QDataStream stream(&msg, QIODevice::WriteOnly);
    stream << PublicKeys << GetId().GetByteArray() << inner_key << outer_key;

    Broadcast(msg);
    if(++_keys_received == _group.GetSize()) {
        SubmitData();
    }
}
예제 #20
0
void
GMApp::OpenMailbox
	(
	const JCharacter*	filename,
	const JBoolean		beep,
	const JBoolean		iconify
	)
{
	if (JDirectoryExists(filename))
		{
		const JCharacter* map[] =
			{
			"dir", filename
			};
		const JString msg = JGetString("NameIsDirectoryNotFile::GMApp", map, sizeof(map));
		JGetUserNotification()->ReportError(msg);
		return;
		}
		
	if (MailboxOpen(filename, !iconify))
		{
		return;
		}

	JString mailbox(filename);
	JBoolean locked = FileLocked(mailbox, kJFalse);
	GMessageTableDir* dir;

	if (!locked)
		{
		if (GLockFile(mailbox) && GMessageTableDir::Create(this, mailbox, &dir, iconify))
			{
			itsTableDirs->Append(dir);
			GUnlockFile(mailbox);
			Broadcast(MailboxOpened(mailbox));
			if (beep && GGetPrefsMgr()->IsBeepingOnNewMail())
				{
				GetCurrentDisplay()->Beep();
				}
			}
		}
}
예제 #21
0
void HandleDisconnect(int reason, ENetPeer* source)
{	
	Player* p = board->getPlayerByAddress((int)source);
	ostringstream output;
	if (p != NULL) {
		if (board->isStarted()) {
			// mark player as lost
			p->isDefeated(true);
			output << "SD" << p->getId() << "\0";
			Broadcast(output.str().c_str(),true);
			printf("Player %d disconnected. Signalled as lost.\n",p->getId());
		} else {
			// remove player from play list
			board->removePlayer(p->getId());
			printf("Player %d disconnected. Removed from player list.\n",p->getId());
		}
		PrintBoard();
	}
	// Aw, someone left the game.
}
예제 #22
0
파일: Test1.c 프로젝트: dragosht/courses
void Test1()//micro
{
	m=Create(1,SIGNAL_AND_WAIT);
	test("Create",m!=NULL);
	
	test("Enter",Enter(m)==0);
	test("Enter",Enter(m)==-1);
	test("Leave",Leave(m)==0);
	
	test("Leave",Leave(m)==-1);
	test("Wait",Wait(m,2)==-1);
	test("Signal",Signal(m,2)==-1);
	test("Broadcast",Broadcast(m,3)==-1);
	
	test("Enter",Enter(m)==0);
	test("Distroy", Destroy(m)==-1);
	test("Leave",Leave(m)==0);
	
	test("Destroy",Destroy(m)==0);
}
void
CBStylerBase::ExtractStyles()
{
	assert( itsEditDialog != NULL );

	JBoolean active;
	JArray<JFontStyle> newTypeStyles = *itsTypeStyles;
	JStringMap<JFontStyle> newWordStyles;
	itsEditDialog->GetData(&active, &newTypeStyles, &newWordStyles);
	if (active != IsActive() ||
		TypeStylesChanged(newTypeStyles) ||
		WordStylesChanged(newWordStyles))
		{
		itsEditDialog->GetData(&active, itsTypeStyles, itsWordStyles);

		SetActive(active);
		(CBMGetDocumentManager())->StylerChanged(this);

		Broadcast(WordListChanged(*itsWordStyles));
		}
}
JBoolean
SCCircuitVarList::SetFunction
	(
	const JIndex		index,
	const JFunction&	f
	)
{
	if (IsFunction(index))
		{
		VarInfo info = itsVars->GetElement(index);
		delete (info.f);
		info.f = f.Copy();
		itsVars->SetElement(index, info);
		Broadcast(VarValueChanged(index,1));
		return kJTrue;
		}
	else
		{
		return kJFalse;
		}
}
예제 #25
0
void CChatChannel::RevokeVoice(CChatChanMember * pByMember, LPCTSTR pszName)
{
	ADDTOCALLSTACK("CChatChannel::RevokeVoice");
	if (!IsModerator(pByMember->GetChatName()))
	{
		pByMember->SendChatMsg(CHATMSG_MustHaveOps);
		return;
	}
	CChatChanMember * pMember = FindMember(pszName);
	if (!pMember)
	{
		pByMember->SendChatMsg(CHATMSG_NoPlayer, pszName);
		return;
	}
	if (!HasVoice(pszName))
		return;
	SetVoice(pszName, false);
	SendThisMember(pMember); // Update the color
	pMember->SendChatMsg(CHATMSG_ModeratorRemovedSpeaking, pByMember->GetChatName());
	Broadcast(CHATMSG_PlayerNoSpeaking, pszName, "", "");
}
예제 #26
0
void CChatChannel::GrantModerator(CChatChanMember * pByMember, LPCTSTR pszName)
{
	ADDTOCALLSTACK("CChatChannel::GrantModerator");
	if (!IsModerator(pByMember->GetChatName()))
	{
		pByMember->SendChatMsg(CHATMSG_MustHaveOps);
		return;
	}
	CChatChanMember * pMember = FindMember(pszName);
	if (!pMember)
	{
		pByMember->SendChatMsg(CHATMSG_NoPlayer, pszName);
		return;
	}
	if (IsModerator(pMember->GetChatName()))
		return;
	SetModerator(pszName, true);
	SendThisMember(pMember); // Update the color
	Broadcast(CHATMSG_PlayerIsAModerator, pMember->GetChatName(), "", "");
	pMember->SendChatMsg(CHATMSG_YouAreAModerator, pByMember->GetChatName());
}
void
JXDisplayMenu::ChooseDisplay
	(
	const JIndex index
	)
{
	if (index < itsNewDisplayIndex)
		{
		itsDisplayIndex = index;
		Broadcast(DisplayChanged(itsDisplayIndex));
		}
	else
		{
		assert( itsNewDisplayDialog == NULL );
		JXWindowDirector* supervisor = (GetWindow())->GetDirector();
		itsNewDisplayDialog = new JXOpenDisplayDialog(supervisor);
		assert( itsNewDisplayDialog != NULL );
		ListenTo(itsNewDisplayDialog);
		itsNewDisplayDialog->BeginDialog();
		}
}
예제 #28
0
void CChatChannel::RevokeModerator(CChatChanMember * pByMember, LPCTSTR pszName)
{
	ADDTOCALLSTACK("CChatChannel::RevokeModerator");
	if (!IsModerator(pByMember->GetChatName()))
	{
		pByMember->SendChatMsg(CHATMSG_MustHaveOps);
		return;
	}
	CChatChanMember * pMember = FindMember(pszName);
	if (!pMember)
	{
		pByMember->SendChatMsg(CHATMSG_NoPlayer, pszName);
		return;
	}
	if (!IsModerator(pMember->GetChatName()))
		return;
	SetModerator(pszName, false);
	SendThisMember(pMember); // Update the color
	Broadcast(CHATMSG_PlayerNoLongerModerator, pMember->GetChatName(), "", "");
	pMember->SendChatMsg(CHATMSG_RemovedListModerators, pByMember->GetChatName());
}
JBoolean
SCComponentMenu::SetCompIndex
	(
	const JIndex compIndex
	)
{
	JIndex menuIndex;
	if (CompIndexToMenuIndex(compIndex, &menuIndex))
		{
		itsMenuIndex = menuIndex;
		SetPopupChoice(itsMenuIndex);
		if (itsBroadcastCompChangeFlag)
			{
			Broadcast(ComponentChanged(compIndex));
			}
		return kJTrue;
		}
	else
		{
		return kJFalse;
		}
}
예제 #30
0
void
XDLink::SetValue
	(
	const JCharacter* name,
	const JCharacter* value
	)
{
	if (ProgramIsStopped())
		{
		const JString encValue = JString(value).EncodeBase64();

		JString cmd = "property_set @i -n ";
		cmd        += name;
		cmd        += " -l ";
		cmd        += encValue.GetLength();
		cmd        += " -- ";
		cmd        += encValue;
		Send(cmd);

		Broadcast(ValueChanged());
		}
}