Esempio n. 1
0
void
CMLink::HandleCommandRunning
	(
	const JIndex cmdID
	)
{
	assert( itsRunningCommand == NULL );

	const JSize fgCount = itsForegroundQ->GetElementCount();
	for (JIndex i=1; i<=fgCount; i++)
		{
		CMCommand* command = itsForegroundQ->NthElement(i);
		if (command->GetTransactionID() == cmdID)
			{
			itsRunningCommand = command;
			itsForegroundQ->RemoveElement(i);
			break;
			}
		}

	if (itsRunningCommand == NULL && !itsBackgroundQ->IsEmpty())
		{
		CMCommand* command = itsBackgroundQ->FirstElement();
		if (command->GetTransactionID() == cmdID)
			{
			itsRunningCommand = command;
			itsBackgroundQ->RemoveElement(1);
			}
		}
}
Esempio n. 2
0
void
CMLink::CancelBackgroundCommands()
{
	for (JIndex i=itsBackgroundQ->GetElementCount(); i>=1; i--)
		{
		CMCommand* cmd = itsBackgroundQ->NthElement(i);
		itsBackgroundQ->RemoveElement(i);	// remove first, in case auto-delete
		cmd->Finished(kJFalse);

		if (itsRunningCommand == cmd)
			{
			itsRunningCommand = NULL;
			}
		}
}
Esempio n. 3
0
void
CMLink::DeleteOneShotCommands
	(
	JPtrArray<CMCommand>* list
	)
{
	const JSize count = list->GetElementCount();
	for (JIndex i=count; i>=1; i--)
		{
		CMCommand* cmd = list->NthElement(i);
		if (cmd->IsOneShot())
			{
			delete cmd;		// automatically removed from list
			}
		}
}
Esempio n. 4
0
void
CMLink::RunNextCommand()
{
	if (!itsForegroundQ->IsEmpty() && OKToSendMultipleCommands())
		{
		const JSize count = itsForegroundQ->GetElementCount();
		for (JIndex i=1; i<=count; i++)
			{
			CMCommand* command = itsForegroundQ->NthElement(i);
			if (command->GetState() != CMCommand::kExecuting)
				{
				SendMedicCommand(command);
				}
			}
		}
	else if (!itsForegroundQ->IsEmpty())
		{
		CMCommand* command = itsForegroundQ->FirstElement();
		if (command->GetState() != CMCommand::kExecuting && OKToSendCommands(kJFalse))
			{
			SendMedicCommand(command);
			}
		}
	else if (!itsBackgroundQ->IsEmpty() && OKToSendCommands(kJTrue))
		{
		CMCommand* command = itsBackgroundQ->FirstElement();
		if (command->GetState() != CMCommand::kExecuting)
			{
			SendMedicCommand(command);
			}
		}
}
Esempio n. 5
0
void
XDLink::ReceiveMessageFromDebugger()
{
	itsLink->StopTimer();

	JString data;
	const JBoolean ok = itsLink->GetNextMessage(&data);
	assert( ok );

	if (data.IsEmpty() || data.GetFirstCharacter() != '<')
		{
		return;
		}

	Broadcast(DebugOutput(data, kOutputType));

	if (itsInitFinishedFlag)
		{
		if (!itsProgramIsStoppedFlag)
			{
			itsProgramIsStoppedFlag = kJTrue;
			Broadcast(ProgramStopped(CMLocation("", 1)));
			}

		itsDebuggerBusyFlag = kJFalse;
		Broadcast(DebuggerReadyForInput());
		}

	xmlDoc* doc = xmlReadMemory(data.GetCString(), data.GetLength(),
								NULL, NULL, XML_PARSE_NOCDATA);
	if (doc != NULL)
		{
		xmlNode* root = xmlDocGetRootElement(doc);

		if (root != NULL && strcmp((char*) root->name, "init") == 0)
			{
			itsIDEKey         = JGetXMLNodeAttr(root, "idekey");
			const JString uri = JGetXMLNodeAttr(root, "fileuri");

			const JCharacter* map[] =
				{
				"idekey", itsIDEKey,
				"uri",    uri
				};
			JString msg = JGetString("ConnectionInfo::XDLink", map, sizeof(map));
			Broadcast(UserOutput(msg, kJFalse));

			Send("feature_set -n show_hidden -v 1");
			Send("step_into");

			JString programName;
			GetProgram(&programName);

			Broadcast(AttachedToProcess());
			Broadcast(SymbolsLoaded(JI2B(uri == itsScriptURI), programName));

			itsInitFinishedFlag = kJTrue;
			itsScriptURI        = uri;
			}
		else if (root != NULL && strcmp((char*) root->name, "response") == 0)
			{
			const JString status = JGetXMLNodeAttr(root, "status");
			const JString reason = JGetXMLNodeAttr(root, "reason");
			if (status == "break" && reason == "error" &&
				root->children != NULL && root->children->children != NULL &&
				strcmp((char*) root->children->name, "error") == 0 &&
				root->children->children->type == XML_TEXT_NODE)
				{
				JString msg            = (char*) root->children->children->content;
				const JString encoding = JGetXMLNodeAttr(root->children, "encoding");
				if (encoding == "base64")
					{
					msg.DecodeBase64(&msg);
					}
				msg += "\n";
				Broadcast(UserOutput(msg, kJTrue));
				}

			const JString idStr = JGetXMLNodeAttr(root, "transaction_id");
			JUInt id;
			if (idStr.ConvertToUInt(&id))
				{
				HandleCommandRunning(id);
				}

			CMCommand* cmd;
			if (GetRunningCommand(&cmd))
				{
				itsParsedDataRoot = root;

				cmd->Finished(JI2B(
					root->children == NULL || strcmp((char*) root->children->name, "error") != 0));

				itsParsedDataRoot = NULL;

				SetRunningCommand(NULL);
				if (!HasForegroundCommands())
					{
					RunNextCommand();
					}
				}

			if (status == "stopping" || status == "stopped")
				{
				CancelAllCommands();

				XDCloseSocketTask* task = new XDCloseSocketTask(itsLink);
				assert( task != NULL );
				task->Go();
				}
			}

		xmlFreeDoc(doc);
		}
}