aboutsummaryrefslogtreecommitdiff
path: root/tools/gator/daemon/ExternalSource.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/gator/daemon/ExternalSource.cpp')
-rw-r--r--tools/gator/daemon/ExternalSource.cpp59
1 files changed, 39 insertions, 20 deletions
diff --git a/tools/gator/daemon/ExternalSource.cpp b/tools/gator/daemon/ExternalSource.cpp
index 8f5e6b684c53..8d71b6de3d5e 100644
--- a/tools/gator/daemon/ExternalSource.cpp
+++ b/tools/gator/daemon/ExternalSource.cpp
@@ -1,5 +1,5 @@
/**
- * Copyright (C) ARM Limited 2010-2014. All rights reserved.
+ * Copyright (C) ARM Limited 2010-2015. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -12,10 +12,14 @@
#include <sys/prctl.h>
#include <unistd.h>
+#include "Child.h"
#include "Logging.h"
#include "OlySocket.h"
#include "SessionData.h"
+extern Child *child;
+
+static const char STREAMLINE_ANNOTATE[] = "\0streamline-annotate";
static const char MALI_VIDEO[] = "\0mali-video";
static const char MALI_VIDEO_STARTUP[] = "\0mali-video-startup";
static const char MALI_VIDEO_V1[] = "MALI_VIDEO 1\n";
@@ -40,7 +44,7 @@ static bool setNonblock(const int fd) {
return true;
}
-ExternalSource::ExternalSource(sem_t *senderSem) : mBuffer(0, FRAME_EXTERNAL, 128*1024, senderSem), mMonitor(), mMveStartupUds(MALI_VIDEO_STARTUP, sizeof(MALI_VIDEO_STARTUP)), mMaliStartupUds(MALI_GRAPHICS_STARTUP, sizeof(MALI_GRAPHICS_STARTUP)), mAnnotate(8083), mInterruptFd(-1), mMaliUds(-1), mMveUds(-1) {
+ExternalSource::ExternalSource(sem_t *senderSem) : mBuffer(0, FRAME_EXTERNAL, 128*1024, senderSem), mMonitor(), mMveStartupUds(MALI_VIDEO_STARTUP, sizeof(MALI_VIDEO_STARTUP)), mMaliStartupUds(MALI_GRAPHICS_STARTUP, sizeof(MALI_GRAPHICS_STARTUP)), mAnnotate(8083), mAnnotateUds(STREAMLINE_ANNOTATE, sizeof(STREAMLINE_ANNOTATE), true), mInterruptFd(-1), mMaliUds(-1), mMveUds(-1) {
sem_init(&mBufferSem, 0, 0);
}
@@ -49,18 +53,22 @@ ExternalSource::~ExternalSource() {
void ExternalSource::waitFor(const int bytes) {
while (mBuffer.bytesAvailable() <= bytes) {
+ if (gSessionData->mOneShot && gSessionData->mSessionIsActive) {
+ logg->logMessage("One shot (external)");
+ child->endSession();
+ }
sem_wait(&mBufferSem);
}
}
void ExternalSource::configureConnection(const int fd, const char *const handshake, size_t size) {
if (!setNonblock(fd)) {
- logg->logError(__FILE__, __LINE__, "Unable to set nonblock on fh");
+ logg->logError("Unable to set nonblock on fh");
handleException();
}
if (!mMonitor.add(fd)) {
- logg->logError(__FILE__, __LINE__, "Unable to add fh to monitor");
+ logg->logError("Unable to add fh to monitor");
handleException();
}
@@ -68,7 +76,7 @@ void ExternalSource::configureConnection(const int fd, const char *const handsha
waitFor(Buffer::MAXSIZE_PACK32 + size - 1);
mBuffer.packInt(fd);
mBuffer.writeBytes(handshake, size - 1);
- mBuffer.commit(1);
+ mBuffer.commit(1, true);
}
bool ExternalSource::connectMali() {
@@ -106,6 +114,7 @@ bool ExternalSource::prepare() {
!setNonblock(mMveStartupUds.getFd()) || !mMonitor.add(mMveStartupUds.getFd()) ||
!setNonblock(mMaliStartupUds.getFd()) || !mMonitor.add(mMaliStartupUds.getFd()) ||
!setNonblock(mAnnotate.getFd()) || !mMonitor.add(mAnnotate.getFd()) ||
+ !setNonblock(mAnnotateUds.getFd()) || !mMonitor.add(mAnnotateUds.getFd()) ||
false) {
return false;
}
@@ -122,18 +131,21 @@ void ExternalSource::run() {
prctl(PR_SET_NAME, (unsigned long)&"gatord-external", 0, 0, 0);
if (pipe_cloexec(pipefd) != 0) {
- logg->logError(__FILE__, __LINE__, "pipe failed");
+ logg->logError("pipe failed");
handleException();
}
mInterruptFd = pipefd[1];
if (!mMonitor.add(pipefd[0])) {
- logg->logError(__FILE__, __LINE__, "Monitor::add failed");
+ logg->logError("Monitor::add failed");
handleException();
}
// Notify annotate clients to retry connecting to gatord
- gSessionData->annotateListener.signal();
+ uint64_t val = 1;
+ if (::write(gSessionData->mAnnotateStart, &val, sizeof(val)) != sizeof(val)) {
+ logg->logMessage("Writing to annotate pipe failed");
+ }
while (gSessionData->mSessionIsActive) {
struct epoll_event events[16];
@@ -141,11 +153,11 @@ void ExternalSource::run() {
while (sem_trywait(&mBufferSem) == 0);
int ready = mMonitor.wait(events, ARRAY_LENGTH(events), -1);
if (ready < 0) {
- logg->logError(__FILE__, __LINE__, "Monitor::wait failed");
+ logg->logError("Monitor::wait failed");
handleException();
}
- const uint64_t currTime = getTime();
+ const uint64_t currTime = getTime() - gSessionData->mMonotonicStarted;
for (int i = 0; i < ready; ++i) {
const int fd = events[i].data.fd;
@@ -155,7 +167,7 @@ void ExternalSource::run() {
// Don't read from this connection, establish a new connection to Mali-V500
close(client);
if (!connectMve()) {
- logg->logError(__FILE__, __LINE__, "Unable to configure incoming Mali video connection");
+ logg->logError("Unable to configure incoming Mali video connection");
handleException();
}
} else if (fd == mMaliStartupUds.getFd()) {
@@ -164,13 +176,19 @@ void ExternalSource::run() {
// Don't read from this connection, establish a new connection to Mali Graphics
close(client);
if (!connectMali()) {
- logg->logError(__FILE__, __LINE__, "Unable to configure incoming Mali graphics connection");
+ logg->logError("Unable to configure incoming Mali graphics connection");
handleException();
}
} else if (fd == mAnnotate.getFd()) {
int client = mAnnotate.acceptConnection();
if (!setNonblock(client) || !mMonitor.add(client)) {
- logg->logError(__FILE__, __LINE__, "Unable to set socket options on incoming annotation connection");
+ logg->logError("Unable to set socket options on incoming annotation connection");
+ handleException();
+ }
+ } else if (fd == mAnnotateUds.getFd()) {
+ int client = mAnnotateUds.acceptConnection();
+ if (!setNonblock(client) || !mMonitor.add(client)) {
+ logg->logError("Unable to set socket options on incoming annotation connection");
handleException();
}
} else if (fd == pipefd[0]) {
@@ -190,28 +208,29 @@ void ExternalSource::run() {
if (bytes < 0) {
if (errno == EAGAIN) {
// Nothing left to read
- mBuffer.commit(currTime);
+ mBuffer.commit(currTime, true);
break;
}
// Something else failed, close the socket
- mBuffer.commit(currTime);
+ mBuffer.commit(currTime, true);
mBuffer.packInt(-1);
mBuffer.packInt(fd);
- mBuffer.commit(currTime);
+ // Here and other commits, always force-flush the buffer as this frame don't work like others
+ mBuffer.commit(currTime, true);
close(fd);
break;
} else if (bytes == 0) {
// The other side is closed
- mBuffer.commit(currTime);
+ mBuffer.commit(currTime, true);
mBuffer.packInt(-1);
mBuffer.packInt(fd);
- mBuffer.commit(currTime);
+ mBuffer.commit(currTime, true);
close(fd);
break;
}
mBuffer.advanceWrite(bytes);
- mBuffer.commit(currTime);
+ mBuffer.commit(currTime, true);
// Short reads also mean nothing is left to read
if (bytes < contiguous) {
@@ -238,7 +257,7 @@ void ExternalSource::interrupt() {
int8_t c = 0;
// Write to the pipe to wake the monitor which will cause mSessionIsActive to be reread
if (::write(mInterruptFd, &c, sizeof(c)) != sizeof(c)) {
- logg->logError(__FILE__, __LINE__, "write failed");
+ logg->logError("write failed");
handleException();
}
}