Ejemplo n.º 1
1
bool Ctrl::SetWndFocus()
{
	GuiLock __;
	LLOG("SetWndFocus0 " << Upp::Name(this) << ", top: " << top);
	if(top) {
		LLOG("SetWndFocus0 DO gdk: " << gdk());
		SetWndForeground();
		int t0 = msecs();
		while(!gtk_window_is_active(gtk()) && msecs() - t0 < 500) // Wait up to 500ms for window to become active - not ideal, but only possibility
			FetchEvents(true);
		FocusSync();
	}
	return true;
}
Ejemplo n.º 2
0
/*
 * intel_wait_for_pipe_off - wait for pipe to turn off
 * @dev: drm device
 * @pipe: pipe to wait for
 *
 * After disabling a pipe, we can't wait for vblank in the usual way,
 * spinning on the vblank interrupt status bit, since we won't actually
 * see an interrupt when the pipe is disabled.
 *
 * On Gen4 and above:
 *   wait for the pipe register state bit to turn off
 *
 * Otherwise:
 *   wait for the display line value to settle (it usually
 *   ends up stopping at the start of the next frame).
 *
 */
void intel_wait_for_pipe_off(struct drm_device *dev, int pipe)
{
	struct drm_i915_private *dev_priv = dev->dev_private;

	if (INTEL_INFO(dev)->gen >= 4) {
		int reg = PIPECONF(pipe);

		/* Wait for the Pipe State to go off */
		if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
			     100))
			fprintf(stderr, "pipe_off wait timed out\n");
	} else {
		u32 last_line;
		int reg = PIPEDSL(pipe);
		unsigned long timeout = msecs() + 100;

		/* Wait for the display line to settle */
		do {
			last_line = I915_READ(reg) & DSL_LINEMASK;
			mdelay(5);
		} while (((I915_READ(reg) & DSL_LINEMASK) != last_line) &&
			 (timeout> msecs()));
		if ((msecs()> timeout))
			fprintf(stderr, "pipe_off wait timed out\n");
	}
}
Ejemplo n.º 3
0
void StopService()
{
	service_stopped = true;
	int start = msecs();
	while(msecs(start) < 10000 && !service_exited)
		Sleep(100);
}
Ejemplo n.º 4
0
void AutosaveTest::successTest()
{
	AutosaveTestDocument doc(Autosave::Success);
	
	// Enable and trigger Autosave
	doc.setAutosaveNeeded(true);
	
	// Verify that Autosave does not trigger too early
	QThread::msleep(msecs(0.9 * autosave_interval));
	QCoreApplication::processEvents();
	QCOMPARE(doc.autosaveCount(), 0);
	
	// Verify that Autosave does trigger exactly once before too late
	QThread::msleep(msecs(0.2 * autosave_interval));
	QCoreApplication::processEvents();
	QCOMPARE(doc.autosaveCount(), 1);
	
	// Verify that Autosave does not trigger again too early
	QThread::msleep(msecs(0.9 * autosave_interval));
	QCoreApplication::processEvents();
	QCOMPARE(doc.autosaveCount(), 1);
	
	// Verify that Autosave does trigger again once before too late
	QThread::msleep(msecs(0.2 * autosave_interval));
	QCoreApplication::processEvents();
	QCOMPARE(doc.autosaveCount(), 2);
}
Ejemplo n.º 5
0
void Timer::GlobalTick()
{
	map<NetworkID, Timer*>::iterator it;

	for (it = timers.begin(); it != timers.end();)
	{
		Timer* timer = it->second;

		if (timer->markdelete)
		{
			timers.erase(it++);
			delete timer;
			continue;
		}

		if ((msecs() - timer->ms) > timer->interval)
		{
			last_timer = it->first;
			timer->Call(timer->args);
			timer->ms = msecs();
		}

		++it;
	}
}
Ejemplo n.º 6
0
int Socket::Data::Read(void *buf, int amount)
{
	int res = recv(socket, (char *)buf, amount, 0);
#if FAKESLOWLINE
	if(res > 0) {
		int end = msecs() + iscale(res, 10000, FAKESLOWLINE) + 10;
		for(int delta; (delta = end - msecs()) > 0; Sleep(delta))
			;
	}
#endif
#ifndef NOFAKEERROR
	if(fake_error && res > 0) {
		if((fake_error -= res) <= 0) {
			fake_error = 0;
			if(sock)
				sock->SetSockError(socket, "recv", 1, "fake error");
			return -1;
		}
		else
			LLOG("Socket::Data::Read: fake error after " << fake_error);
	}
#endif
	if(res == 0)
		is_eof = true;
	else if(res < 0 && Socket::GetErrorCode() != IS_BLOCKED)
		SetSockError("recv");
	return res;
}
Ejemplo n.º 7
0
bool Console::Wait()
{
	int ms0 = msecs();
	for(;;) {
		if(ms0 != msecs()) {
			ProcessEvents();
			ms0 = msecs();
		}
		if(Flush() == -1)
			return error_keys.IsEmpty();
		Sleep(0);
	}
}
Ejemplo n.º 8
0
void Console::Wait(int slot)
{
	int ms0 = msecs();
	while(processes[slot].process) {
		if(ms0 != msecs()) {
			ProcessEvents();
			ms0 = msecs();
		}
		if(Flush() == -1)
			return;
		Sleep(0);
	}
}
Ejemplo n.º 9
0
// read data, requested amount, blocks 'timeout' milliseconds
// if reqSize == 0 just read all available data, waiting for 'timeout' if != 0
String Serial::Read(size_t reqSize, uint32_t timeout)
{
	char buf[1001];
	buf[1000] = 0;
	String data;

	size_t n;
	uint32_t tim = msecs() + timeout;
	if(reqSize)
	{
		n = min(reqSize, (size_t)1000);
		while(reqSize)
		{
			n = read(fd, buf, n);
			if(!n)
			{
				if((uint32_t)msecs() > tim)
					break;
				n = min(reqSize, (size_t)1000);
				continue;
			}
			tim = msecs() + timeout;
			if(n)
			{
				reqSize -= n;
				data.Cat(buf, n);
			}
			n = min(reqSize, (size_t)1000);
		}
	}
	else
	{
		for(;;)
		{
			n = read(fd, buf, 1000);
			if(!n)
			{
				if((uint32_t)msecs() > tim)
					break;
				continue;
			}
			tim = msecs() + timeout;
			if(n)
				data.Cat(buf, n);
		}
	}
	return data;	
}
Ejemplo n.º 10
0
// write a single byte
bool Serial::Write(char c, uint32_t timeout)
{
	if(!timeout)
		return write(fd, &c, 1);

	uint32_t tim = msecs() + timeout;
	for(;;)
	{
		if(write(fd, &c, 1) == 1)
			return true;
		if((uint32_t)msecs() > tim)
			break;
	}
	
	return false;
}
Ejemplo n.º 11
0
void VfkStream::SpeedTest()
{
	for(int i = 0; i < tables.GetCount(); i++) {
		int begin = msecs();
		Data data = GetData(tables[i].name);
		int get = msecs();
		if(data.GetCount() > 0)
			data[0];
		int first = msecs();
		for(int r = 1; r < data.GetCount(); r++)
			data[r];
		int nth = msecs();
		puts(NFormat("%s: get(%d), first(%d), nth(%2v)",
			tables[i].name, get - begin, first - get, (nth - first) / max<double>((double)data.GetCount() - 1, 1)));
	}
}
Ejemplo n.º 12
0
bool UninstallService(String name, String& status)
{
	ServiceHandle scm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	if(!scm) {
		status = "Cannot open service manager";
		return false;
	}

	ServiceHandle me = OpenService(scm, name, SC_MANAGER_ALL_ACCESS);
	if(!me) {
		status = "Cannot open service.";
		return false;
	}
	SERVICE_STATUS srvstat;
	if(ControlService(me, SERVICE_CONTROL_STOP, &srvstat)) {
		int start = msecs();
		while(QueryServiceStatus(me, &srvstat) && srvstat.dwCurrentState != SERVICE_STOPPED && msecs(start) < 10000)
			Sleep(100);
	}
	if(!DeleteService(me)) {
		status = NFormat("Error deleting service: %s", GetLastErrorMessage());
		return false;
	}
	return true;
}
Ejemplo n.º 13
0
void Console::CheckEndGroup()
{
	for(int g = groups.GetCount(); --g >= 0;) {
		String gname = groups.GetKey(g);
		Group& group = groups[g];
		if(!IsNull(gname) && group.finished) {
			int p = processes.GetCount();
			while(--p >= 0 && !(!!processes[p].process && processes[p].group == gname))
				;
			if(p < 0) {
				if(group.count > 0) {
					int duration = msecs(group.start_time);
					String msg = NFormat("%s: %d file(s) built in %s, %d msecs / file, duration = %d msecs",
						gname, group.count, PrintTime(group.msecs), group.msecs / group.count, duration);
					if(processes.GetCount() > 1) {
						int k = 100 * processes.GetCount() / (processes.GetCount() - 1);
						msg << NFormat(", parallelization %d%%", minmax(k - group.msecs * k / max(group.raw_msecs, 1), 0, 100));
					}
					msg << '\n';
					spooled_output.Cat(msg);
					if(console_lock < 0) {
						Append(spooled_output);
						spooled_output = Null;
					}
				}
				groups.Remove(g);
			}
		}
	}
}
Ejemplo n.º 14
0
bool Console::Run(One<AProcess> pick_ process, const char *cmdline, Stream *out, bool quiet, int slot, String key, int blitz_count)
{
	if(!process) {
		if(verbosebuild)
			spooled_output << "Error running " << cmdline << "\n";
		FlushConsole();
		return false;
	}
	else if(verbosebuild)
		spooled_output << cmdline << "\n";
	Wait(slot);
	Slot& pslot = processes[slot];
	pslot.process = pick(process);
	pslot.cmdline = cmdline;
	pslot.outfile = out;
	pslot.output = Null;
	pslot.quiet = quiet;
	pslot.key = key;
	pslot.group = current_group;
	pslot.last_msecs = msecs();
	pslot.serial = ++serial;
	groups.GetAdd(pslot.group).count += blitz_count;
	if(processes.GetCount() == 1)
		Wait(slot);
	return true;
}
Ejemplo n.º 15
0
int Console::AllocSlot()
{
	int ms0 = msecs();
	
	for(;;) {
		for(int i = 0; i < processes.GetCount(); i++)
			if(!IsRunning(i))
				return i;
		Flush();
		Sleep(0);
		if(ms0 != msecs()) {
			ProcessEvents();
			ms0 = msecs();
		}
	}
}
Ejemplo n.º 16
0
bool Serial::Read(char &c, uint32_t timeout)
{
	char buf[1];
	
	uint32_t tim = msecs() + timeout;
	for(;;)
	{
		if(!read(fd, buf, 1))
		{
			if((uint32_t)msecs() > tim)
				return false;
			continue;
		}
		c = buf[0];
		return true;
	}		
}
Ejemplo n.º 17
0
String Ctrl::DragGet(const char *fmt)
{
	LLOG("DragGet " << fmt << " " << (Ctrl::dnd_targets.Find(fmt) >= 0));
	if(Ctrl::dnd_targets.Find(fmt) < 0)
		return Null;
	dnd_data.Clear();
	dnd_data_wait = true;
	dnd_data_fmt = fmt;
	int t0 = msecs();
	gtk_drag_get_data(dnd_widget, dnd_context,
	                  GAtom(strcmp(fmt, "image") == 0 ? ~dnd_image_target :
	                        strcmp(fmt, "text") == 0 ? ~dnd_text_target :
	                        strcmp(fmt, "files") == 0 ? ~dnd_files_target : fmt),
	                  dnd_time);
	while(msecs() - t0 < 1000 && dnd_data_wait)
		FetchEvents(true);
	LLOG("DragGet data length " << dnd_data.GetLength());
	return dnd_data;
}
Ejemplo n.º 18
0
String Gdb::Cmd(const char *command)
{
	if(!dbg || !dbg->IsRunning() || IdeIsDebugLock()) return Null;
#ifdef _DEBUG
	TimeStop ts;
#endif
	Lock();
	if(command) {
		LLOG("========= Cmd: " << command);
		dbg->Write(String(command) + "\n");
		PutVerbose(command);
	}
	String result;
	int ms0 = msecs();
	while(dbg) {
		String s;
		if(!dbg->Read(s)) {
			PutVerbose(result);
			PutVerbose("Debugger terminated");
			break;
		}
		if(!s.IsEmpty() && Result(result, s)) {
			LLOG(result);
			PutVerbose(result);
			break;
		}
		if(ms0 != msecs()) {
			ProcessEvents();
			ms0 = msecs();
		}
//		if(s.GetCount() == 0)
			GuiSleep(0);
		if(TTYQuit())
			Stop();
	}
	Unlock();
#ifdef _DEBUG
	if(command)
		LLOG("Cmd Time of `" << command <<"` " << ts);
#endif
	return result;
}
Ejemplo n.º 19
0
void Ctrl::WndSetPos(const Rect& rect)
{
	LLOG("WndSetPos0 " << rect);
	GuiLock __;
	if(!IsOpen())
		return;
	Ptr<Ctrl> this_ = this;
	SweepConfigure(false); // Remove any previous GDK_CONFIGURE for this window
	if(!this_ || !IsOpen())
		return;
//	gtk_window_move(gtk(), rect.left, rect.top);
//	gtk_window_resize(gtk(), rect.GetWidth(), rect.GetHeight());
	gdk_window_move_resize(gdk(), rect.left, rect.top, rect.GetWidth(), rect.GetHeight());
	int t0 = msecs();
	do { // Wait up to 500ms for corresponding GDK_CONFIGURE to arrive
		if(SweepConfigure(true))
			break;
	}
	while(msecs() - t0 < 500);
	LLOG("-- WndSetPos0 " << rect << " " << msecs() - t0);
}
Ejemplo n.º 20
0
int Console::Flush()
{
	bool done_output = false;
	int num_running = 0;
	for(int i = 0; i < processes.GetCount(); i++)
		if(!!processes[i].process)
			num_running++;
	if(num_running) {
		int time = msecs();
		for(int i = 0; i < processes.GetCount(); i++) {
			Slot& slot = processes[i];
			if(!!slot.process) {
				Group& group = groups.GetAdd(slot.group);
				group.msecs += (time - slot.last_msecs) / num_running;
				group.raw_msecs += time - slot.last_msecs;
				slot.last_msecs = time;
			}
		}
	}
	bool running = false;
	for(int i = 0; i < processes.GetCount(); i++) {
		Slot& slot = processes[i];
		if(!slot.process)
			continue;
		String s;
		slot.process->Read(s);
		if(!IsNull(s)) {
			done_output = true;
			if(slot.outfile)
				slot.outfile->Put(s);
			if(!slot.quiet) {
				if(console_lock < 0 || console_lock == i) {
					console_lock = i;
					AppendOutput(s);
				}
				else
					slot.output.Cat(s);
			}
		}
		if(!slot.process->IsRunning()) {
			Kill(i);
			if(slot.exitcode != 0 && verbosebuild)
				spooled_output.Cat("Error executing " + slot.cmdline + "\n");
			if(console_lock == i)
				console_lock = -1;
			FlushConsole();
			CheckEndGroup();
			continue;
		}
		running = true;
	}
	return !running ? -1 : done_output ? 1 : 0;
}
Ejemplo n.º 21
0
// writes data
bool Serial::Write(String const &data, uint32_t timeout)
{
	int dLen = data.GetCount();
	if(!timeout)
		return (write(fd, ~data, data.GetCount()) == dLen);

	uint32_t tim = msecs() + timeout;
	const char *dPos = ~data;
	for(;;)
	{
		int written = write(fd, dPos, dLen);
		if(written == dLen)
			return true;
		if(written >= 0)
		{
			dPos += written;
			dLen -= written;
			continue;
		}
		if((uint32_t)msecs() >= tim)
			break;
	}
	return false;
}
Ejemplo n.º 22
0
bool Ctrl::IsWaitingEvent()
{
	GuiLock __;
	if(quit) {
		WhenDisconnect();
		EndSession();
		Exit(0);
	}
	while(socket.Timeout(0).WaitRead()) {
		socket.Timeout(20000);
		String s = websocket.Recieve();
		if(s.IsVoid()) { // No data returned -> means EOF was reached
			WhenDisconnect();
			EndSession();
			Exit(0);
		}
		LLOG("Recieved data " << s);
		StringStream ss(s);
		while(!ss.IsEof()) {
			String s = ss.GetLine();
			CParser p(s);
			try {
				if(p.Id("S")) {
					uint32 l = p.ReadNumber();
					uint32 h = p.ReadNumber();
					recieved_update_serial = MAKEQWORD(l, h);
					stat_client_ms = p.ReadNumber();
				}
				else
					event_queue.AddTail(s);
			}
			catch(CParser::Error) {}
		}
		if(recieved_update_serial == serial_0) {
			serial_0 = 0;
			stat_roundtrip_ms = msecs() - serial_time0;
			serial_time0 = Null;
		}
	}
	socket.Timeout(20000);
	if(socket.IsError())
		LLOG("ERROR: " << socket.GetErrorDesc());
	return event_queue.GetCount();
}
Ejemplo n.º 23
0
void Ide::BuildAndExecute()
{
	if(Build()) {
		int time = msecs();
		One<Host> h = CreateHostRunDir();
		h->ChDir(Nvl(rundir, GetFileFolder(target)));
		String cmdline;
		if(!runexternal)
			cmdline << '\"' << h->GetHostPath(target) << "\" ";
		cmdline << ToSystemCharset(runarg);
		int exitcode;
		switch(runmode) {
		case RUN_WINDOW:
			HideBottom();
			h->Launch(cmdline, FindIndex(SplitFlags(mainconfigparam, true), "GUI") < 0);
			break;
		case RUN_CONSOLE:
			ShowConsole();
			PutConsole(String().Cat() << "Executing: " << cmdline);
			console.Sync();
			exitcode = h->ExecuteWithInput(cmdline);
			PutConsole("Finished in " + GetPrintTime(time) + ", exit code: " + AsString(exitcode));
			break;
		case RUN_FILE: {
				HideBottom();
				String fn;
				if(IsNull(stdout_file))
					fn = ForceExt(target, ".ol");
				else
					fn = stdout_file;
				FileOut out(fn);
				if(!out) {
					PromptOK("Unable to open output file [* " + DeQtf(stdout_file) + "] !");
					return;
				}
				if(h->Execute(cmdline, out) >= 0) {
					out.Close();
					EditFile(fn);
				}
			}
		}
	}
}
Ejemplo n.º 24
0
void AutosaveTest::autosaveStopTest()
{
	{
		AutosaveTestDocument doc(Autosave::Success);
		
		// Enable and trigger Autosave
		doc.setAutosaveNeeded(true);
		
		// Sleep some time
		QThread::msleep(msecs(0.3 * autosave_interval));
		QCoreApplication::processEvents();
		QCOMPARE(doc.autosaveCount(), 0);
		
		// Verify that Autosave does not trigger after setAutosaveNeeded(false)
		doc.setAutosaveNeeded(false);
		QThread::msleep(msecs(1.1 * autosave_interval));
		QCoreApplication::processEvents();
		QCOMPARE(doc.autosaveCount(), 0);
	}
	
	{
		AutosaveTestDocument doc(Autosave::TemporaryFailure);
		
		// Test stopping autosave in temporary failure mode
		doc.setAutosaveNeeded(true);
		QThread::msleep(msecs(1.1 * autosave_interval));
		QCoreApplication::processEvents();
		QCOMPARE(doc.autosaveCount(), 1);
		
		doc.setAutosaveNeeded(false);
		QThread::msleep(msecs(autosave_interval) + 6000);
		QCoreApplication::processEvents();
		QCOMPARE(doc.autosaveCount(), 1);
	}
	
	{
		AutosaveTestDocument doc(Autosave::PermanentFailure);
		
		// Test stopping autosave in permament failure mode
		doc.setAutosaveNeeded(true);
		QThread::msleep(msecs(1.1 * autosave_interval));
		QCoreApplication::processEvents();
		QCOMPARE(doc.autosaveCount(), 1);
		
		doc.setAutosaveNeeded(false);
		QThread::msleep(msecs(1.1 * autosave_interval));
		QCoreApplication::processEvents();
		QCOMPARE(doc.autosaveCount(), 1);
	}
}
Ejemplo n.º 25
0
bool InstallService(String name, String display_name, String& cmdline, String& status)
{
	ServiceHandle scm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	if(!scm) {
		status = "Cannot open service manager";
		return false;
	}
	ServiceHandle me = OpenService(scm, name, SC_MANAGER_ALL_ACCESS);
	if(me) {
		SERVICE_STATUS srvstat;
		if(ControlService(me, SERVICE_CONTROL_STOP, &srvstat)) {
			int start = msecs();
			while(QueryServiceStatus(me, &srvstat) && srvstat.dwCurrentState != SERVICE_STOPPED && msecs(start) < 10000)
				Sleep(100);
		}
		if(!DeleteService(me)) {
			status = NFormat("Error deleting existing service: %s", GetLastErrorMessage());
			return false;
		}
		me.Close();
	}

	me = CreateService(scm, name, display_name,
		SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
		SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
		cmdline, 0, 0, 0, 0, 0);
	if(!me) {
		status = NFormat("Error creating service: %s", GetLastErrorMessage());
		return false;
	}
	if(!StartService(me, 0, NULL)) {
		status = NFormat("Error starting service: %s", GetLastErrorMessage());
		return false;
	}
	return true;
}
Ejemplo n.º 26
0
LRESULT CALLBACK Ctrl::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	GuiLock __;
	if(sFinished)
		return DefWindowProc(hWnd, message, wParam, lParam);
#ifdef PLATFORM_WINCE
	if(message == WM_CREATE)
#else
	if(message == WM_NCCREATE)
#endif
	{
		Ctrl *w = (Ctrl *)((LPCREATESTRUCT) lParam)->lpCreateParams;
		if(w) {
			w->NcCreate(hWnd);
			int i = Windows().Find(NULL);
			if(i >= 0) {
				Windows().SetKey(i, hWnd);
				Windows()[i] = w;
			}
			else
				Windows().Add(hWnd) = w;
		}
	}
	Ctrl *w = Windows().Get(hWnd, NULL);
#ifdef PLATFORM_WINCE
	if(message == WM_DESTROY)
#else
	if(message == WM_NCDESTROY)
#endif
	{
		if(w) w->NcDestroy();
		int i = Windows().Find(hWnd);
		if(i >= 0)
			Windows().SetKey(i, NULL);
	}
#if LOGMESSAGES
	bool logblk = false;
	if(message != WM_SETCURSOR && message != WM_CTLCOLORBTN && message != WM_TIMER &&
#ifndef PLATFORM_WINCE
	   message != WM_NCHITTEST  &&  message != WM_ENTERIDLE &&
#endif
	   message != WM_CTLCOLORDLG && message != WM_CTLCOLOREDIT && message != WM_CTLCOLORLISTBOX &&
	   message != WM_CTLCOLORMSGBOX && message != WM_CTLCOLORSCROLLBAR &&
	   message != WM_CTLCOLORSTATIC && message != WM_CANCELMODE &&
	   message != 0x0118)
		for(WinMsg *m = sWinMsg; m->ID; m++)
			if(m->ID == message) {
				RLOG(m->name << ' ' << UPP::Name(w) <<
					Sprintf(", wParam = %d (0x%x), lParam = %d (0x%x)",
					       wParam, wParam, lParam, lParam));
				VppLog() << LOG_BEGIN;
				logblk = true;
				break;
			}
#endif
	LRESULT l = 0;
	if(w) {
#if defined(_DEBUG) && LOGTIMING
			int ticks = msecs();
			String wname = w->Name();
#endif
			Ptr<Ctrl> pw = w;
			l = w->WindowProc(message, wParam, lParam);
			if(pw)
				pw->SyncMoves();
#if defined(_DEBUG) && LOGTIMING
			String msgname;
			for(WinMsg *m = sWinMsg; m->ID; m++)
				if(m->ID == message) {
					msgname = m->name;
					break;
				}
			if(IsNull(msgname))
				msgname = NFormat("0x%04x", (int)message);
			LLOG(NFormat("T+%d %s 0x%08x 0x%08x -> %s", msecs(ticks), msgname, (int)wParam, (int)lParam, wname));
#endif
	}
	else
		l = DefWindowProc(hWnd, message, wParam, lParam);
#if LOGMESSAGES
	if(logblk)
		VppLog() << LOG_END;
#endif
	return l;
}
Ejemplo n.º 27
0
bool Socket::Data::OpenClient(const char *host, int port, bool nodelay, dword *my_addr, int timeout, bool block)
{
	SLOG("Socket::Data::OpenClient(" << host << ':' << port << ", timeout " << timeout << ", block " << block << ')');

	int ticks = msecs();
	sockaddr_in sin;
	sockaddr_in addr;

	{
		CriticalSection::Lock __(GetHostByNameMutex());
		Socket::Init();
		hostent *he = gethostbyname(host);
		if(!he) {
			SetSockError(NFormat("gethostbyname(%s) failed", host));
			return false;
		}

		Zero(sin);
		sin.sin_family = AF_INET;
		sin.sin_port = htons(0);
		sin.sin_addr.s_addr = htonl(INADDR_ANY);

		Zero(addr);
		addr.sin_family = AF_INET;
		addr.sin_port = htons(port);
		addr.sin_addr = *(in_addr *)(he -> h_addr_list[0]);
	}

	if(!Open(block))
		return false;

	if(nodelay)
		NoDelay();

	while(bind(socket, (const sockaddr *)&sin, sizeof(sin))) {
		if(Socket::GetErrorCode() != SOCKERR(EINPROGRESS) || !IsNull(timeout) && msecs(ticks) >= timeout) {
			SetSockError(NFormat("bind(host=%s, port=%d)", FormatIP(Peek32be(&addr.sin_addr)), port));
			return false;
		}
		Sleep(500);
	}
	if(my_addr)
		*my_addr = sin.sin_addr.s_addr;

#if FAKEERROR
	fake_error = (rand() * 11111) % 100000;
	SLOG("Socket::OpenClient -> fake error = " << fake_error);
#else
	fake_error = 0;
#endif

	if(!connect(socket, (sockaddr *)&addr, sizeof(addr)))
		return true;

	int err = Socket::GetErrorCode();
#ifdef PLATFORM_WIN32
	if(err != SOCKERR(EWOULDBLOCK))
#else
	if(err != SOCKERR(EINPROGRESS))
#endif
	{
		SetSockError(NFormat("connect(%s:%d)", host, port));
		SLOG("Socket::Data::OpenClient -> connect error, returning false");
		return false;
	}
/*
	if(!Peek(IsNull(timeout) ? NB_TIMEOUT : max<int>(0, timeout - msecs(ticks)), true)) {
		SetSockError("connect timeout expired");
		return false;
	}
*/
	return true;
}
Ejemplo n.º 28
0
int Timestamp::msecsDiff(const Timestamp &ts) const {
	return msecs() - ts.msecs();
}
Ejemplo n.º 29
0
bool MakeBuild::Build(const Workspace& wspc, String mainparam, String outfile, bool clear_console)
{
	String hfile = outfile + ".xxx";
	SaveFile(hfile, "");
	FileTime start_time = GetFileTime(hfile); // Defensive way to get correct filetime of start
	DeleteFile(hfile);
	
	ClearErrorEditor();
	BeginBuilding(true, clear_console);
	bool ok = true;
	if(wspc.GetCount()) {
		for(int i = 0; i < wspc.GetCount(); i++) {
			const Package& pk = wspc.package[i];
			for(int j = 0; j < pk.GetCount(); j++)
				if(pk[j] == "main.conf") {
					String pn = wspc[i];
					String p = SourcePath(pn, "main.conf");
					main_conf << "// " << pn << "\r\n" << LoadFile(p) << "\r\n";
					PutConsole("Found " + p);
				}
		}

		if(main_conf.GetCount()) {
			VectorMap<String, String> bm = GetMethodVars(method);
			One<Host> host = CreateHost(false);
			One<Builder> b = CreateBuilder(~host);
			if(b) {
				Index<String> mcfg = PackageConfig(wspc, 0, bm, mainparam, *host, *b, NULL);
				String outdir = OutDir(mcfg, wspc[0], bm, false);
				String path = AppendFileName(outdir, "main.conf.h");
				RealizePath(path);
				SaveChangedFile(path, main_conf);
				PutConsole("Saving " + path);
				add_includes << outdir << ';';
			}
		}

		Vector<int> build_order;
		if(GetTargetMode().linkmode != 2) {
			for(int i = 1; i < wspc.GetCount(); i++)
				build_order.Add(i);
		}
		else {
			Index<int> remaining;
			for(int i = 1; i < wspc.GetCount(); i++)
				remaining.Add(i);
			while(!remaining.IsEmpty()) {
				int t;
				for(t = 0; t < remaining.GetCount(); t++) {
					const Package& pk = wspc.package[remaining[t]];
					bool delay = false;
					for(int u = 0; u < pk.uses.GetCount(); u++)
						if(remaining.Find(wspc.package.Find(pk.uses[u].text)) >= 0) {
							delay = true;
							break;
						}
					if(!delay)
						break;
				}
				if(t >= remaining.GetCount())
					t = 0;
				build_order.Add(remaining[t]);
				remaining.Remove(t);
			}
		}

		String mainpackage = wspc[0];
		Vector<String> linkfile;
		String linkopt = GetMethodVars(method).Get(targetmode ? "RELEASE_LINK" : "DEBUG_LINK", Null);
		if(linkopt.GetCount())
			linkopt << ' ';
		ok = true;
		int ms = msecs();
		for(int i = 0; i < build_order.GetCount() && (ok || !stoponerrors); i++) {
			int px = build_order[i];
			ok = BuildPackage(wspc, px, i, build_order.GetCount() + 1,
				              mainparam, Null, linkfile, linkopt) && ok;
			if(msecs() - ms >= 200) {
				DoProcessEvents();
				ms = msecs();
			}
		}
		if(ok || !stoponerrors) {
			ok = BuildPackage(wspc, 0, build_order.GetCount(), build_order.GetCount() + 1,
			                  mainparam, outfile, linkfile, linkopt, ok) && ok;
			// Set the time of target to start-time, so that if any file changes during
			// compilation, it is recompiled during next build
			SetFileTime(target, start_time); 
		}
	}
	EndBuilding(ok);
	ReQualifyCodeBase();
	SetErrorEditor();
	return ok;
}
Ejemplo n.º 30
0
int main(int argc, char **argv) {
    char buf[32];
    struct pru_data	pru;
    int fd, rdsize;

#ifndef DEBUG
    if (fork() != 0) {
        return 0;
    }
#endif

    tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;

    printf("Initializing pruss\n");
    prussdrv_init();
    if (prussdrv_open(PRU_EVTOUT_0)) {
        fprintf(stderr, "Cannot setup PRU_EVTOUT_0.\n");
        return -EINVAL;
    }
    
    printf("Initializing interrupts\n");
    prussdrv_pruintc_init(&pruss_intc_initdata);

    printf("Mapping PRUSS0 RAM\n");
    prussdrv_map_prumem(PRUSS0_PRU0_DATARAM, (void *) &pru.prumem);
    if (pru.prumem == NULL) {
        fprintf(stderr, "Cannot map PRU0 memory buffer.\n");
        return -ENOMEM;
    }


    printf("Creating FIFO\n");
    /* Create the FIFO if it does not exist */
    umask(0);
    mknod(FIFO_FILE, S_IFIFO|0666, 0);

    printf("Opening FIFO\n");
    fd = open(FIFO_FILE, O_RDONLY);
    if (fd < 0) {
        fprintf(stderr, "Cannot open FIFO.\n");
        return -EINVAL;
    }

    pru.prumem[RUN_FLAG_IDX] = 1; /* startup */

    printf("Loading PRU0 program\n");
    prussdrv_exec_program(0, "7seg_spi_test_fifo.bin");

    signal(SIGINT, shutdown_clock);
    signal(SIGTERM, shutdown_clock);

    printf("Entering runloop\n");
    while (running) {	
        if ((rdsize = read(fd, buf, sizeof(buf) - 1)) > 0) {
            update_buffer((const char *) &buf, &pru, rdsize);
        }
        usleep(msecs(10));
    }
    close(fd);

    pru.prumem[RUN_FLAG_IDX] = 0;
    
#ifdef DEBUG
    fprintf(stdout, "Waiting for PRU core to shutdown..\n");
#endif

    prussdrv_pru_wait_event(PRU_EVTOUT_0);
    prussdrv_pru_clear_event(PRU0_ARM_INTERRUPT);

    prussdrv_pru_disable(0);
    prussdrv_exit();

    return 0;
}