DOCloudJob.hh 1.76 KB
Newer Older
1 2
// (C) Copyright 2015 by Autodesk, Inc.

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
//=============================================================================
//
//  namespace COMISO::DOcloud
//
//=============================================================================

//== COMPILE-TIME PACKAGE REQUIREMENTS ========================================
#ifndef COMISO_DOCLOUDJOB_HH
#define COMISO_DOCLOUDJOB_HH

#include <CoMISo/Config/config.hh>
#if COMISO_DOCLOUD_AVAILABLE

#include "cURLpp.hh"

#include <Base/Utils/StopWatch.hh>
#include <string>
#include <vector>

namespace COMISO {
namespace DOcloud { 

class JsonTokens;

class Job : public cURLpp::Session
{
public:
30
  Job(const std::string& _filename, const std::string& _file_buf) 
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
    : filename_(_filename), file_buf_(_file_buf), stts_(nullptr) 
  {}
  ~Job();

  void setup()
  {
    make();
    upload();
    start();
  }

  void wait();
  void sync_status();
  void sync_log();
  bool active() const; // requires synchronized status
Martin Marinov's avatar
Martin Marinov committed
46
  bool stalled() const;
47 48 49 50 51 52 53

  void abort();
  double solution(std::vector<double>& _x) const;

protected:
  void make();
  void start();
54
  void upload(cURLpp::Upload& _upld);
55 56 57
  void upload();

private:
58 59
  const std::string filename_;
  const std::string file_buf_;
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
  std::string url_;
  JsonTokens* stts_;
  // these variables are initialized in start() 
  int log_seq_idx_; // the log sequence number, used to get DOcloud log entires
  int sol_nmbr_; // number of solutions found so far, according to the log
  int sol_sec_nmbr_; // number of seconds at the last new solution 
  int stld_sec_nmbr_; // number of seconds since the last new solution 
  Base::StopWatch stop_wtch_; // time since last successful log synchronization.
};

} // namespace DOcloud 
} // namespace COMISO 

#endif//COMISO_DOCLOUD_AVAILABLE
#endif//COMISO_DOCLOUDJOB_HH