Skip to content

Commit

Permalink
Added a backend monitor object to the event loop example
Browse files Browse the repository at this point in the history
  • Loading branch information
gansm committed Sep 24, 2024
1 parent 9e6d5da commit b17f41c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
17 changes: 11 additions & 6 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,21 @@ AC_CHECK_FUNCS( \
timer_settime \
vsnprintf \
wcwidth )
# Checks for 'tgetent'
AC_SEARCH_LIBS([tgetent], [terminfo mytinfo termlib termcap tinfo ncurses curses])
# Checks for 'tparm'
AC_SEARCH_LIBS([tparm], [terminfo mytinfo termlib termcap tinfo ncurses curses])

# Checks for 'pthread_rwlock_wrlock'
AC_SEARCH_LIBS([pthread_rwlock_wrlock], [pthread])

# Checks for 'timer_create'
AC_SEARCH_LIBS([timer_create], [rt])

# Checks for 'timer_settime'
AC_SEARCH_LIBS([timer_settime], [rt])
# Checks for 'pthread_rwlock_wrlock'
AC_SEARCH_LIBS([pthread_rwlock_wrlock], [pthread])

# Checks for 'tgetent'
AC_SEARCH_LIBS([tgetent], [terminfo mytinfo termlib termcap tinfo ncurses curses])

# Checks for 'tparm'
AC_SEARCH_LIBS([tparm], [terminfo mytinfo termlib termcap tinfo ncurses curses])

AC_SUBST([FINAL_LIBS])
AC_SUBST([TERMCAP_LIB])
Expand Down
18 changes: 18 additions & 0 deletions examples/eventloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <cstdio>
#include <iostream>
#include <thread>

#include <final/final.h>

Expand All @@ -47,6 +48,13 @@ static void onExit()
std::cout << "Bye!" << std::endl;
}

//----------------------------------------------------------------------
void wait_5_seconds (const finalcut::BackendMonitor* mon)
{
std::this_thread::sleep_for(std::chrono::seconds(5));
mon->setEvent(); // Generates the event
}


//----------------------------------------------------------------------
// main part
Expand All @@ -60,8 +68,10 @@ auto main() -> int
finalcut::SignalMonitor sig_int_monitor{&loop};
finalcut::SignalMonitor sig_abrt_monitor{&loop};
finalcut::IoMonitor stdin_monitor{&loop};
finalcut::BackendMonitor backend_monitor{&loop};
finalcut::FTermios::init();
auto stdin_no = finalcut::FTermios::getStdIn();
std::thread backend_thread(wait_5_seconds, &backend_monitor);

// Save terminal setting and set terminal to raw mode
// (no echo, no line buffering).
Expand Down Expand Up @@ -125,12 +135,20 @@ auto main() -> int
}
, nullptr );

backend_monitor.init ( [] (const finalcut::Monitor*, short)
{
std::cout << "A backend event has occurred." << std::endl;
}
, nullptr );

// Start monitors
timer1.resume();
timer2.resume();
sig_int_monitor.resume();
sig_abrt_monitor.resume();
stdin_monitor.resume();
backend_monitor.resume();
backend_thread.detach();

// Monitoring
return loop.run();
Expand Down
2 changes: 1 addition & 1 deletion final/fapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ auto FApplication::isWheelEvent (const FMouseData& md) -> bool
|| md.isWheelDown()
|| md.isWheelLeft()
|| md.isWheelRight();
};
}

//----------------------------------------------------------------------
void FApplication::unsetMoveResizeMode (const FMouseData&)
Expand Down

0 comments on commit b17f41c

Please sign in to comment.