Lumiverse  2.5
A framework for creating lighting control applications
DistributedArnoldInterface.h
1 
4 #ifndef _ArnoldDISTRIBUTED_INTERFACE_H_
5 #define _ArnoldDISTRIBUTED_INTERFACE_H_
6 
7 #pragma once
8 
9 #include "LumiverseCoreConfig.h"
10 
11 #ifdef USE_ARNOLD
12 #ifdef USE_DUMIVERSE
13 
14 #include <curl_easy.h>
15 #include <curl_exception.h>
16 #include <curl_form.h>
17 #include <zlib.h>
18 #include <algorithm>
19 #include <cstdio>
20 #include "ArnoldInterface.h"
21 #include "../lib/libjson/libjson.h"
22 #include <thread>
23 #include <iostream>
24 #include <locale>
25 #include <unordered_map>
26 
27 // Apparently we need this to use zlib on windows to avoid windows being
28 // dumb and converting end-of-line characters for binary files
29 #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
30 # include <fcntl.h>
31 # include <io.h>
32 # define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
33 #else
34 # define SET_BINARY_MODE(file)
35 #endif
36 
37 #define CHUNK (1 << 17)
38 #define WINDOW_BITS 15
39 #define GZIP_ENCODING 16
40 
41 namespace Lumiverse {
42 
46  struct RequestBuffer {
47  char *buffer = NULL;
48  size_t num_written = 0;
49  };
50 
61  static size_t write_buffer_callback(void *ptr, size_t size, size_t nmemb, void *userdata);
62 
70  class DistributedArnoldInterface : public virtual ArnoldInterface
71  {
72  public:
79  DistributedArnoldInterface(string host, int port, string outputPath) :
80  ArnoldInterface(),
81  m_host_name(host),
82  m_host_port(port),
83  m_file_output_path(outputPath),
84  m_remote_open(false) {}
85 
92  DistributedArnoldInterface() :
93  ArnoldInterface(),
94  m_host_name("localhost"),
95  m_host_port(80),
96  m_file_output_path("./test.out"),
97  m_remote_open(false) {}
98 
99 
100  ~DistributedArnoldInterface() { }
101 
110  void init(const JSONNode jsonPatch);
111 
119  void close() override;
120 
124  bool setDims(int w, int h) override;
125 
129  void setSamples(int samples) override;
130 
136  virtual string getInterfaceType() { return "DistributedArnoldInterface"; }
137 
145  void setHostPort(long hostPort) { m_host_port = hostPort; };
146 
150  long getHostPort() { return m_host_port; };
151 
158  void setHostName(std::string hostName) { m_host_name = hostName; };
159 
165  std::string getHostName() { return m_host_name; };
166 
175  int render(const std::set<Device *> &devices);
176 
180  void interrupt() override;
181 
187  virtual float getPercentage() override;
188 
194  curl::curl_easy getCurlConnection() { return m_curl_connection; };
195 
201  std::string getFileOutputPath() { return m_file_output_path; };
202 
208  void setFileOutputPath(std::string outputPath) { m_file_output_path = outputPath; };
209 
218  void setOptionParameter(const std::string &paramName, int val) override;
219  void setOptionParameter(const std::string &paramName, float val) override;
220 
224  bool isDistributedOpen() override;
225 
226  private:
227 
231  std::string m_host_name;
232 
236  long m_host_port;
237 
246  bool openConnection();
247 
259  bool sendDistributedInitRequest(const JSONNode jsonPatch);
260 
269  bool closeConnection();
270 
274  curl::curl_easy m_curl_connection;
275 
282  std::string m_file_output_path;
283 
290  bool deflateAss();
291 
299  void bindRequestBuffer(struct RequestBuffer *buffer, curl::curl_easy &curl_request);
300 
308  void bindRequestBuffer(struct RequestBuffer *buffer);
309 
313  bool remoteRequestSuccessful(JSONNode response);
314 
322  const JSONNode getDevicesJSON(const std::set<Device *> &devices);
323 
330  const JSONNode getSettingsJSON();
331 
332  // Maps containing global Arnold options node settings
333  std::unordered_map<std::string, float> float_options;
334  std::unordered_map<std::string, int> int_options;
335 
339  bool m_remote_open;
340  };
341 }
342 
343 #endif // USE_DUMIVERSE
344 #endif // USE_ARNOLD
345 #endif // _ArnoldDISTRIBUTED_INTERFACE_H_
void render()
Render a frame and pass it back to node.
Definition: Dumiverse.cpp:43
void interrupt()
Interrupt the current Arnold renderer.
Definition: Dumiverse.cpp:114
void close()
Close the connection to node.
Definition: Dumiverse.cpp:37
void init(const char *jsonPatchStr, const char *filename)
Initializes data structures.
Definition: Dumiverse.cpp:29
float getPercentage()
Gets the progress of current frame as a percentage.
Definition: Dumiverse.cpp:25
Contains all core Lumiverse functions and variables.
Definition: Device.cpp:2
Implementation of a interface between ArnoldPatch and arnold.