35 LinuxEventLoop::registerFdCallback (getReadHandle(),
38 while (
auto msg = popNextMessage (
fd))
42 msg->messageCallback();
51 LinuxEventLoop::unregisterFdCallback (getReadHandle());
53 close (getReadHandle());
54 close (getWriteHandle());
65 if (bytesInSocket < maxBytesInSocketQueue)
70 unsigned char x = 0xff;
83 int bytesInSocket = 0;
84 static constexpr int maxBytesInSocketQueue = 128;
86 int getWriteHandle()
const noexcept {
return msgpipe[0]; }
87 int getReadHandle()
const noexcept {
return msgpipe[1]; }
93 if (bytesInSocket > 0)
140 const auto iter = getPollfd (
fd);
142 if (iter == pfds.end() || iter->fd !=
fd)
150 listeners.call ([] (
auto&
l) {
l.fdCallbacksChanged(); });
153 void unregisterFdCallback (
int fd)
158 callbacks.erase (
fd);
160 const auto iter = getPollfd (
fd);
162 if (iter != pfds.end() && iter->fd ==
fd)
170 listeners.call ([] (
auto&
l) {
l.fdCallbacksChanged(); });
173 bool dispatchPendingEvents()
175 callbackStorage.clear();
176 getFunctionsToCallThisTime (callbackStorage);
179 for (
auto& fn : callbackStorage)
182 return ! callbackStorage.empty();
185 void dispatchEvent (
int fd)
const
190 const auto iter = callbacks.find (
fd);
191 return iter != callbacks.end() ? iter->second :
nullptr;
195 if (
auto* callback = fn.get())
199 bool sleepUntilNextEvent (
int timeoutMs)
202 return poll (pfds.data(),
static_cast<nfds_t> (pfds.size()), timeoutMs) != 0;
209 result.
reserve (callbacks.size());
213 [] (
const auto& pair) { return pair.first; });
236 if (! sleepUntilNextEvent (0))
239 for (
auto&
pfd : pfds)
243 const auto iter = callbacks.find (
pfd.fd);
245 if (iter != callbacks.end())
255 return descriptor.fd < toFind;
259 bool pfdsAreSorted()
const
261 return std::is_sorted (pfds.begin(), pfds.end(), [] (
auto a,
auto b) { return a.fd < b.fd; });
276namespace LinuxErrorHandling
278 static bool keyboardBreakOccurred =
false;
280 static void keyboardBreakSignalHandler (
int sig)
283 keyboardBreakOccurred =
true;
286 static void installKeyboardBreakHandler()
291 saction.sa_handler = keyboardBreakSignalHandler;
299void MessageManager::doPlatformSpecificInitialisation()
302 LinuxErrorHandling::installKeyboardBreakHandler();
304 InternalRunLoop::getInstance();
305 InternalMessageQueue::getInstance();
308void MessageManager::doPlatformSpecificShutdown()
310 InternalMessageQueue::deleteInstance();
311 InternalRunLoop::deleteInstance();
314bool MessageManager::postMessageToSystemQueue (MessageManager::MessageBase*
const message)
316 if (
auto* queue = InternalMessageQueue::getInstanceWithoutCreating())
318 queue->postMessage (message);
337 if (LinuxErrorHandling::keyboardBreakOccurred)
340 if (
auto*
runLoop = InternalRunLoop::getInstanceWithoutCreating())
342 if (
runLoop->dispatchPendingEvents())
348 runLoop->sleepUntilNextEvent (2000);
359 if (
auto*
runLoop = InternalRunLoop::getInstanceWithoutCreating())
363void LinuxEventLoop::unregisterFdCallback (
int fd)
365 if (
auto*
runLoop = InternalRunLoop::getInstanceWithoutCreating())
372 if (
auto*
runLoop = InternalRunLoop::getInstanceWithoutCreating())
373 runLoop->addListener (listener);
376void LinuxEventLoopInternal::deregisterLinuxEventLoopListener (LinuxEventLoopInternal::Listener& listener)
378 if (
auto*
runLoop = InternalRunLoop::getInstanceWithoutCreating())
379 runLoop->removeListener (listener);
382void LinuxEventLoopInternal::invokeEventLoopCallbackForFd (
int fd)
384 if (
auto*
runLoop = InternalRunLoop::getInstanceWithoutCreating())
390 if (
auto*
runLoop = InternalRunLoop::getInstanceWithoutCreating())
391 return runLoop->getRegisteredFds();
T back_inserter(T... args)
Automatically locks and unlocks a mutex object.
Automatically unlocks and re-locks a mutex object.
static void quit()
Signals that the main message loop should stop and the application should terminate.
static bool isStandaloneApp() noexcept
Returns true if this executable is running as an app (as opposed to being a plugin or other kind of s...
Holds a set of objects and can invoke a member function callback on each object in the set with a sin...
Internal class used as the base class for all message objects.
static void broadcastMessage(const String &messageText)
Sends a message to all other JUCE applications that are running.
ObjectClassPtr removeAndReturn(int indexToRemove)
Removes and returns an object from the array.
A smart-pointer class which points to a reference-counted object.
T emplace_back(T... args)
#define JUCE_TRY
The JUCE_TRY/JUCE_CATCH_EXCEPTION wrappers can be used to pass any uncaught exceptions to the JUCEApp...
#define JUCE_CATCH_EXCEPTION
The JUCE_TRY/JUCE_CATCH_EXCEPTION wrappers can be used to pass any uncaught exceptions to the JUCEApp...
#define JUCE_IMPLEMENT_SINGLETON(Classname)
This is a counterpart to the JUCE_DECLARE_SINGLETON macros.
#define JUCE_DECLARE_SINGLETON(Classname, doNotRecreateAfterDeletion)
Macro to generate the appropriate methods and boilerplate for a singleton class.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...