示例#1
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;
			}
		}
}
示例#2
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);
		}
}