Allolib  1.0
C++ Components For Interactive Multimedia
al_HtmlInterfaceServer.hpp
1 #ifndef INCLUDE_AL_HTMLINTERFACESERVER_HPP
2 #define INCLUDE_AL_HTMLINTERFACESERVER_HPP
3 /* Allocore --
4  Multimedia / virtual environment application class library
5 
6  Copyright (C) 2009. AlloSphere Research Group, Media Arts & Technology,
7  UCSB. Copyright (C) 2012. The Regents of the University of California. All
8  rights reserved.
9 
10  Redistribution and use in source and binary forms, with or without
11  modification, are permitted provided that the following conditions are
12  met:
13 
14  Redistributions of source code must retain the above copyright
15  notice, this list of conditions and the following disclaimer.
16 
17  Redistributions in binary form must reproduce the above
18  copyright notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the
20  distribution.
21 
22  Neither the name of the University of California nor the names
23  of its contributors may be used to endorse or promote products derived from
24  this software without specific prior written permission.
25 
26  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
27  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
30  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
33  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
34  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
35  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 
38 
39  File description:
40  Serve an HTML GUI to connect to a ParameterServer and PresetServer
41  using interface.js
42 
43  File author(s):
44  2016 Andres Cabrera andres@mat.ucsb.edu
45 */
46 
47 #include <fstream>
48 #include <iostream>
49 #include <string>
50 
51 #ifndef AL_WINDOWS
52 #include <signal.h>
53 #include <stdio.h>
54 #include <sys/wait.h>
55 #include <unistd.h>
56 
57 #define READ 0
58 #define WRITE 1
59 #else
60 
61 #endif
62 
63 #include "al/ui/al_Parameter.hpp"
64 #include "al/ui/al_PresetHandler.hpp"
65 #include "al/ui/al_PresetServer.hpp"
66 
67 namespace al {
85  public:
86  HtmlInterfaceServer(std::string pathToInterfaceJs = "../interface.js",
87  bool autorun = true);
89 
90  HtmlInterfaceServer &addParameter(Parameter &param,
91  std::string interfaceName = "");
92  HtmlInterfaceServer &addParameterServer(ParameterServer &paramServer,
93  std::string interfaceName = "");
94  HtmlInterfaceServer &addPresetServer(PresetServer &presetServer,
95  std::string interfaceName = "");
96 
97  HtmlInterfaceServer &operator<<(Parameter &param) {
98  return this->addParameter(param);
99  }
100  HtmlInterfaceServer &operator<<(ParameterServer &paramServer) {
101  return this->addParameterServer(paramServer);
102  }
103  HtmlInterfaceServer &operator<<(PresetServer &presetServer) {
104  return this->addPresetServer(presetServer);
105  }
106 
107  void runInterfaceJs(); // Runs interface.js. Call only if autorun set to
108  // false in the constructor
109 
110  private:
111  void writeHtmlFile(std::vector<Parameter *> parameters,
112  std::string interfaceName = "");
113  void writeHtmlFile(PresetServer &presetServer, std::string interfaceName = "",
114  int numPresets = -1);
115 
116  std::string mRootPath;
117  std::string mNodeJsPath;
118 #ifndef AL_WINDOWS
119  pid_t mPid;
120 #else
121  // TODO: Windows equivalent
122 #endif
123  int p_stdin[2], p_stdout[2];
124 
125  int mInterfaceSendPort; // Interface.js sends OSC on this port
126  int mInterfaceRecvPort; // Interface.js receives OSC on this port
127 
128  std::vector<Parameter *> mParameters;
129 };
130 
131 } // namespace al
132 
133 #endif // INCLUDE_AL_HTMLINTERFACESERVER_HPP
The HtmlInterfaceServer class runs an interface.simpleserver.js server and builds the html interface ...
The Parameter class.
The ParameterServer class creates an OSC server to receive parameter values.
Definition: al_App.hpp:23