summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'daemon/StreamlineSetup.cpp')
-rw-r--r--daemon/StreamlineSetup.cpp74
1 files changed, 21 insertions, 53 deletions
diff --git a/daemon/StreamlineSetup.cpp b/daemon/StreamlineSetup.cpp
index 88c07a6..e196a7d 100644
--- a/daemon/StreamlineSetup.cpp
+++ b/daemon/StreamlineSetup.cpp
@@ -20,6 +20,7 @@
20#include "StreamlineSetup.h" 20#include "StreamlineSetup.h"
21#include "ConfigurationXML.h" 21#include "ConfigurationXML.h"
22#include "Driver.h" 22#include "Driver.h"
23#include "EventsXML.h"
23 24
24static const char* TAG_SESSION = "session"; 25static const char* TAG_SESSION = "session";
25static const char* TAG_REQUEST = "request"; 26static const char* TAG_REQUEST = "request";
@@ -77,8 +78,8 @@ StreamlineSetup::StreamlineSetup(OlySocket* s) {
77 free(data); 78 free(data);
78 } 79 }
79 80
80 if (gSessionData->mCounterOverflow) { 81 if (gSessionData->mCounterOverflow > 0) {
81 logg->logError(__FILE__, __LINE__, "Exceeded maximum number of %d performance counters", MAX_PERFORMANCE_COUNTERS); 82 logg->logError(__FILE__, __LINE__, "Only %i performance counters are permitted, %i are selected", MAX_PERFORMANCE_COUNTERS, gSessionData->mCounterOverflow);
82 handleException(); 83 handleException();
83 } 84 }
84} 85}
@@ -87,12 +88,12 @@ StreamlineSetup::~StreamlineSetup() {
87} 88}
88 89
89char* StreamlineSetup::readCommand(int* command) { 90char* StreamlineSetup::readCommand(int* command) {
90 char type; 91 unsigned char header[5];
91 char* data; 92 char* data;
92 int response, length; 93 int response;
93 94
94 // receive type 95 // receive type and length
95 response = mSocket->receiveNBytes(&type, sizeof(type)); 96 response = mSocket->receiveNBytes((char*)&header, sizeof(header));
96 97
97 // After receiving a single byte, we are no longer waiting on a command 98 // After receiving a single byte, we are no longer waiting on a command
98 gSessionData->mWaitingOnCommand = false; 99 gSessionData->mWaitingOnCommand = false;
@@ -102,12 +103,8 @@ char* StreamlineSetup::readCommand(int* command) {
102 handleException(); 103 handleException();
103 } 104 }
104 105
105 // receive length 106 const char type = header[0];
106 response = mSocket->receiveNBytes((char*)&length, sizeof(length)); 107 const int length = (header[1] << 0) | (header[2] << 8) | (header[3] << 16) | (header[4] << 24);
107 if (response < 0) {
108 logg->logError(__FILE__, __LINE__, "Target error: Unexpected socket disconnect");
109 handleException();
110 }
111 108
112 // add artificial limit 109 // add artificial limit
113 if ((length < 0) || length > 1024 * 1024) { 110 if ((length < 0) || length > 1024 * 1024) {
@@ -198,51 +195,22 @@ void StreamlineSetup::handleDeliver(char* xml) {
198 mxmlDelete(tree); 195 mxmlDelete(tree);
199} 196}
200 197
201void StreamlineSetup::sendData(const char* data, int length, int type) { 198void StreamlineSetup::sendData(const char* data, uint32_t length, char type) {
202 mSocket->send((char*)&type, 1); 199 unsigned char header[5];
203 mSocket->send((char*)&length, sizeof(length)); 200 header[0] = type;
201 header[1] = (length >> 0) & 0xff;
202 header[2] = (length >> 8) & 0xff;
203 header[3] = (length >> 16) & 0xff;
204 header[4] = (length >> 24) & 0xff;
205 mSocket->send((char*)&header, sizeof(header));
204 mSocket->send((char*)data, length); 206 mSocket->send((char*)data, length);
205} 207}
206 208
207void StreamlineSetup::sendEvents() { 209void StreamlineSetup::sendEvents() {
208#include "events_xml.h" // defines and initializes char events_xml[] and int events_xml_len 210 EventsXML eventsXML;
209 char path[PATH_MAX]; 211 char* string = eventsXML.getXML();
210 mxml_node_t *xml;
211 FILE *fl;
212
213 // Avoid unused variable warning
214 (void)events_xml_len;
215
216 // Load the provided or default events xml
217 if (gSessionData->mEventsXMLPath) {
218 strncpy(path, gSessionData->mEventsXMLPath, PATH_MAX);
219 } else {
220 util->getApplicationFullPath(path, PATH_MAX);
221 strncat(path, "events.xml", PATH_MAX - strlen(path) - 1);
222 }
223 fl = fopen(path, "r");
224 if (fl) {
225 xml = mxmlLoadFile(NULL, fl, MXML_NO_CALLBACK);
226 fclose(fl);
227 } else {
228 logg->logMessage("Unable to locate events.xml, using default");
229 xml = mxmlLoadString(NULL, (char *)events_xml, MXML_NO_CALLBACK);
230 }
231
232 // Add dynamic events from the drivers
233 mxml_node_t *events = mxmlFindElement(xml, xml, "events", NULL, NULL, MXML_DESCEND);
234 if (!events) {
235 logg->logMessage("Unable to find <events> node in the events.xml");
236 handleException();
237 }
238 for (Driver *driver = Driver::getHead(); driver != NULL; driver = driver->getNext()) {
239 driver->writeEvents(events);
240 }
241
242 char* string = mxmlSaveAllocString(xml, mxmlWhitespaceCB);
243 sendString(string, RESPONSE_XML); 212 sendString(string, RESPONSE_XML);
244 free(string); 213 free(string);
245 mxmlDelete(xml);
246} 214}
247 215
248void StreamlineSetup::sendConfiguration() { 216void StreamlineSetup::sendConfiguration() {
@@ -302,8 +270,8 @@ void StreamlineSetup::writeConfiguration(char* xml) {
302 // Re-populate gSessionData with the configuration, as it has now changed 270 // Re-populate gSessionData with the configuration, as it has now changed
303 { ConfigurationXML configuration; } 271 { ConfigurationXML configuration; }
304 272
305 if (gSessionData->mCounterOverflow) { 273 if (gSessionData->mCounterOverflow > 0) {
306 logg->logError(__FILE__, __LINE__, "Exceeded maximum number of %d performance counters", MAX_PERFORMANCE_COUNTERS); 274 logg->logError(__FILE__, __LINE__, "Only %i performance counters counters are permitted, %i are selected", MAX_PERFORMANCE_COUNTERS, gSessionData->mCounterOverflow);
307 handleException(); 275 handleException();
308 } 276 }
309} 277}