diff eventLogger.h @ 8:e2c6cfe8c6b7

JSON logs and presets.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Thu, 10 Jan 2013 18:24:26 +0000
parents 845ea04f8e33
children 346807b47860
line wrap: on
line diff
--- a/eventLogger.h	Thu Dec 06 18:26:51 2012 +0000
+++ b/eventLogger.h	Thu Jan 10 18:24:26 2013 +0000
@@ -11,6 +11,7 @@
 #ifndef __oscSenderExample__eventLogger__
 #define __oscSenderExample__eventLogger__
 
+#define EVENT_LOG_FILENAME "log.json"
 
 #include "ofMain.h"
 #include "ofxiPhone.h"
@@ -21,8 +22,16 @@
 #include <string>
 #include <map>
 #include "2dvector.h"
+#include "json.h"
+
+#import "iViewController.h"
+
+
+
 enum leventType {SAVE_PRESET, SAVE_DESET, SCROLL, SCROLL_STOPPED, ZOOM, CHANGE_SLIDER, SWAP_VIEW, SET_MIN_ZOOM, SET_MAX_ZOOM};
 
+//---------------------------------------------------------------------------
+
 class lEvent{
 public:
     // try and make this as compact as possible.
@@ -30,14 +39,29 @@
     double val1; // x coord, scale if zoom
     double val2; // y coord, 0 if zoom
     int sliderID;
-    lEvent(leventType eType, double v1, double v2 = 0.0,int sID = 0){
+    lEvent(leventType eType, double v1 = 0.0, double v2 = 0.0,int sID = 0){
         eventType = eType;
         val1 = v1;
         val2 = v2;
         sliderID = sID;
     }
+    lEvent(const Json::Value &jevt){
+        eventType = (leventType)jevt["eventType"].asInt();
+        val1 = jevt["val1"].asFloat();
+        val2 = jevt["val2"].asFloat();
+        sliderID = jevt["sliderID"].asInt();
+    }
+    Json::Value eventToJson(){
+        Json::Value jevt;
+        jevt["eventType"] = eventType;
+        jevt["val1"] = val1;
+        jevt["val2"] = val2;
+        jevt["sliderID"] = sliderID;
+        return jevt;
+    }
 };
 //---------------------------------------------------------------------------
+// streams no longer used
 inline istream& operator>>(istream & is, lEvent& e){
     is.setf(ios_base::fixed,ios_base::floatfield);
     is.precision(1);
@@ -73,20 +97,24 @@
     
     vector<lEvent> theEvents;
     
-    unsigned int deviceID; // get something from hardware??
+    
+    // values applicable to all events
+    unsigned int deviceID; // unique get something from hardware??
     unsigned int totalInteractionTime, sessionTime, sessionStartTime;
-    string userName;
-    
+    string userName; // not unique
+    unsigned int nextUploadQty;
     EventLogger();
     void init();
-    
+    void setUsername(const char *u);
     void logEvent(const leventType& evtType,const TwoVector& centre = TwoVector(), const double& scale = 1.0, const int& sliderID = -1, const double& sliderVal = 0.0);
     void logEvent(const leventType& evtType,const int& sliderID, const double& sliderVal);
     void sendHttp();
     void checkLogFile();
-    void attemptUpload();
+    bool attemptUpload();
     void firstEverAppOpen();
+    void readJsonToLog(const string &jsonFile);
     void exitAndSave();
+    Json::Value logsToJson();
     void printAll(){
         cout << "ALL LOGGED EVENTS!: \n";
         vector<lEvent>::iterator evIter;
@@ -98,6 +126,7 @@
 };
 
 
-    
+    //---------------------------------------------------------------------------
+   
 
 #endif /* defined(__oscSenderExample__eventLogger__) */