void TCPConnection::GetSocketData()
{
  wxString msg;

//::wxSafeShowMessage(_("Titanes"),_("Dentro de GetSocketData"));
  Conn->SetNotify(wxSOCKET_LOST_FLAG);
  while (Conn->WaitForRead(0,100)==true)
  {
//::wxSafeShowMessage(_("Titanes"),_("Antes del ReadLine"));
    msg=Input->ReadLine();
//::wxSafeShowMessage(_("Titanes"),_("Antes del Enter"));
    m_critsec.Enter();
//::wxSafeShowMessage(_("Titanes"),_("Antes del Add"));
    MsgList->Add(msg);
//::wxSafeShowMessage(_("Titanes"),_("Antes del Leave"));
    m_critsec.Leave();
//::wxSafeShowMessage(_("Titanes"),_("Despues del Leave"));
/*
    ::wxSafeYield();
    ::wxMilliSleep(300);
*/
  }
  Conn->SetNotify(wxSOCKET_LOST_FLAG | wxSOCKET_INPUT_FLAG);
//::wxSafeShowMessage(_("Titanes"),_("Dentro de GetSocketData"));
}
void *TCPThread::Entry()
{
  wxString msg;

//::wxSafeShowMessage(_("Titanes"),_("Dentro del Thread."));
  while (TestDestroy()==FALSE)
  {
    msg=m_input->ReadLine();
    m_critsec.Enter();
    m_msglist->Add(msg);
    m_critsec.Leave();
  }
//	::wxSafeShowMessage(_("Titanes"),_("Fuera del Thread."));
  return NULL;
}
wxString TCPConnection::GetMessage()
{
  wxString msg;

  m_critsec.Enter();
  if (MsgList->GetCount()>0)
  {
    msg=MsgList->Item(0);
    MsgList->RemoveAt(0);
  }
  else
  {
    msg=wxEmptyString;
  }
  m_critsec.Leave();
  return msg;
}
void HeaderDirTraverser::AddLock(bool is_file)
{
    if (is_file)
        m_Files++;
    else
        m_Dirs++;

    if ((m_Files+m_Dirs) % 100 == 1)
    {
        TRACE(_T("HeaderDirTraverser: %lu directories and %lu files traversed. Unlocking temporarily."), static_cast<unsigned long>(m_Dirs), static_cast<unsigned long>(m_Files));

        if (m_Locked)
        {
            m_SystemHeadersThreadCS->Leave();
            m_Locked = false;
        }

        m_SystemHeadersThreadCS->Enter();
        m_Locked = true;
    }
}
Esempio n. 5
0
wxCondError wxConditionInternal::DoSignal( bool signalAll)
{
    m_gate.Wait();
    m_varSection.Enter();

    wxASSERT( m_signals == m_canceled );

    if ( m_waiters == m_canceled)
    {
        m_varSection.Leave();
        m_gate.Post();
        return wxCOND_NO_ERROR;
    }

    if ( m_canceled > 0)
    {
        m_waiters -= m_canceled;
        m_signals = 0;
        m_canceled = 0;
    }

    m_signals = signalAll ? m_waiters : 1;
    size_t n = m_signals;

    m_varSection.Leave();

    // Let the waiters inherit the gate lock.

    do
    {
        wxSemaError err = m_semaphore.Post();
        wxASSERT( err == wxSEMA_NO_ERROR );
    }
    while ( --n );

    return wxCOND_NO_ERROR;
}
Esempio n. 6
0
void SearchThread::SearchDir(const wxString& path, const SearchInfo& si, ProjectInfoHandler& infoHandler) {
    MMapBuffer buf;
    wxFileName filepath;
    vector<FileMatch> matches;

    wxArrayString dirs;
    wxArrayString filenames;
    infoHandler.GetDirAndFileLists(path, dirs, filenames);

    for (size_t f = 0; f < filenames.size(); ++f) {
        if (!m_isSearching) return;
        m_outputCrit.Enter();
        m_currentPath = path + filenames[f];
        m_outputCrit.Leave();
        filepath = m_currentPath;

        // Map the file to memory
        buf.Open(filepath);
        if (!buf.IsMapped()) {
            wxLogDebug(wxT(" Mapping failed!"));
            continue;
        }

        // Search the file
        DoSearch(buf, si, matches);
        if (matches.empty()) continue;

        // Show matches
        WriteResult(buf, filepath, matches);
        matches.clear();
    }

    for (size_t d = 0; d < dirs.size(); ++d) {
        const wxString dirpath = path + dirs[d] + wxFILE_SEP_PATH;
        SearchDir(dirpath, si, infoHandler);
    }
}
Esempio n. 7
0
void* SearchThread::Entry() {
    while (1) {
        // Wait for signal that we should start search
        m_isWaiting = true;
        wxMutexLocker lock(m_condMutex);
        m_startSearchCond.Wait();
        m_isWaiting = false;

        if (m_stopSearch) {
            while (1) {
                if (TestDestroy()) break;
                Sleep(100);
            }
        }

        SearchInfo si;
        if (!PrepareSearchInfo(si, m_pattern, m_matchCase, m_regex)) continue;

        m_isSearching = true;

        ProjectInfoHandler infoHandler;
        infoHandler.SetRoot(m_path);

        // Write the html header for output
        m_outputCrit.Enter();
        m_output = wxT("<head><style type=\"text/css\">#match {background-color: yellow}</style></head>");
        m_outputCrit.Leave();

        SearchDir(m_path, si, infoHandler);
        m_isSearching = false;

        // Clean up
        if (si.regex) free(si.regex);
    }

    return NULL;
}
Esempio n. 8
0
wxCondError wxConditionInternal::WaitTimeout( unsigned long msectimeout )
{
    m_gate.Wait();

    if ( ++ m_waiters == INT_MAX )
    {
        m_varSection.Enter();

        m_waiters -= m_canceled;
        m_signals -= m_canceled;
        m_canceled = 0;

        m_varSection.Leave();
    }

    m_gate.Post();
    m_mutex.Unlock();

    wxSemaError err = m_semaphore.WaitTimeout( msectimeout);
    wxASSERT( err == wxSEMA_NO_ERROR || err == wxSEMA_TIMEOUT);

    m_varSection.Enter();

    if ( err != wxSEMA_NO_ERROR )
    {
        if ( m_signals > m_canceled )
        {
            // A signal is being sent after we timed out.
            if ( m_waiters == m_signals )
            {
                // There are no excess waiters to catch the signal, so
                // we must throw it away.
                wxSemaError err2 = m_semaphore.Wait();
                if ( err2 != wxSEMA_NO_ERROR )
                {
                    wxLogSysError( wx("Error while waiting on semaphore") );
                }

                wxASSERT( err2 == wxSEMA_NO_ERROR);

                --m_waiters;
                if ( --m_signals == m_canceled )
                {
                    // This was the last signal. open the gate.
                    wxASSERT( m_waiters == m_canceled );
                    m_gate.Post();
                }
            }
            else
            {
                // There are excess waiters to catch the signal, leave it be.
                --m_waiters;
            }
        }
        else
        {
            // No signals is being sent:
            // the gate may be open or closed, so we can't touch m_waiters.
            ++m_canceled;
            ++m_signals;
        }
    }
    else
    {
        // We caught a signal.
        wxASSERT( m_signals > m_canceled );

        --m_waiters;

        if ( --m_signals == m_canceled)
        {
            // This was the last signal. open the gate.
            wxASSERT( m_waiters == m_canceled );

            m_gate.Post();
        }
    }

    m_varSection.Leave();
    m_mutex.Lock();

    if (err != noErr)
        return err == wxSEMA_TIMEOUT ? wxCOND_TIMEOUT : wxCOND_MISC_ERROR;

    return wxCOND_NO_ERROR;
}
Esempio n. 9
0
void SearchThread::WriteResult(const MMapBuffer& buf, const wxFileName& filepath, vector<FileMatch>& matches) {
    if (matches.empty()) return;

    // Header
    const wxString path = filepath.GetFullPath();
    const wxString format = (matches.size() == 1) ? _("<b>%s - %d match</b>") : _("<b>%s - %d matches</b>");
    wxString output = wxString::Format(format, path.c_str(), matches.size());
    output += wxT("<br><table cellspacing=0>");

    unsigned int linecount = 1;
    const char* subject = buf.data();
    const char* end = subject + buf.Length();
    const char* linestart = subject;
    vector<FileMatch>::iterator m = matches.begin();
    const char* matchstart = subject + m->start;

    // Count lines
    while (subject < end) {
        if (subject == matchstart) {
            const size_t column = 1 + (matchstart - linestart); // column ndx starts from 1
            const size_t sel_len = m->end - m->start;

            // Write linenumber with link
            wxString line = wxString::Format(wxT("<tr><td bgcolor=#f6f6ef align=\"right\"><a href=\"txmt://open/?url=file://%s&line=%d&column=%d&sel=%d\">%d</a></td><td> "), path.c_str(), linecount, column, sel_len, linecount);

            // Start of line
            {
                wxString result = wxString(linestart, wxConvUTF8, matchstart-linestart);
                SimpleHtmlEncode(result);
                line += result;
            }


            // Match
            line += wxT("<i style=\"background-color: yellow\">");
            const size_t match_len = m->end - m->start;
            {
                wxString result = wxString(matchstart, wxConvUTF8, match_len);
                SimpleHtmlEncode(result);
                line += result;
            }
            line += wxT("</i>");

            // End of line
            const char* const matchend = subject + match_len;
            const char* lineend = matchend;
            while (lineend < end && *lineend != '\n') ++lineend;
            {
                wxString result = wxString(matchend, wxConvUTF8, lineend - matchend);
                SimpleHtmlEncode(result);
                line += result;
            }
            line += wxT("</td></tr>");
            output += line;

            ++m;
            if (m == matches.end()) break;
            matchstart = buf.data() + m->start;
        }

        if (*subject == '\n') {
            ++linecount;
            linestart = subject+1;
        }

        ++subject;
    }

    output += wxT("</table><p>");

    m_outputCrit.Enter();
    m_output += output;
    m_outputCrit.Leave();
}
Esempio n. 10
0
bool SearchThread::PrepareSearchInfo(SearchInfo& si, const wxString& pattern, bool matchCase, bool regex) {
    si.pattern = pattern;
    si.matchCase = matchCase;
    si.regex = NULL;

    // We need both upper- & lowercase versions for caseless search
    if (!regex && !matchCase) {
        si.pattern.MakeLower();
        si.patternUpper = pattern;
        si.patternUpper.MakeUpper();
    }

    // Convert the searchtext to UTF8
    // For performance we assume all text to be in utf8 format.
    // In the future we might want to detect encoding of each file
    // before searching it, but it will cost us some speed.
    si.UTF8buffer = wxConvUTF8.cWC2MB(si.pattern);

    if (regex) {
        const char *error;
        int erroffset;

        // While the pattern is utf-8, we treat it as ascii here.
        // Otherwise we would have to check all the files if they
        // were valid utf-8 before searching.
        int options = PCRE_MULTILINE;
        if (!matchCase) options |= PCRE_CASELESS;

        // Compile the pattern
        si.regex = pcre_compile(
                       si.UTF8buffer.data(), // the pattern
                       options,              // options
                       &error,               // for error message
                       &erroffset,           // for error offset
                       NULL);                // use default character tables

        // Handle errors
        if (!si.regex) {
            m_outputCrit.Enter();
            m_currentPath = wxT("Invalid pattern: ") + wxString(error, wxConvUTF8);
            m_outputCrit.Leave();
            m_lastError = true;
            return false;
        };
    }
    else {
        si.byte_len = strlen(si.UTF8buffer);
        if (!matchCase) {
            si.UTF8bufferUpper = wxConvUTF8.cWC2MB(si.patternUpper);

            // This algorithm assumes that UTF8 upper- & lowercase chars have same byte width
            wxASSERT(si.byte_len == strlen(si.UTF8bufferUpper));
        }

        // Build a dictionary of char-to-last distances in the search string
        // since this is a char, distances in the searchstring can not be longer than 256
        memset(si.charmap, si.byte_len, 256);
        const size_t last_char_pos = si.byte_len-1;
        for (size_t i = 0; i < last_char_pos; ++i) {
            si.charmap[si.UTF8buffer[i]] = last_char_pos-i;
            if (!matchCase) si.charmap[si.UTF8bufferUpper[i]] = last_char_pos-i;
        }
    }
    return true;
}
Esempio n. 11
0
    int Execute()
    {
        TRACK_THREAD_LOCKER(s_ParserCritical);
        s_ParserCritical.Enter();
        THREAD_LOCKER_SUCCESS(s_ParserCritical);
        wxString preDefs(m_Parser.m_PredefinedMacros);
        StringList priorityHeaders(m_Parser.m_PriorityHeaders);
        StringList batchFiles(m_Parser.m_BatchParseFiles);
        s_ParserCritical.Leave();

        if (!preDefs.IsEmpty())
            m_Parser.ParseBuffer(preDefs, false, false);

        {
            TRACK_THREAD_LOCKER(s_ParserCritical);
            wxCriticalSectionLocker locker(s_ParserCritical);
            THREAD_LOCKER_SUCCESS(s_ParserCritical);

            m_Parser.m_PredefinedMacros.Clear();
            m_Parser.m_IsPriority = true;
        }

        while (!priorityHeaders.empty())
        {
            m_Parser.Parse(priorityHeaders.front());
            priorityHeaders.pop_front();
        }

        {
            TRACK_THREAD_LOCKER(s_ParserCritical);
            wxCriticalSectionLocker locker(s_ParserCritical);
            THREAD_LOCKER_SUCCESS(s_ParserCritical);

            m_Parser.m_PriorityHeaders.clear();
            m_Parser.m_IsPriority = false;

            if (m_Parser.m_IgnoreThreadEvents)
                m_Parser.m_IsFirstBatch = true;
        }

        while (!batchFiles.empty())
        {
            m_Parser.Parse(batchFiles.front());
            batchFiles.pop_front();
        }

        {
            TRACK_THREAD_LOCKER(s_ParserCritical);
            wxCriticalSectionLocker locker(s_ParserCritical);
            THREAD_LOCKER_SUCCESS(s_ParserCritical);

            m_Parser.m_BatchParseFiles.clear();

            if (m_Parser.m_IgnoreThreadEvents)
            {
                m_Parser.m_IgnoreThreadEvents = false;
                m_Parser.m_IsParsing = true;
            }
        }

        return 0;
    }