static OSStatus Listener(AudioObjectID objectID,
                            UInt32 numberAddresses,
                            const AudioObjectPropertyAddress inAddresses[],
                            void *clientData)
   {
      DeviceChangeListener *This = (DeviceChangeListener *) clientData;

      for (int i = 0; i < numberAddresses; i++)
      {
#if 0
         printf("address %d\n", i);
         printf("selector %08x\n", inAddresses[i].mSelector);
         printf("scope %08x\n", inAddresses[i].mScope);
         printf("element %08x\n", inAddresses[i].mElement);
#endif
         if (This->mEnabled)
         {
            This->mEnabled = false;
            wxMutexGuiEnter();
            wxCommandEvent e(EVT_DEVICE_CHANGE);
            This->mHandler->AddPendingEvent(e);
            wxMutexGuiLeave();
         }   
      }
   
       return 0;
   }
/////////////////////
// Ask to stop later
void AudioPlayer::RequestStop() {
	wxCommandEvent event(wxEVT_STOP_AUDIO, 1000);
    event.SetEventObject(this);
	wxMutexGuiEnter();
	AddPendingEvent(event);
	wxMutexGuiLeave();
}
Exemple #3
0
wxThread::ExitCode MyGUIThread::Entry()
{
    // uncomment this to check that disabling logging here does disable it for
    // this thread -- but not the main one if you also comment out wxLogNull
    // line in MyFrame::OnStartGUIThread()
    //wxLogNull noLog;

    // this goes to the main window
    wxLogMessage("GUI thread starting");

    // use a thread-specific log target for this thread to show that its
    // messages don't appear in the main window while it runs
    wxLogBuffer logBuf;
    wxLog::SetThreadActiveTarget(&logBuf);

    for (int i=0; i<GUITHREAD_NUM_UPDATES && !TestDestroy(); i++)
    {
        // inform the GUI toolkit that we're going to use GUI functions
        // from a secondary thread:
        wxMutexGuiEnter();

        {
            wxCriticalSectionLocker lock(m_dlg->m_csBmp);

            // draw some more stuff on the bitmap
            wxMemoryDC dc(m_dlg->m_bmp);
            dc.SetBrush((i%2)==0 ? *wxBLUE_BRUSH : *wxGREEN_BRUSH);
            dc.DrawRectangle(rand()%GUITHREAD_BMP_SIZE, rand()%GUITHREAD_BMP_SIZE, 30, 30);

            // simulate long drawing time:
            wxMilliSleep(200);
        }

        // if we don't release the GUI mutex the MyImageDialog won't be able to refresh
        wxMutexGuiLeave();

        // notify the dialog that another piece of our masterpiece is complete:
        wxThreadEvent event( wxEVT_THREAD, GUITHREAD_EVENT );
        event.SetInt(i+1);
        wxQueueEvent( m_dlg, event.Clone() );

        if ( !((i + 1) % 10) )
        {
            // this message will go to the buffer
            wxLogMessage("Step #%d.", i + 1);
        }

        // give the main thread the time to refresh before we lock the GUI mutex again
        // FIXME: find a better way to do this!
        wxMilliSleep(100);
    }

    // now remove the thread-specific thread target
    wxLog::SetThreadActiveTarget(NULL);

    // so that this goes to the main window again
    wxLogMessage("GUI thread finished.");

    return (ExitCode)0;
}
 void paint(const Configuration& config)
 {
     wxMutexGuiEnter();
     m_vlayer->clear();
     m_vlayer << config;
     wxMutexGuiLeave();
     m_panel->Refresh();
 }
Exemple #5
0
Generator::~Generator(){
	if(!wxThread::IsMain())	// Queued in destroy list in main thread (or deleted after run in current thread)?
		wxMutexGuiEnter();
	this->gencanc->Enable(true);	// Disabled in case of cancel operation
	this->gencanc->SetLabelText(_("Generate"));
	this->gencanc->SetToolTip(_("Start process!"));
	if(!wxThread::IsMain())
		wxMutexGuiLeave();
}
Exemple #6
0
/* we have to use this to avoid GUI-noGUI threads crashing */
void printevent(const char *msg)
{
#ifndef __WXGTK__ 
	wxMutexGuiEnter();
#endif /* __WXGTK__ */
	wxLogMessage(wxT("%s"), msg);
#ifndef __WXGTK__ 
    wxMutexGuiLeave();
#endif /* __WXGTK__ */
}
Exemple #7
0
void DSPDebuggerLLE::Repopulate()
{
  if (!wxIsMainThread())
    wxMutexGuiEnter();
  UpdateSymbolMap();
  UpdateDisAsmListView();
  UpdateRegisterFlags();
  UpdateState();
  if (!wxIsMainThread())
    wxMutexGuiLeave();
}
Exemple #8
0
void AudioThread::WriteText(const wxString& text)
{
    wxString msg;

    wxMutexGuiEnter();

    msg << text;
    m_frame->WriteText(msg);

    wxMutexGuiLeave();

}
/* sample error callback expecting a FILE* client object */
void mxf_error_callback(const char *msg, void *client_data) {
	int message_len = strlen(msg) - 1;
	if (msg[message_len] != '\n')
		message_len = MAX_MESSAGE_LEN;
#ifndef __WXGTK__ 
		wxMutexGuiEnter();
#endif /* __WXGTK__ */
	wxLogMessage(wxT("[ERROR] %.*s"), message_len, msg);
#ifndef __WXGTK__ 
    wxMutexGuiLeave();
#endif /* __WXGTK__ */
}
Exemple #10
0
// save the jp2 file format
bool wxJP2Handler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbose )
{
#ifndef __WXGTK__ 
		wxMutexGuiEnter();
#endif /* __WXGTK__ */
    wxLogError(wxT("JP2: Couldn't save image -> not implemented."));
#ifndef __WXGTK__ 
		wxMutexGuiLeave();
#endif /* __WXGTK__ */

    return false;
}
Exemple #11
0
   HRESULT STDMETHODCALLTYPE OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState)
   {
      if (mEnabled)
      {
         mEnabled = false;
         wxMutexGuiEnter();
         wxCommandEvent e(EVT_DEVICE_CHANGE);
         mHandler->AddPendingEvent(e);
         wxMutexGuiLeave();
      }

      return S_OK;
   }
Exemple #12
0
void wxApp::WakeUpIdle()
{
#if wxUSE_THREADS
    if (!wxThread::IsMain())
        wxMutexGuiEnter();
#endif

    wxEventLoop::GetActive()->WakeUp();

#if wxUSE_THREADS
    if (!wxThread::IsMain())
        wxMutexGuiLeave();
#endif
}
Exemple #13
0
void nbr_event_panel::SetCount(int idx,int count)
{
	wxString str;
	bool ismain=wxThread::IsMain();

	if ((idx<0)||(idx>=m_num_rows))
		return;

	if (!ismain) wxMutexGuiEnter();
	str.Printf("%i",count);
	m_event_grid->SetCellValue(idx,1,str);
	if (!ismain) wxMutexGuiLeave();

}
Exemple #14
0
void wxApp::WakeUpIdle()
{
#if wxUSE_THREADS
    if (!wxThread::IsMain())
        wxMutexGuiEnter();
#endif

    while (wxTheApp->ProcessIdle())
        ;

#if wxUSE_THREADS
    if (!wxThread::IsMain())
        wxMutexGuiLeave();
#endif
}
void DSPDebuggerLLE::Update()
{
#if defined __WXGTK__
	if (!wxIsMainThread())
		wxMutexGuiEnter();
#endif
	UpdateSymbolMap();
	UpdateDisAsmListView();
	UpdateRegisterFlags();
	UpdateState();
#if defined __WXGTK__
	if (!wxIsMainThread())
		wxMutexGuiLeave();
#endif
}
Exemple #16
0
void AudioThread::WriteText(const wxString& text)
{
    wxString msg;

    // before doing any GUI calls we must ensure that this thread is the only
    // one doing it!

    wxMutexGuiEnter();

    msg << text;
    m_frame->WriteText(msg);

    wxMutexGuiLeave();

}
Exemple #17
0
void CFrame::GetRenderWindowSize(int& x, int& y, int& width, int& height)
{
#ifdef __WXGTK__
	if (!wxIsMainThread())
		wxMutexGuiEnter();
#endif
	wxRect client_rect = m_RenderParent->GetClientRect();
	width = client_rect.width;
	height = client_rect.height;
	x = client_rect.x;
	y = client_rect.y;
#ifdef __WXGTK__
	if (!wxIsMainThread())
		wxMutexGuiLeave();
#endif
}
Exemple #18
0
void PathUtilDlg::Dump( std::string msg )
{	// wxPostEvent?
    OutputDebugStringA(msg.c_str());
    bool lock = (m_host_thread_id!=GetCurrentThreadId());
    if (lock)
        wxMutexGuiEnter();
    this->SetStatusText( to_tchar_string(msg), 0);
    wxString s = to_tchar_string(msg);
    wxLogMessage(s);
    if (boost::ends_with(msg, "\r\n")==false)
    {
        s += wxT("\r\n");
    }
    if (lock)
        wxMutexGuiLeave();
}
Exemple #19
0
static gint wxapp_poll_func( GPollFD *ufds, guint nfds, gint timeout )
{
    gdk_threads_enter();

    wxMutexGuiLeave();
    g_mainThreadLocked = true;

    gint res = (*wxgs_poll_func)(ufds, nfds, timeout);

    wxMutexGuiEnter();
    g_mainThreadLocked = false;

    gdk_threads_leave();

    return res;
}
Exemple #20
0
void threadIdaServer::sendDoneEvent(wxString msg, int retCode)
{
	// Tell the parent frame we're done so it can load the GUI
	wxCommandEvent DoneEvent( wxEVT_COMMAND_BUTTON_CLICKED );

	// Put the save file name in the event for later display 
	DoneEvent.SetString(msg);
	DoneEvent.SetInt(retCode);
	
	if (m_parentFrame)
	{
		wxMutexGuiEnter();
		wxPostEvent(m_parentFrame, DoneEvent);
		wxMutexGuiLeave();
	}
}
Exemple #21
0
void threadIdaServer::sendRecvEvent(wxString *data)
{
	wxCommandEvent DoneEvent( wxEVT_COMMAND_BUTTON_CLICKED );

	DoneEvent.SetString(*data);
	DoneEvent.SetInt(THREAD_IDA_MSG_RECEIVED);

	if (m_parentFrame)
	{
		wxMutexGuiEnter();
		wxPostEvent(m_parentFrame, DoneEvent);
		wxMutexGuiLeave();
	}

	delete data;
}
Exemple #22
0
void threadIdaServer::OnExit(void)
{
	// Called when the thread exits by termination or with Delete()
	// but not Kill()ed
	wxMutexGuiEnter();
	wxLogDebug(wxT("Exiting"));
	wxMutexGuiLeave();

	closesocket(ListenSocket);

	for(i = 0 ; i < TotalSockets ; i++)
		FreeSocketInformation(i);

	this->sendDoneEvent(wxT("Done"), THREAD_IDA_FINISHED_NOERROR);


}
Exemple #23
0
bool Host_GetKeyState(int keycode)
{
#ifdef _WIN32
	return (0 != GetAsyncKeyState(keycode));
#elif defined __WXGTK__
	std::unique_lock<std::recursive_mutex> lk(main_frame->keystate_lock, std::try_to_lock);
	if (!lk.owns_lock())
		return false;

	bool key_pressed;
	if (!wxIsMainThread()) wxMutexGuiEnter();
	key_pressed = wxGetKeyState(wxKeyCode(keycode));
	if (!wxIsMainThread()) wxMutexGuiLeave();
	return key_pressed;
#else
	return wxGetKeyState(wxKeyCode(keycode));
#endif
}
void OPJEncoThread::WriteText(const wxString& text)
{
    wxString msg;

    // before doing any GUI calls we must ensure that this thread is the only
    // one doing it!

#ifndef __WXGTK__ 
    wxMutexGuiEnter();
#endif // __WXGTK__

    msg << text;
    m_canvas->WriteText(msg);

#ifndef __WXGTK__ 
    wxMutexGuiLeave();
#endif // __WXGTK__
}
Exemple #25
0
wxThread::ExitCode turbotrace::Entry()
{
    tlog(_("Thread starting\n"));

    //Resolve the hostname , get the ip address
    if(!resolve_host(host))
    {
        return false;
    }

    wxMutexGuiEnter();
    parent_frame->set_ip( wxString( inet_ntoa(dest_ip) , wxConvUTF8) );
    wxMutexGuiLeave();

    //Call the outer class function start_sniffer
    start_sniffer();

    return (wxThread::ExitCode)0;
}
Exemple #26
0
void wxThreadInternal::Wait()
{
    wxCHECK_RET( !m_isDetached, _T("can't wait for a detached thread") );

    // if the thread we're waiting for is waiting for the GUI mutex, we will
    // deadlock so make sure we release it temporarily
    if ( wxThread::IsMain() )
        wxMutexGuiLeave();

    wxLogTrace(TRACE_THREADS,
               _T("Starting to wait for thread %ld to exit."),
               THR_ID(this));

    // to avoid memory leaks we should call pthread_join(), but it must only be
    // done once so use a critical section to serialize the code below
    {
        wxCriticalSectionLocker lock(m_csJoinFlag);

        if ( m_shouldBeJoined )
        {
            // FIXME shouldn't we set cancellation type to DISABLED here? If
            //       we're cancelled inside pthread_join(), things will almost
            //       certainly break - but if we disable the cancellation, we
            //       might deadlock
            if ( pthread_join(GetId(), &m_exitcode) != 0 )
            {
                // this is a serious problem, so use wxLogError and not
                // wxLogDebug: it is possible to bring the system to its knees
                // by creating too many threads and not joining them quite
                // easily
                wxLogError(_("Failed to join a thread, potential memory leak detected - please restart the program"));
            }

            m_shouldBeJoined = false;
        }
    }

    // reacquire GUI mutex
    if ( wxThread::IsMain() )
        wxMutexGuiEnter();
}
Exemple #27
0
bool wxGUIEventLoop::Dispatch()
{
    if ( !wxTheApp )
        return false;

    wxMacAutoreleasePool autoreleasepool;

    EventRef theEvent;

    OSStatus status = ReceiveNextEvent(0, NULL, m_sleepTime, true, &theEvent) ;

    switch (status)
    {
        case eventLoopTimedOutErr :
            if ( wxTheApp->ProcessIdle() )
                m_sleepTime = kEventDurationNoWait ;
            else
            {
                m_sleepTime = kEventDurationSecond;
#if wxUSE_THREADS
                wxMutexGuiLeave();
                wxMilliSleep(20);
                wxMutexGuiEnter();
#endif
            }
            break;

        case eventLoopQuitErr :
            // according to QA1061 this may also occur
            // when a WakeUp Process is executed
            break;

        default:
            DispatchAndReleaseEvent(theEvent);
            m_sleepTime = kEventDurationNoWait ;
            break;
    }

    return true;
}
void dc_gui_chatpanel::WriteToRichText(std::string msg, wxColour col)
{
	if (!wxIsMainThread())
		wxMutexGuiEnter();

	txtMain->Freeze();

	txtMain->SetCaretPosition(txtMain->GetLastPosition() - 1);
	size_t before_number_of_lines = txtMain->GetNumberOfLines();

	txtMain->Newline();
	txtMain->BeginTextColour(col);
	txtMain->WriteText(msg);
	txtMain->EndTextColour();

	size_t after_number_of_lines = txtMain->GetNumberOfLines();
	txtMain->Thaw();

	txtMain->ScrollLines(txtMain->GetNumberOfLines());

	if (!wxIsMainThread())
		wxMutexGuiLeave();
}
void AudacityLogger::DoLogText(const wxString & str)
{
   if (!wxIsMainThread()) {
      wxMutexGuiEnter();
   }

   if (mBuffer.IsEmpty()) {
      wxString stamp;

      TimeStamp(&stamp);

      mBuffer << stamp << wxT("Audacity ") << AUDACITY_VERSION_STRING << wxT("\n");
   }

   mBuffer << str << wxT("\n");

   mUpdated = true;

   Flush();

   if (!wxIsMainThread()) {
      wxMutexGuiLeave();
   }
}
Exemple #30
0
   static void *Listener(void *parm)
   {
      DeviceChangeListener *This = (DeviceChangeListener *) parm;

      // Instantiate the udev object
      struct udev *udev = udev_new();
      if (!udev)
      {
         pthread_exit(NULL);
      }
   
      // Instantiate the monitor object
      struct udev_monitor *mon = udev_monitor_new_from_netlink(udev, "udev");

      // Start receiving notifications
      udev_monitor_enable_receiving(mon);

      // Get the file descriptor we'll wait on
      int fd = udev_monitor_get_fd(mon);

      while (true)
      {
         fd_set set;
         
         FD_ZERO(&set);
         FD_SET(fd, &set);

         if (select(fd + 1, &set, NULL, NULL, NULL) < 0)
         {
            break;
         }
         
         if (FD_ISSET(fd, &set))
         {
            struct udev_device *dev = udev_monitor_receive_device(mon);
            if (dev)
            {
#if 0
               printf("Got Device\n");
               printf("   Node: %s\n", udev_device_get_devnode(dev));
               printf("   Subsystem: %s\n", udev_device_get_subsystem(dev));
               printf("   Devtype: %s\n", udev_device_get_devtype(dev));
               printf("   Action: %s\n", udev_device_get_action(dev));
#endif
               if (This->mEnabled)
               {
                  This->mEnabled = false;
                  wxMutexGuiEnter();
                  wxCommandEvent e(EVT_DEVICE_CHANGE);
                  This->mHandler->AddPendingEvent(e);
                  wxMutexGuiLeave();
               }
         
               udev_device_unref(dev);
            }
         }
      }
   
      udev_unref(udev);

      pthread_exit(NULL);
   }