Bug 714183: Import downstream widget/src/gonk changes from b2g. rs=cjones,mwu

This commit is contained in:
Chris Jones 2011-12-29 14:39:25 -08:00
Родитель afff57e387
Коммит 12dda5aa07
2 изменённых файлов: 27 добавлений и 19 удалений

Просмотреть файл

@ -45,17 +45,18 @@
#include <signal.h> #include <signal.h>
#include <sys/epoll.h> #include <sys/epoll.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include "mozilla/Hal.h"
#include "mozilla/Services.h"
#include "nsAppShell.h" #include "nsAppShell.h"
#include "nsGkAtoms.h" #include "nsGkAtoms.h"
#include "nsGUIEvent.h" #include "nsGUIEvent.h"
#include "nsWindow.h"
#include "nsIObserverService.h" #include "nsIObserverService.h"
#include "mozilla/Services.h" #include "nsWindow.h"
#include "android/log.h" #include "android/log.h"
@ -399,11 +400,6 @@ nsAppShell::~nsAppShell()
nsresult nsresult
nsAppShell::Init() nsAppShell::Init()
{ {
epoll_event event = {
EPOLLIN,
{ 0 }
};
nsresult rv = nsBaseAppShell::Init(); nsresult rv = nsBaseAppShell::Init();
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -413,12 +409,8 @@ nsAppShell::Init()
int ret = pipe2(signalfds, O_NONBLOCK); int ret = pipe2(signalfds, O_NONBLOCK);
NS_ENSURE_FALSE(ret, NS_ERROR_UNEXPECTED); NS_ENSURE_FALSE(ret, NS_ERROR_UNEXPECTED);
FdHandler *handler = mHandlers.AppendElement(); rv = AddFdHandler(signalfds[0], pipeHandler);
handler->fd = signalfds[0]; NS_ENSURE_SUCCESS(rv, rv);
handler->func = pipeHandler;
event.data.u32 = mHandlers.Length() - 1;
ret = epoll_ctl(epollfd, EPOLL_CTL_ADD, signalfds[0], &event);
NS_ENSURE_FALSE(ret, NS_ERROR_UNEXPECTED);
DIR *dir = opendir("/dev/input"); DIR *dir = opendir("/dev/input");
NS_ENSURE_TRUE(dir, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(dir, NS_ERROR_UNEXPECTED);
@ -461,17 +453,30 @@ nsAppShell::Init()
if (!handlerFunc) if (!handlerFunc)
continue; continue;
handler = mHandlers.AppendElement(); rv = AddFdHandler(fd, handlerFunc);
handler->fd = fd; if (NS_FAILED(rv))
handler->func = handlerFunc;
event.data.u32 = mHandlers.Length() - 1;
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &event))
LOG("Failed to add fd to epoll fd"); LOG("Failed to add fd to epoll fd");
} }
return rv; return rv;
} }
nsresult
nsAppShell::AddFdHandler(int fd, FdHandlerCallback handlerFunc)
{
epoll_event event = {
EPOLLIN,
{ 0 }
};
FdHandler *handler = mHandlers.AppendElement();
handler->fd = fd;
handler->func = handlerFunc;
event.data.u32 = mHandlers.Length() - 1;
return epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &event) ?
NS_ERROR_UNEXPECTED : NS_OK;
}
void void
nsAppShell::ScheduleNativeEventCallback() nsAppShell::ScheduleNativeEventCallback()
{ {

Просмотреть файл

@ -86,6 +86,9 @@ protected:
virtual void ScheduleNativeEventCallback(); virtual void ScheduleNativeEventCallback();
private:
nsresult AddFdHandler(int fd, FdHandlerCallback handlerFunc);
// This is somewhat racy but is perfectly safe given how the callback works // This is somewhat racy but is perfectly safe given how the callback works
bool mNativeCallbackRequest; bool mNativeCallbackRequest;
nsTArray<FdHandler> mHandlers; nsTArray<FdHandler> mHandlers;