Emdee
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
progressreporter.h
Go to the documentation of this file.
1 #ifndef PROGRESSREPORT_H
2 #define PROGRESSREPORT_H
3 
4 #include <exception>
5 
6 #include <stdio.h>
7 // The curl library must be installed, do something like sudo apt-get install libcurl4-openssl-dev
8 //#include <curl/curl.h>
9 #include <time.h>
10 #include <iostream>
11 #include <string>
12 // <thread> is a c++11 feature, you need to compile with -std=c++0x
13 #include <thread>
14 
15 using namespace std;
16 
18 public:
19  ProgressReporter(string username, string runName);
20 
21  void reportProgress(double progress);
22 private:
23  double m_lastReportTime;
24  string m_username;
25  int m_runID;
26  string m_runName;
27 };
28 
29 inline ProgressReporter::ProgressReporter(string username, string runName) :
30  m_lastReportTime(0),
31  m_username(username),
32  m_runName(runName)
33 {
34 // srand(time(NULL));
35 // m_runID = rand();
36 }
37 
38 inline void ProgressReporter::reportProgress(double progress)
39 {
40  (void)progress;
41 // time_t timer;
42 // struct tm someTime;
43 // double seconds;
44 
45 // someTime.tm_hour = 0; someTime.tm_min = 0; someTime.tm_sec = 0;
46 // someTime.tm_year = 100; someTime.tm_mon = 0; someTime.tm_mday = 1;
47 // time(&timer); /* get current time; same as: timer = time(NULL) */
48 
49 // seconds = difftime(timer,mktime(&someTime));
50 // if(progress != 0 && progress != 1 && seconds - 10 < m_lastReportTime) { // skip all reports that come too soon, except the first and the last
51 // return;
52 // }
53 // if(progress < 0 || progress > 1) {
54 // cerr << "Progress must be between 0 and 1." << endl;
55 // throw new std::exception();
56 // }
57 // CURL *curl;
58 // curl = curl_easy_init();
59 // if(curl) {
60 // stringstream url;
61 // url << "http://compphys.dragly.org/wp-content/plugins/run-reporter/submit.php?";
62 // url << "user=" << m_username;
63 // url << "&runName=" << m_runName;
64 // url << "&runID=" << m_runID;
65 // url << "&progress=" << progress;
66 // curl_easy_setopt(curl, CURLOPT_URL, url.str().c_str());
67 // curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 5000);
68 // /* example.com is redirected, so we tell libcurl to follow redirection */
69 // curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
70 
71 // /* Perform the request, res will get the return code */
72 // // res = curl_easy_perform(curl);
73 // /* Check for errors */
74 // // if(res != CURLE_OK)
75 // // fprintf(stderr, "curl_easy_perform() failed: %s\n",
76 // // curl_easy_strerror(res));
77 
78 // thread test(ProgressReporter::callAndCleanCurl, curl);
79 // if(progress == 1) {
80 // test.join();
81 // } else {
82 // test.detach();
83 // }
84 // }
85 // m_lastReportTime = seconds;
86 }
87 #endif // PROGRESSREPORT_H