Ejemplo n.º 1
0
void OpenTxSimulator::start(const char * filename, bool tests)
{
#if defined(PCBSKY9X) && !defined(REVX)
  g_rotenc[0] = 0;
#elif defined(PCBGRUVIN9X)
  g_rotenc[0] = 0;
  g_rotenc[1] = 0;
#endif

  StartEepromThread(filename);
  StartAudioThread(volumeGain);
  StartMainThread(tests);
}
Ejemplo n.º 2
0
    DWORD Client::Start_Helper(VOID)
    {
        eState_ = STATE::starting;

        // Проверка запущен ли сервер: клиент не должен запускаться, если не запущен сервер. ∙ ▼
        hC_Event_Stop_Server_ = CreateEvent ( 
                                                NULL,                                               // default security attribute 
                                                TRUE,                                               // manual-reset event 
                                                FALSE,                                              // initial state = unsignaled 
                                                TEXT(STOP_SERVER_EVENT_GUID)                        // named event object 
                                            );
        DWORD create_event_result = GetLastError();

        if ((hC_Event_Stop_Server_ == NULL) || (create_event_result != ERROR_ALREADY_EXISTS))
        {  
            return ERROR_NOT_FOUND;
        }
        // ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ▲

        // Инициализация pipe-a. ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ▼
        hPipe_ = CreateFile ( 
                                PipeName_.c_str(),            // pipe name 
                                GENERIC_READ |             // read and write access 
                                GENERIC_WRITE, 
                                0,                // no sharing 
                                NULL,               // default security attributes
                                OPEN_EXISTING,             // opens existing pipe 
                                0,                // default attributes 
                                NULL               // no template file 
                            ); 

        if (hPipe_ == INVALID_HANDLE_VALUE) 
        {
            //return GetLastError();
            DWORD last_error = GetLastError();
        
            if (last_error == ERROR_PIPE_BUSY)
            {
                WaitNamedPipe(PipeName_.c_str(), NMPWAIT_WAIT_FOREVER);


                   hPipe_ = CreateFile ( 
                                            PipeName_.c_str(),                                      // pipe name 
                                            GENERIC_READ |                                          // read and write access 
                                            GENERIC_WRITE, 
                                            0,                                                      // no sharing 
                                            NULL,                                                   // default security attributes
                                            OPEN_EXISTING,                                          // opens existing pipe 
                                            0,                                                      // default attributes 
                                            NULL                                                    // no template file 
                                        ); 
            }
        }

        // The pipe connected; change to message-read mode. 
        DWORD dwMode = PIPE_READMODE_MESSAGE; 
        BOOL bSuccess = SetNamedPipeHandleState ( 
                                                    hPipe_,                                         // pipe handle 
                                                    &dwMode,                                        // new pipe mode 
                                                    NULL,                                           // don't set maximum bytes 
                                                    NULL                                            // don't set maximum time 
                                                );
        if (!bSuccess) 
        {
            return GetLastError();
        } 
        // ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ▲

        // Старт потока(ов). ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ▼
        if (DWORD start_thread_result = StartMainThread() != ERROR_SUCCESS)    
            return start_thread_result;    
        // ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ▲

        InitializeCriticalSection(&csPipe_Write_);
        InitializeCriticalSection(&csPipe_Read_);

        eState_ = STATE::started;

        return ERROR_SUCCESS;
    }
Ejemplo n.º 3
0
    DWORD Server::Start_Helper(VOID)
    {
        // Предотвращение повторного запуска.
        hServerIsUp_Mutex = CreateMutexA(NULL, FALSE,  SERVER_IS_WORKING_MUTEX_GUID);
        if ((hServerIsUp_Mutex == NULL) || (GetLastError() == ERROR_ALREADY_EXISTS))
        {
            CLOSE_HANDLE(hServerIsUp_Mutex);

            return ERROR_ALREADY_EXISTS;
        }

        DWORD i;

        // The initial loop creates several S_PIPES_INSTANCES of a named pipe 
        // along with an event object for each instance.  An 
        // overlapped ConnectNamedPipe operation is started for 
        // each instance. 

        for (i = 0; i < S_PIPES_INSTANCES; i++) 
        {
            // Create an event object for this instance.
            CREATE_EVENT__SIGNALED(hPipes_Events_[i], t_string(TEXT("!!!!!_") + t_to_string(i)).c_str());

            if (hPipes_Events_[i] == NULL) 
            {     
                return GetLastError();   
            }

            Pipe_[i].oOverlap.hEvent = hPipes_Events_[i]; 

            Pipe_[i].hPipeInst = CreateNamedPipe(             
                                                    PipeName_.c_str(),                              // pipe name 
                                                    PIPE_ACCESS_DUPLEX |                            // read/write access 
                                                    FILE_FLAG_OVERLAPPED,                           // overlapped mode 
                                                    PIPE_TYPE_MESSAGE |                             // message-type pipe 
                                                    PIPE_READMODE_MESSAGE |                         // message-read mode 
                                                    PIPE_WAIT,                                      // blocking mode 
                                                    S_PIPES_INSTANCES,                              // number of S_PIPES_INSTANCES 
                                                    BUFSIZE*sizeof(TCHAR),                          // output buffer size 
                                                    BUFSIZE*sizeof(TCHAR),                          // input buffer size 
                                                    S_PIPE_TIMEOUT,                                 // client time-out 
                                                    NULL                                            // default security attributes 
                                                );

            if (Pipe_[i].hPipeInst == INVALID_HANDLE_VALUE) 
            {
                return GetLastError();
            }

            // Call the subroutine to connect to the new client            
            if (DWORD connect_to_new_client_result = ConnectToNewClient(i) != ERROR_SUCCESS) 
            {
                return connect_to_new_client_result;
            }  
        }

        // stop-event
        CREATE_EVENT__UNSIGNALED(hPipes_Events_[S_EVENT_STOP], TEXT(""));
        // stop-server-event
        CREATE_EVENT__UNSIGNALED(hPipes_Events_[S_EVENT_STOP_SERVER], TEXT(STOP_SERVER_EVENT_GUID));

        for (DWORD counter = 0; counter < S_EVENTS_; counter++ )
        {
            CREATE_EVENT__UNSIGNALED(hS_Events_[counter], TEXT(""));
        }

        //TODO_URGENT: инициализировать S_EVENTS_

        InitializeCriticalSection(&csReadPipe_);
        for (DWORD counter = 0; counter < S_PIPES_INSTANCES; counter++)
        {        
            InitializeCriticalSection(&Pipe_[counter].csWritePipe);
        }    

        StartMainThread();

        eState_ = STATE::started;

        return ERROR_SUCCESS;
    }