1 #include <stdlib.h>
2 
3 #include <fstream>
4 #include <iostream>
5 #include <iterator>
6 #include <string>
7 
8 #define OONIFFI_EMULATE_MK_API
9 #include "ooniffi.h"
10 
main(int argc,char ** argv)11 int main(int argc, char **argv) {
12   if (argc != 2) {
13     std::clog << "usage: ffirun /path/to/json/settings" << std::endl;
14     exit(1);
15   }
16   std::ifstream filep(argv[1]);
17   if (!filep.good()) {
18     std::clog << "fatal: cannot open settings file" << std::endl;
19     exit(1);
20   }
21   std::string settings((std::istreambuf_iterator<char>(filep)),
22       std::istreambuf_iterator<char>());
23   auto taskp = mk_task_start(settings.c_str());
24   if (taskp == nullptr) {
25     std::clog << "fatal: cannot start task" << std::endl;
26     exit(1);
27   }
28   while (!mk_task_is_done(taskp)) {
29     auto evp = mk_task_wait_for_next_event(taskp);
30     if (evp == nullptr) {
31       std::clog << "warning: cannot wait for next event" << std::endl;
32       break;
33     }
34     auto evstr = mk_event_serialization(evp);
35     if (evstr != nullptr) {
36       std::cout << evstr << std::endl;
37     } else {
38       std::clog << "warning: cannot get event serialization" << std::endl;
39     }
40     mk_event_destroy(evp);
41   }
42   mk_task_destroy(taskp);
43 }
44