Beispiel #1
0
            virtual void Run()
            {
#ifdef _WIN32
                CoInitializeEx(NULL, COINIT_MULTITHREADED);
                m_proc(m_arg);
                CoUninitialize();
#else
                m_proc(m_arg);
#endif
            }
/**	Updates the texture
 *
 *	@returns	The texture buffer ID of this object
 *
 *	Operation:
 *		-#	Allocate a buffer the size requested in the constructor
 *		-#	Initialise the buffer with zeros
 *		-#	Call the procedure, passing the buffer, width and height to it
 *		-#	Generate an OpenGL texture object
 *		-#	Enable GL_TEXTURE_2D
 *		-#	Load the buffer containing the 32bit image data into an opengl texture object (This is not the same as a Fusion Texture Object)
 *		-#	Delete any temporary memory allocated
 *		-#	Return the texture buffer id
 */
int OGLProceduralTexture::UpdateTexture()
{
	DeleteTexture();

	unsigned char *buffer = new unsigned char[m_width*m_height*m_numcomp];

	memset(buffer,0,m_width*m_height*m_numcomp);

	buffer = m_proc(buffer,m_width,m_height,m_numcomp);

	CreateTexture(buffer);

	delete[] buffer;

	return m_tbid;
}
Beispiel #3
0
void COSError::LogMessage(const TCHAR* msg)
{
	static CLock lock;
	TCHAR txt[512];
	size_t len = CTimeWrap::GetNow(txt, _countof(txt));
	_stprintf_s(txt + len, _countof(txt) - len, _T("  %s%s"), msg, _T("\r\n"));
	lock.Lock();
	try
	{
		if(m_proc!=NULL)
			m_proc(txt);
		 else if(m_show_out)
			 _tprintf_s(_T("%s"), txt);

		if(m_log != NULL)
			_fputts(txt, m_log);
	}
	catch(...)
	{
	}
	lock.UnLock();
}
Beispiel #4
0
	// muust be exec only once!
	ErrorCode PipeServer::runProc()
	{	
		int listenSocket = -1;
		struct sockaddr_un localAddress;		

		if ((listenSocket = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) 
		{
			perror("socket");
			return ErrorCode::FAILURE;
		}
		
		localAddress.sun_family = AF_UNIX;
		strcpy(localAddress.sun_path, pipename);
		unlink(localAddress.sun_path);
		unsigned int len = strlen(localAddress.sun_path) + sizeof(localAddress.sun_family);
		
		if (bind(listenSocket, (struct sockaddr *)&localAddress, len) == -1) 
		{
			perror("bind");
			close(listenSocket);
			return ErrorCode::FAILURE;
		}
	
		/*
		 * The backlog argument defines the maximum length to which the queue of pending connections 
		 * for sockfd may  grow.   If  a  connection request  arrives  when  the queue is full, 
		 * the client may receive an error with an indication of ECONNREFUSED or, if the underlying
		 * protocol supports retransmission, the request may be ignored so that
		 * a later reattempt at connection succeeds.
		*/
		if (listen(listenSocket, CPPL_PIPESERV_UNIX_MAXCONNQUEUE) == -1) 
		{
			perror("listen");
			close(listenSocket);
			return ErrorCode::FAILURE;
		}
	
		socklen_t t;
		int acceptSocket;
		struct sockaddr_un remoteAddress;

		// int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen);

		int tmperrno;

		// Set timeout on accept
        struct timeval tv;
        ms2tv(mTimCON, &tv);       
        setsockopt(listenSocket, SOL_SOCKET, SO_RCVTIMEO, (const void *) &tv, sizeof(struct timeval));

		while(1) // TODO: Termination through IPC or SIGTERM or by closing socket
		{
			t = sizeof(sockaddr_un);
			
			errno = 0;
			acceptSocket = accept(listenSocket, (struct sockaddr *)&remoteAddress, &t);
			tmperrno = errno;
			
			if (isTerminated())
			{
				close(listenSocket);
				printf("PipeServer terminating ....\n");
				manager.terminateAndJoin();
				return ErrorCode::TERMINATED;
			}
			
			int joined = manager.joinIfFinished();
			if (joined) printf("joined %d and remains %d\n", joined, manager.threadCount());	
			
			if (tmperrno == EAGAIN)
			{
				continue;
			}

			// TODO: if timeout continue;			
			if (acceptSocket == -1) 
			{
				perror("accept");
				close(listenSocket);
				// TODO: we should here terminate and join all threads here
				return ErrorCode::FAILURE;
			}
				
			manager.startThread<PipeChannel>([=](){return m_proc(acceptSocket, mTimRX, mTimTX);});
		}
		
		return ErrorCode::SUCCESS;
	}
Beispiel #5
0
	ErrorCode PipeServer::runProc()
	{
	   HANDLE hPipe = INVALID_HANDLE_VALUE; 
	   
	   // this means that lpszPipename is type of LPWSTR
	   wchar_t lpszPipename[CPPL_PIPESERV_WIN_MAXFNAMEBYTES]; // = TEXT("\\\\.\\pipe\\mynamedpipe"); 
	   
       if (strlen(pipename) >= CPPL_PIPESERV_WIN_MAXCHARPIPENAME) return ErrorCode::FAILURE;
	   
	   // LPCSTR -> LPCWSTR
	   if (!MultiByteToWideChar(CP_UTF8, 0, pipename, strlen(pipename) + 1, lpszPipename, CPPL_PIPESERV_WIN_MAXFNAMEBYTES))
	   {
		   printf("Error PipeServer::start()::MultiByteToWideChar::GLA: %d", GetLastError());
           return ErrorCode::FAILURE;
	   }	  
	   
	   int joined;

	   OVERLAPPED o;

	   memset(&o, 0, sizeof(OVERLAPPED)); // might be unnecessary
	   o.Offset = 0;
	   o.OffsetHigh = 0;

	   // maybe second parameter false ResetEvent()???
	   o.hEvent = CreateEvent(NULL, true, false, NULL);
       if (o.hEvent == NULL) return ErrorCode::FAILURE;

	   // The main loop creates an instance of the named pipe and 
	   // then waits for a client to connect to it. When the client 
	   // connects, a thread is created to handle communications 
	   // with that client, and this loop is free to wait for the
	   // next client connect request. It is an infinite loop.
 
	   while(1) // TODO: Termination through IPC or "something like signal"
	   { 
		  if (isTerminated())
		  {
			CloseHandle(o.hEvent);
			CloseHandle(hPipe);  
			manager.terminateAndJoin();
            return ErrorCode::TERMINATED;
		  }

		  joined = manager.joinIfFinished();
		  if (joined) printf("joined %d and remains %d\n", joined, manager.threadCount());

		  hPipe = CreateNamedPipeW( 
			  lpszPipename,             // pipe name 
			  PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,       // read/write access, asnyc becouse of timeout implementation
			  PIPE_REJECT_REMOTE_CLIENTS | PIPE_TYPE_BYTE | PIPE_READMODE_BYTE,
			  PIPE_UNLIMITED_INSTANCES, // max. instances  
			  CPPL_PIPESERV_WIN_OUTBUFSIZE,      // output buffer size 
			  CPPL_PIPESERV_WIN_INBUFSIZE,       // input buffer size 
			  CPPL_PIPESERV_WIN_CONNECTTIMEO,    // client time-out 
			  NULL);                             // default security attribute 

		  if (hPipe == INVALID_HANDLE_VALUE) 
		  {
			  printf("CreateNamedPipe failed, GLE=%d.\n", GetLastError()); 
			  CloseHandle(o.hEvent);
			  CloseHandle(hPipe);
              return ErrorCode::FAILURE;
		  }
 
		  // beware of overlapped io. Return value behaves very weird.
		  ConnectNamedPipe(hPipe, &o); 
 
		  DWORD errCode = GetLastError();
		
		  if (errCode != ERROR_IO_PENDING && errCode != ERROR_SUCCESS && errCode != ERROR_PIPE_CONNECTED)
		  {			
			printf("ConnectNamedPipe() fatal error: GLA:%d\n", errCode);
			CloseHandle(o.hEvent);
			CloseHandle(hPipe);
            return ErrorCode::FAILURE;
		  }

		  DWORD rval;
		  while(1)
		  {
			rval = WaitForSingleObject(o.hEvent, mTimCON);
			
			if (isTerminated())
			{
			 	CloseHandle(o.hEvent);
				CloseHandle(hPipe);  
				manager.terminateAndJoin();
                return ErrorCode::TERMINATED;
			}

			joined = manager.joinIfFinished();
			if (joined) printf("joined %d and remains %d\n", joined, manager.threadCount());

			if (rval == WAIT_OBJECT_0) break;
			if (rval == WAIT_TIMEOUT) 
			{
				if (ResetEvent(o.hEvent) == FALSE)
				{
					printf("PipeServer::start():2:ResetEvent failed\n");
					CloseHandle(o.hEvent);
					CloseHandle(hPipe);
                    return ErrorCode::FAILURE;
				}  
				continue;
			}

			CloseHandle(o.hEvent);
			CloseHandle(hPipe);  
            return ErrorCode::FAILURE;
		  }
				
		  // GetOverlappedResult is useless because for ConnectNamedPipe() is return value undefined
		  // http://msdn.microsoft.com/en-us/library/windows/desktop/ms683209(v=vs.85).aspx
		  manager.startThread<PipeChannel>([=](){return m_proc(hPipe, mTimRX, mTimTX);});
	   } 

	   CloseHandle(o.hEvent);
	   CloseHandle(hPipe);  
       return ErrorCode::SUCCESS; 
	}
IViewFactory* CViewFactoryCreatorProc::CreatePlugin()
{
	return m_proc();
}
Beispiel #7
0
 virtual void run() override {
   m_proc(m_server, m_connectionId, m_data);
 }
Beispiel #8
0
    static void CALLBACK DefaultWorkCallbackTest(PTP_CALLBACK_INSTANCE, PVOID pContext, PTP_WORK)
    {
        auto schedulerParam = std::unique_ptr<_Scheduler_Param>(static_cast<_Scheduler_Param*>(pContext));

        schedulerParam->m_proc(schedulerParam->m_param);
    }
Beispiel #9
0
 virtual void Run()
 {
     m_proc(m_arg);
 }