├── .gitignore ├── LICENSE ├── Qt Creator ├── ExampleHeat │ ├── ExampleHeat.pro │ └── ExampleHeat.pro.user ├── ExampleSin │ ├── ExampleSin.pro │ └── ExampleSin.pro.user └── GateY │ ├── GateY.pro │ └── GateY.pro.user ├── README.md ├── TODO ├── Visual Studio 2012 ├── ExampleHeat │ ├── ExampleHeat.vcxproj │ └── ExampleHeat.vcxproj.filters ├── ExampleSin │ ├── ExampleSin.vcxproj │ └── ExampleSin.vcxproj.filters ├── ExampleSpaceship │ ├── ExampleSpaceship.vcxproj │ └── ExampleSpaceship.vcxproj.filters ├── GateY │ ├── GateY.vcxproj │ └── GateY.vcxproj.filters ├── VC Solution.sln └── libwebsockets │ ├── libwebsockets.vcxproj │ └── libwebsockets.vcxproj.filters ├── Visual Studio 2013 ├── ExampleBrownianMotion │ ├── ExampleBrownianMotion.vcxproj │ └── ExampleBrownianMotion.vcxproj.filters ├── ExampleHeat │ ├── ExampleHeat.vcxproj │ └── ExampleHeat.vcxproj.filters ├── ExampleSin │ ├── ExampleSin.vcxproj │ └── ExampleSin.vcxproj.filters ├── ExampleSpaceship │ ├── ExampleSpaceship.vcxproj │ └── ExampleSpaceship.vcxproj.filters ├── GateY │ ├── GateY.vcxproj │ └── GateY.vcxproj.filters ├── VC Solution.sln └── libwebsockets │ ├── libwebsockets.vcxproj │ └── libwebsockets.vcxproj.filters ├── Xcode ├── ExampleHeat │ └── ExampleHeat.xcodeproj │ │ └── project.pbxproj ├── ExampleSin │ └── ExampleSin.xcodeproj │ │ └── project.pbxproj ├── ExampleSpaceship │ └── ExampleSpaceship.xcodeproj │ │ └── project.pbxproj └── GateY │ └── GateY.xcodeproj │ └── project.pbxproj ├── combine.py ├── examples ├── brownian motion │ └── main.cpp ├── heat │ └── main.cpp ├── sin │ └── main.cpp └── spaceship │ └── main.cpp ├── external ├── jsoncpp │ ├── AUTHORS │ ├── LICENSE │ ├── NEWS.txt │ ├── README.md │ ├── include │ │ └── json │ │ │ ├── assertions.h │ │ │ ├── autolink.h │ │ │ ├── config.h │ │ │ ├── features.h │ │ │ ├── forwards.h │ │ │ ├── json.h │ │ │ ├── reader.h │ │ │ ├── value.h │ │ │ ├── version.h │ │ │ └── writer.h │ ├── src │ │ └── lib_json │ │ │ ├── json_batchallocator.h │ │ │ ├── json_internalarray.inl │ │ │ ├── json_internalmap.inl │ │ │ ├── json_reader.cpp │ │ │ ├── json_tool.h │ │ │ ├── json_value.cpp │ │ │ ├── json_valueiterator.inl │ │ │ ├── json_writer.cpp │ │ │ └── version.h.in │ └── version └── libwebsockets │ ├── LICENSE │ ├── README │ ├── README.build │ ├── README.coding │ ├── README.test-apps │ ├── Readme gateY │ └── src │ ├── base64-decode.cpp │ ├── context.cpp │ ├── handshake.cpp │ ├── libwebsockets.cpp │ ├── libwebsockets.h │ ├── lws-plat-unix.cpp │ ├── lws-plat-win.cpp │ ├── lws_config.h │ ├── main.cpp │ ├── output.cpp │ ├── parsers.cpp │ ├── platforms.h │ ├── pollfd.cpp │ ├── private-libwebsockets.h │ ├── server-handshake.cpp │ ├── server.cpp │ ├── service.cpp │ └── sha-1.cpp ├── gatey.cpp ├── gatey.hpp ├── images ├── browser screenshot.png ├── chrome_256x256.png ├── firefox_256x256.png ├── internet-explorer_256x256.png ├── native screenshot.png ├── safari_256x256.png ├── spaceship.png └── spaceship.svg ├── js ├── .idea │ ├── .name │ ├── encodings.xml │ ├── js.iml │ ├── misc.xml │ ├── modules.xml │ ├── scopes │ │ └── scope_settings.xml │ └── vcs.xml ├── brownian_motion.html ├── gateY.js ├── heatmap_d3.html ├── heatmap_highcharts.html ├── sin_graph.html ├── sin_text.html └── spaceship_canvas.html └── src ├── GateY.cpp ├── GateY.hpp ├── Log.cpp ├── Log.hpp ├── Serialize.cpp ├── Serialize.hpp ├── Variable.hpp ├── WebSocketQueue.cpp ├── WebSocketQueue.hpp ├── json.cpp ├── json.hpp ├── libwebsockets.cpp ├── libwebsockets.h └── main.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | [Dd]ebug*/ 2 | [Rr]elease*/ 3 | *.sdf 4 | *.suo 5 | build*/ 6 | js/.idea/workspace.xml 7 | 8 | #Xcode 9 | .DS_Store 10 | build/ 11 | *.pbxuser 12 | !default.pbxuser 13 | *.mode1v3 14 | !default.mode1v3 15 | *.mode2v3 16 | !default.mode2v3 17 | *.perspectivev3 18 | !default.perspectivev3 19 | *.xcworkspace 20 | !default.xcworkspace 21 | xcuserdata 22 | profile 23 | *.moved-aside 24 | DerivedData 25 | Visual Studio 2013/external/ 26 | Visual Studio 2012/external/ 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | gatey.cpp is basically the code of 3 libraries concatenated into 1 file. It 2 | contains libwebsockets (LGPL with static link license) jsoncpp (MIT license) 3 | and my own code libgatey (MIT license) 4 | 5 | ============================================================================= 6 | 7 | The MIT License (MIT) 8 | 9 | Copyright (c) 2014 Tobias Neukom 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in all 19 | copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 | SOFTWARE. -------------------------------------------------------------------------------- /Qt Creator/ExampleHeat/ExampleHeat.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | CONFIG += console 3 | CONFIG -= app_bundle 4 | CONFIG -= qt 5 | CONFIG += c++11 6 | 7 | LIBS += -lws2_32 8 | 9 | SOURCES += \ 10 | ../../examples/heat/main.cpp \ 11 | ../../gatey.cpp 12 | 13 | HEADERS += \ 14 | ../../gatey.hpp 15 | 16 | -------------------------------------------------------------------------------- /Qt Creator/ExampleSin/ExampleSin.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | CONFIG += console 3 | CONFIG -= app_bundle 4 | CONFIG -= qt 5 | CONFIG += c++11 6 | 7 | LIBS += -lws2_32 8 | 9 | SOURCES += \ 10 | ../../examples/sin/main.cpp \ 11 | ../../gatey.cpp 12 | 13 | HEADERS += \ 14 | ../../gatey.hpp 15 | 16 | -------------------------------------------------------------------------------- /Qt Creator/GateY/GateY.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | CONFIG += console 3 | CONFIG -= app_bundle 4 | CONFIG -= qt 5 | CONFIG += c++11 6 | 7 | LIBS += -lws2_32 8 | 9 | SOURCES += \ 10 | ../../src/GateY.cpp \ 11 | ../../src/json.cpp \ 12 | ../../src/libwebsockets.cpp \ 13 | ../../src/Log.cpp \ 14 | ../../src/main.cpp \ 15 | ../../src/Serialize.cpp \ 16 | ../../src/WebSocketQueue.cpp 17 | 18 | HEADERS += \ 19 | ../../src/GateY.hpp \ 20 | ../../src/json.hpp \ 21 | ../../src/libwebsockets.h \ 22 | ../../src/Log.hpp \ 23 | ../../src/Serialize.hpp \ 24 | ../../src/Variable.hpp \ 25 | ../../src/WebSocketQueue.hpp 26 | 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Native and js screenshots](images/spaceship.png) 2 | 3 | What is it for? 4 | --------------- 5 | 6 | Use a web browser to easily visualize data from your C++ program and control it’s behaviour. libgateY allows you to add variables shared between the native C++ code and the javascript code. Here's an example: 7 | 8 | ##### C++ 9 | ```c++ 10 | gatey::global = std::make_shared(); 11 | 12 | std::tuple position(300.0f, 300.0f); 13 | gatey::WriteVariable> gPosition("position"); 14 | gatey::ReadVariable gDt("dt", 0.01f); 15 | 16 | std::mt19937 gen; 17 | std::normal_distribution normal(0, 1); 18 | 19 | while (true) { 20 | std::get<0>(position) += gDt.get() * normal(gen); 21 | std::get<1>(position) += gDt.get() * normal(gen); 22 | gPosition.set(position); 23 | std::this_thread::sleep_for(std::chrono::milliseconds(20)); 24 | } 25 | ``` 26 | 27 | ##### Javascirpt 28 | ```javascript 29 | $(document).ready(function() { 30 | gatey.global = new gatey.GateY('ws://127.0.0.1:9000'); 31 | 32 | var gDt = new gatey.WriteVariable('dt'); 33 | var gPosition = new gatey.ReadVariable('position', [0, 0]); 34 | 35 | $('#slider_dt').slider({ 36 | min: 0, max: 100, value: 1, 37 | slide: function() { gDt.set($("#slider_dt").slider("value") / 10); } 38 | }); 39 | 40 | var ctx = document.getElementById('particle_trace').getContext('2d'); 41 | gPosition.onChange = function(position) { 42 | ctx.fillRect(position[0] - 2, position[1] - 2, 4, 4); 43 | }; 44 | }); 45 | ``` 46 | 47 | Who is it for? 48 | -------------- 49 | 50 | + You have a console application and want to visualize some data it’s producing at runtime. 51 | + You have a game and don’t want to write an ingame gui to control it’s behaviour. 52 | + You found a bug and need to graph the value of a variable to get a better understanding of the faulty behaviour. 53 | 54 | What does it do? 55 | ---------------- 56 | 57 | LibGateY helps you send data structures over WebSockets from your C++ program to the web browser and the other way. It can send and receive a large amount of C++ standard types by default. For example `std::map>` will automatically be converted to a JSON object of the form `{ key0: [x, y, z], key1: [x, y, z] }` The serialization machinery can be extended to support your own types. 58 | 59 | How do I use it? 60 | ---------------- 61 | 62 | LibGateY tries to be as simple to deploy as possible, so it consists of only one .hpp and one .cpp file. It doesn’t have any dependecies. Just copy it into your project. 63 | 64 | Serialization 65 | ------------- 66 | To send data structures from C++ to JS libGateY uses JSON. It can serialize the following types by default: int, float, double, char, std::string and std::vector, std::map, std::array for any type T that is serializable. Here's an example of a custom type serializer: 67 | 68 | ```C++ 69 | struct Vec2 { 70 | float x, y; 71 | }; 72 | 73 | namespace gatey { namespace serialize { 74 | //Serialize as std::tuple 75 | 76 | void write(Vec2 const& value, Json::Value& jValue, Info info) { 77 | write(std::make_tuple(value.x, value.y), jValue, info); 78 | } 79 | 80 | void read(Json::Value const& jValue, Vec2& value, Info info) { 81 | std::tuple pair; 82 | read(jValue, pair, info); 83 | return Vec2(std::get<0>(pair), std::get<1>(pair)); 84 | } 85 | }} 86 | ``` 87 | 88 | Spaceship example 89 | ----------------- 90 | 91 | ##### C++ 92 | ```C++ 93 | gatey::global = std::make_shared(); 94 | 95 | SDL_Init(SDL_INIT_EVERYTHING); 96 | SDL_Window *win = SDL_CreateWindow("Spaceship", 50, 50, 250, 250, SDL_WINDOW_SHOWN); 97 | SDL_Renderer *renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED); 98 | 99 | Vec2 position(125, 125), velocity(0, 0); 100 | gatey::WriteVariable gPosition("position"), gVelocity("velocity"); 101 | gatey::ReadVariable gPower("power", 20.0f); 102 | 103 | 104 | float dt = 1.0f / 30; 105 | 106 | std::vector trail; 107 | 108 | while (true){ 109 | double tStart = time(); 110 | 111 | SDL_Event e; 112 | while (SDL_PollEvent(&e)) { 113 | if (e.type == SDL_QUIT) 114 | return 0; 115 | } 116 | 117 | Vec2 acceleration(0, 0); 118 | Uint8 const* keyboard = SDL_GetKeyboardState(nullptr); 119 | if(keyboard[SDL_SCANCODE_LEFT]) acceleration += Vec2(-1, 0); 120 | if(keyboard[SDL_SCANCODE_RIGHT]) acceleration += Vec2(1, 0); 121 | if(keyboard[SDL_SCANCODE_UP]) acceleration += Vec2(0, -1); 122 | if(keyboard[SDL_SCANCODE_DOWN]) acceleration += Vec2(0, 1); 123 | 124 | velocity += dt * gPower.get() * acceleration; 125 | position += dt * velocity; 126 | 127 | gVelocity.set(velocity); 128 | gPosition.set(position); 129 | 130 | SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); //black 131 | SDL_RenderClear(renderer); 132 | 133 | SDL_Rect rect = { (int)position.x - 5, (int)position.y - 5, 10, 10 }; 134 | SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); //white 135 | SDL_RenderFillRect(renderer, &rect); 136 | 137 | SDL_RenderPresent(renderer); 138 | 139 | double tEnd = time(); 140 | int tDeltaInMs = (int)(1000.0 * (tEnd - tStart)); 141 | SDL_Delay(std::max(30 - tDeltaInMs, 0)); 142 | } 143 | ``` 144 | 145 | ##### Javascript 146 | ```JavaScript 147 | var gPosition = new gatey.ReadVariable('position', 0); 148 | var gVelocity = new gatey.ReadVariable('velocity', 0); 149 | var gPower = new gatey.WriteVariable('power'); 150 | 151 | //Create a slider to control spaceship acceleration 152 | function slideUpdate() { 153 | gPower.set($("#slider_a").slider("value")); 154 | } 155 | 156 | $(function() { 157 | $('#slider_a').slider({ 158 | min: 0, max: 100, value: 20, 159 | slide: slideUpdate, change: slideUpdate 160 | }); 161 | }); 162 | 163 | //Draw the spaceship trajectory 164 | var canvas = document.getElementById('spaceship_trace'); 165 | var ctx = canvas.getContext('2d'); 166 | 167 | var lastPos = undefined; 168 | gPosition.onChange = function(newPos) { 169 | if(lastPos) { 170 | ctx.beginPath(); 171 | ctx.moveTo(lastPos[0], lastPos[1]); 172 | ctx.lineTo(newPos[0], newPos[1]); 173 | ctx.stroke(); 174 | 175 | $('#position').html(JSON.stringify(newPos)); 176 | } 177 | 178 | lastPos = newPos; 179 | }; 180 | ``` 181 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | - fix issues on disconnect 2 | - replace libwebsockets with server from gamedevwebtools? 3 | Has better license, C++ smaller, but probably less well tested 4 | - rename openSendGate to publish openReceiveGate to subscribe(string name) 5 | - c++ adl problem: function serialise is only looked for in the namespace where the first 6 | argument lives (for example std for serialize(std::vector, JsonValue). 7 | Change JsonValue to gatey::JsonHolder (rename to gatey::Json) is better anyway 8 | - Handle SIGPIPE (on OS X at least) -------------------------------------------------------------------------------- /Visual Studio 2012/ExampleHeat/ExampleHeat.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {70867EA3-43B0-4124-B406-C868F676BCC7} 15 | Win32Proj 16 | ExampleHeat 17 | 18 | 19 | 20 | Application 21 | true 22 | v110 23 | Unicode 24 | 25 | 26 | Application 27 | false 28 | v110 29 | true 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | true 44 | 45 | 46 | false 47 | 48 | 49 | 50 | 51 | 52 | Level3 53 | Disabled 54 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 55 | 56 | 57 | Console 58 | true 59 | 60 | 61 | 62 | 63 | Level3 64 | 65 | 66 | MaxSpeed 67 | true 68 | true 69 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 70 | 71 | 72 | Console 73 | true 74 | true 75 | true 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /Visual Studio 2012/ExampleHeat/ExampleHeat.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | 26 | 27 | Header Files 28 | 29 | 30 | -------------------------------------------------------------------------------- /Visual Studio 2012/ExampleSin/ExampleSin.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {B828D083-7889-46CA-9979-C0F49B76C6CE} 15 | Win32Proj 16 | ExampleSin 17 | 18 | 19 | 20 | Application 21 | true 22 | v110 23 | Unicode 24 | 25 | 26 | Application 27 | false 28 | v110 29 | true 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | true 44 | 45 | 46 | false 47 | 48 | 49 | 50 | 51 | 52 | Level3 53 | Disabled 54 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 55 | 56 | 57 | Console 58 | true 59 | 60 | 61 | 62 | 63 | Level3 64 | 65 | 66 | MaxSpeed 67 | true 68 | true 69 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 70 | 71 | 72 | Console 73 | true 74 | true 75 | true 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /Visual Studio 2012/ExampleSin/ExampleSin.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | 26 | 27 | Header Files 28 | 29 | 30 | -------------------------------------------------------------------------------- /Visual Studio 2012/ExampleSpaceship/ExampleSpaceship.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | {3E651902-431A-491C-A628-1C8CD3CCC01A} 22 | Win32Proj 23 | ExampleSpaceship 24 | 25 | 26 | 27 | Application 28 | true 29 | v110 30 | Unicode 31 | 32 | 33 | Application 34 | false 35 | v110 36 | true 37 | Unicode 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 5af420dd 50 | 51 | 52 | true 53 | 54 | 55 | false 56 | 57 | 58 | 59 | 60 | 61 | Level3 62 | Disabled 63 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 64 | $(SolutionDir)\external\SDL2-2.0.3\include;%(AdditionalIncludeDirectories) 65 | 66 | 67 | Console 68 | true 69 | $(SolutionDir)\external\SDL2-2.0.3\lib\x86;%(AdditionalLibraryDirectories) 70 | SDL2main.lib;SDL2.lib;%(AdditionalDependencies) 71 | 72 | 73 | 74 | 75 | Level3 76 | 77 | 78 | MaxSpeed 79 | true 80 | true 81 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 82 | $(SolutionDir)\external\SDL2-2.0.3\include;%(AdditionalIncludeDirectories) 83 | 84 | 85 | Console 86 | true 87 | true 88 | true 89 | $(SolutionDir)\external\SDL2-2.0.3\lib\x86;%(AdditionalLibraryDirectories) 90 | SDL2main.lib;SDL2.lib;%(AdditionalDependencies) 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /Visual Studio 2012/ExampleSpaceship/ExampleSpaceship.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | 26 | 27 | Header Files 28 | 29 | 30 | -------------------------------------------------------------------------------- /Visual Studio 2012/GateY/GateY.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {3CF4190F-57C4-4338-8F98-1838868526FB} 15 | Win32Proj 16 | GateY 17 | 18 | 19 | 20 | Application 21 | true 22 | v110 23 | Unicode 24 | 25 | 26 | Application 27 | false 28 | v110 29 | true 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | true 44 | 45 | 46 | false 47 | 48 | 49 | 50 | 51 | 52 | Level3 53 | Disabled 54 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 55 | 56 | 57 | Console 58 | true 59 | 60 | 61 | 62 | 63 | Level3 64 | 65 | 66 | MaxSpeed 67 | true 68 | true 69 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 70 | 71 | 72 | Console 73 | true 74 | true 75 | true 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /Visual Studio 2012/GateY/GateY.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | 41 | 42 | Header Files 43 | 44 | 45 | Header Files 46 | 47 | 48 | Header Files 49 | 50 | 51 | Header Files 52 | 53 | 54 | Header Files 55 | 56 | 57 | Header Files 58 | 59 | 60 | Header Files 61 | 62 | 63 | -------------------------------------------------------------------------------- /Visual Studio 2012/VC Solution.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30501.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GateY", "GateY\GateY.vcxproj", "{3CF4190F-57C4-4338-8F98-1838868526FB}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ExampleSin", "ExampleSin\ExampleSin.vcxproj", "{B828D083-7889-46CA-9979-C0F49B76C6CE}" 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ExampleHeat", "ExampleHeat\ExampleHeat.vcxproj", "{70867EA3-43B0-4124-B406-C868F676BCC7}" 11 | EndProject 12 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libwebsockets", "libwebsockets\libwebsockets.vcxproj", "{89DA975F-9C5A-4B4C-B9BE-9C77F9A3D4B2}" 13 | EndProject 14 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ExampleSpaceship", "ExampleSpaceship\ExampleSpaceship.vcxproj", "{3E651902-431A-491C-A628-1C8CD3CCC01A}" 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Debug|Win32 = Debug|Win32 19 | Release|Win32 = Release|Win32 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {3CF4190F-57C4-4338-8F98-1838868526FB}.Debug|Win32.ActiveCfg = Debug|Win32 23 | {3CF4190F-57C4-4338-8F98-1838868526FB}.Debug|Win32.Build.0 = Debug|Win32 24 | {3CF4190F-57C4-4338-8F98-1838868526FB}.Release|Win32.ActiveCfg = Release|Win32 25 | {3CF4190F-57C4-4338-8F98-1838868526FB}.Release|Win32.Build.0 = Release|Win32 26 | {B828D083-7889-46CA-9979-C0F49B76C6CE}.Debug|Win32.ActiveCfg = Debug|Win32 27 | {B828D083-7889-46CA-9979-C0F49B76C6CE}.Debug|Win32.Build.0 = Debug|Win32 28 | {B828D083-7889-46CA-9979-C0F49B76C6CE}.Release|Win32.ActiveCfg = Release|Win32 29 | {B828D083-7889-46CA-9979-C0F49B76C6CE}.Release|Win32.Build.0 = Release|Win32 30 | {70867EA3-43B0-4124-B406-C868F676BCC7}.Debug|Win32.ActiveCfg = Debug|Win32 31 | {70867EA3-43B0-4124-B406-C868F676BCC7}.Debug|Win32.Build.0 = Debug|Win32 32 | {70867EA3-43B0-4124-B406-C868F676BCC7}.Release|Win32.ActiveCfg = Release|Win32 33 | {70867EA3-43B0-4124-B406-C868F676BCC7}.Release|Win32.Build.0 = Release|Win32 34 | {89DA975F-9C5A-4B4C-B9BE-9C77F9A3D4B2}.Debug|Win32.ActiveCfg = Debug|Win32 35 | {89DA975F-9C5A-4B4C-B9BE-9C77F9A3D4B2}.Debug|Win32.Build.0 = Debug|Win32 36 | {89DA975F-9C5A-4B4C-B9BE-9C77F9A3D4B2}.Release|Win32.ActiveCfg = Release|Win32 37 | {89DA975F-9C5A-4B4C-B9BE-9C77F9A3D4B2}.Release|Win32.Build.0 = Release|Win32 38 | {3E651902-431A-491C-A628-1C8CD3CCC01A}.Debug|Win32.ActiveCfg = Debug|Win32 39 | {3E651902-431A-491C-A628-1C8CD3CCC01A}.Debug|Win32.Build.0 = Debug|Win32 40 | {3E651902-431A-491C-A628-1C8CD3CCC01A}.Release|Win32.ActiveCfg = Release|Win32 41 | {3E651902-431A-491C-A628-1C8CD3CCC01A}.Release|Win32.Build.0 = Release|Win32 42 | EndGlobalSection 43 | GlobalSection(SolutionProperties) = preSolution 44 | HideSolutionNode = FALSE 45 | EndGlobalSection 46 | EndGlobal 47 | -------------------------------------------------------------------------------- /Visual Studio 2012/libwebsockets/libwebsockets.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {89DA975F-9C5A-4B4C-B9BE-9C77F9A3D4B2} 15 | Win32Proj 16 | libwebsockets 17 | 18 | 19 | 20 | Application 21 | true 22 | v110 23 | Unicode 24 | 25 | 26 | Application 27 | false 28 | v110 29 | true 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | true 44 | 45 | 46 | false 47 | 48 | 49 | 50 | 51 | 52 | Level3 53 | Disabled 54 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 55 | 56 | 57 | Console 58 | true 59 | 60 | 61 | 62 | 63 | Level3 64 | 65 | 66 | MaxSpeed 67 | true 68 | true 69 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 70 | 71 | 72 | Console 73 | true 74 | true 75 | true 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /Visual Studio 2012/libwebsockets/libwebsockets.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | Source Files 44 | 45 | 46 | Source Files 47 | 48 | 49 | Source Files 50 | 51 | 52 | Source Files 53 | 54 | 55 | Source Files 56 | 57 | 58 | Source Files 59 | 60 | 61 | 62 | 63 | Header Files 64 | 65 | 66 | Header Files 67 | 68 | 69 | Header Files 70 | 71 | 72 | Header Files 73 | 74 | 75 | -------------------------------------------------------------------------------- /Visual Studio 2013/ExampleBrownianMotion/ExampleBrownianMotion.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {985F63CF-A581-4459-85F7-C1CA412A5B33} 15 | Win32Proj 16 | ExampleBrownianMotion 17 | 18 | 19 | 20 | Application 21 | true 22 | v120 23 | Unicode 24 | 25 | 26 | Application 27 | false 28 | v120 29 | true 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | true 44 | 45 | 46 | false 47 | 48 | 49 | 50 | 51 | 52 | Level3 53 | Disabled 54 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 55 | 56 | 57 | Console 58 | true 59 | 60 | 61 | 62 | 63 | Level3 64 | 65 | 66 | MaxSpeed 67 | true 68 | true 69 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 70 | 71 | 72 | Console 73 | true 74 | true 75 | true 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /Visual Studio 2013/ExampleBrownianMotion/ExampleBrownianMotion.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | 26 | 27 | Header Files 28 | 29 | 30 | -------------------------------------------------------------------------------- /Visual Studio 2013/ExampleHeat/ExampleHeat.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {70867EA3-43B0-4124-B406-C868F676BCC7} 15 | Win32Proj 16 | ExampleHeat 17 | 18 | 19 | 20 | Application 21 | true 22 | v120 23 | Unicode 24 | 25 | 26 | Application 27 | false 28 | v120 29 | true 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | true 44 | 45 | 46 | false 47 | 48 | 49 | 50 | 51 | 52 | Level3 53 | Disabled 54 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 55 | 56 | 57 | Console 58 | true 59 | 60 | 61 | 62 | 63 | Level3 64 | 65 | 66 | MaxSpeed 67 | true 68 | true 69 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 70 | 71 | 72 | Console 73 | true 74 | true 75 | true 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /Visual Studio 2013/ExampleHeat/ExampleHeat.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | 26 | 27 | Header Files 28 | 29 | 30 | -------------------------------------------------------------------------------- /Visual Studio 2013/ExampleSin/ExampleSin.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {B828D083-7889-46CA-9979-C0F49B76C6CE} 15 | Win32Proj 16 | ExampleSin 17 | 18 | 19 | 20 | Application 21 | true 22 | v120 23 | Unicode 24 | 25 | 26 | Application 27 | false 28 | v120 29 | true 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | true 44 | 45 | 46 | false 47 | 48 | 49 | 50 | 51 | 52 | Level3 53 | Disabled 54 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 55 | 56 | 57 | Console 58 | true 59 | 60 | 61 | 62 | 63 | Level3 64 | 65 | 66 | MaxSpeed 67 | true 68 | true 69 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 70 | 71 | 72 | Console 73 | true 74 | true 75 | true 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /Visual Studio 2013/ExampleSin/ExampleSin.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | 26 | 27 | Header Files 28 | 29 | 30 | -------------------------------------------------------------------------------- /Visual Studio 2013/ExampleSpaceship/ExampleSpaceship.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | {3E651902-431A-491C-A628-1C8CD3CCC01A} 22 | Win32Proj 23 | ExampleSpaceship 24 | 25 | 26 | 27 | Application 28 | true 29 | v120 30 | Unicode 31 | 32 | 33 | Application 34 | false 35 | v120 36 | true 37 | Unicode 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 5af420dd 50 | 51 | 52 | true 53 | 54 | 55 | false 56 | 57 | 58 | 59 | 60 | 61 | Level3 62 | Disabled 63 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 64 | $(SolutionDir)\external\SDL2-2.0.3\include;%(AdditionalIncludeDirectories) 65 | 66 | 67 | Console 68 | true 69 | $(SolutionDir)\external\SDL2-2.0.3\lib\x86;%(AdditionalLibraryDirectories) 70 | SDL2main.lib;SDL2.lib;%(AdditionalDependencies) 71 | 72 | 73 | 74 | 75 | Level3 76 | 77 | 78 | MaxSpeed 79 | true 80 | true 81 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 82 | $(SolutionDir)\external\SDL2-2.0.3\include;%(AdditionalIncludeDirectories) 83 | 84 | 85 | Console 86 | true 87 | true 88 | true 89 | $(SolutionDir)\external\SDL2-2.0.3\lib\x86;%(AdditionalLibraryDirectories) 90 | SDL2main.lib;SDL2.lib;%(AdditionalDependencies) 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /Visual Studio 2013/ExampleSpaceship/ExampleSpaceship.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | 26 | 27 | Header Files 28 | 29 | 30 | -------------------------------------------------------------------------------- /Visual Studio 2013/GateY/GateY.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {3CF4190F-57C4-4338-8F98-1838868526FB} 15 | Win32Proj 16 | GateY 17 | 18 | 19 | 20 | Application 21 | true 22 | v120 23 | Unicode 24 | 25 | 26 | Application 27 | false 28 | v120 29 | true 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | true 44 | 45 | 46 | false 47 | 48 | 49 | 50 | 51 | 52 | Level3 53 | Disabled 54 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 55 | 56 | 57 | Console 58 | true 59 | 60 | 61 | 62 | 63 | Level3 64 | 65 | 66 | MaxSpeed 67 | true 68 | true 69 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 70 | 71 | 72 | Console 73 | true 74 | true 75 | true 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /Visual Studio 2013/GateY/GateY.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | 41 | 42 | Header Files 43 | 44 | 45 | Header Files 46 | 47 | 48 | Header Files 49 | 50 | 51 | Header Files 52 | 53 | 54 | Header Files 55 | 56 | 57 | Header Files 58 | 59 | 60 | Header Files 61 | 62 | 63 | -------------------------------------------------------------------------------- /Visual Studio 2013/VC Solution.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30501.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GateY", "GateY\GateY.vcxproj", "{3CF4190F-57C4-4338-8F98-1838868526FB}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ExampleSin", "ExampleSin\ExampleSin.vcxproj", "{B828D083-7889-46CA-9979-C0F49B76C6CE}" 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ExampleHeat", "ExampleHeat\ExampleHeat.vcxproj", "{70867EA3-43B0-4124-B406-C868F676BCC7}" 11 | EndProject 12 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libwebsockets", "libwebsockets\libwebsockets.vcxproj", "{89DA975F-9C5A-4B4C-B9BE-9C77F9A3D4B2}" 13 | EndProject 14 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ExampleSpaceship", "ExampleSpaceship\ExampleSpaceship.vcxproj", "{3E651902-431A-491C-A628-1C8CD3CCC01A}" 15 | EndProject 16 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ExampleBrownianMotion", "ExampleBrownianMotion\ExampleBrownianMotion.vcxproj", "{985F63CF-A581-4459-85F7-C1CA412A5B33}" 17 | EndProject 18 | Global 19 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 20 | Debug|Win32 = Debug|Win32 21 | Release|Win32 = Release|Win32 22 | EndGlobalSection 23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 24 | {3CF4190F-57C4-4338-8F98-1838868526FB}.Debug|Win32.ActiveCfg = Debug|Win32 25 | {3CF4190F-57C4-4338-8F98-1838868526FB}.Debug|Win32.Build.0 = Debug|Win32 26 | {3CF4190F-57C4-4338-8F98-1838868526FB}.Release|Win32.ActiveCfg = Release|Win32 27 | {3CF4190F-57C4-4338-8F98-1838868526FB}.Release|Win32.Build.0 = Release|Win32 28 | {B828D083-7889-46CA-9979-C0F49B76C6CE}.Debug|Win32.ActiveCfg = Debug|Win32 29 | {B828D083-7889-46CA-9979-C0F49B76C6CE}.Debug|Win32.Build.0 = Debug|Win32 30 | {B828D083-7889-46CA-9979-C0F49B76C6CE}.Release|Win32.ActiveCfg = Release|Win32 31 | {B828D083-7889-46CA-9979-C0F49B76C6CE}.Release|Win32.Build.0 = Release|Win32 32 | {70867EA3-43B0-4124-B406-C868F676BCC7}.Debug|Win32.ActiveCfg = Debug|Win32 33 | {70867EA3-43B0-4124-B406-C868F676BCC7}.Debug|Win32.Build.0 = Debug|Win32 34 | {70867EA3-43B0-4124-B406-C868F676BCC7}.Release|Win32.ActiveCfg = Release|Win32 35 | {70867EA3-43B0-4124-B406-C868F676BCC7}.Release|Win32.Build.0 = Release|Win32 36 | {89DA975F-9C5A-4B4C-B9BE-9C77F9A3D4B2}.Debug|Win32.ActiveCfg = Debug|Win32 37 | {89DA975F-9C5A-4B4C-B9BE-9C77F9A3D4B2}.Debug|Win32.Build.0 = Debug|Win32 38 | {89DA975F-9C5A-4B4C-B9BE-9C77F9A3D4B2}.Release|Win32.ActiveCfg = Release|Win32 39 | {89DA975F-9C5A-4B4C-B9BE-9C77F9A3D4B2}.Release|Win32.Build.0 = Release|Win32 40 | {3E651902-431A-491C-A628-1C8CD3CCC01A}.Debug|Win32.ActiveCfg = Debug|Win32 41 | {3E651902-431A-491C-A628-1C8CD3CCC01A}.Debug|Win32.Build.0 = Debug|Win32 42 | {3E651902-431A-491C-A628-1C8CD3CCC01A}.Release|Win32.ActiveCfg = Release|Win32 43 | {3E651902-431A-491C-A628-1C8CD3CCC01A}.Release|Win32.Build.0 = Release|Win32 44 | {985F63CF-A581-4459-85F7-C1CA412A5B33}.Debug|Win32.ActiveCfg = Debug|Win32 45 | {985F63CF-A581-4459-85F7-C1CA412A5B33}.Debug|Win32.Build.0 = Debug|Win32 46 | {985F63CF-A581-4459-85F7-C1CA412A5B33}.Release|Win32.ActiveCfg = Release|Win32 47 | {985F63CF-A581-4459-85F7-C1CA412A5B33}.Release|Win32.Build.0 = Release|Win32 48 | EndGlobalSection 49 | GlobalSection(SolutionProperties) = preSolution 50 | HideSolutionNode = FALSE 51 | EndGlobalSection 52 | EndGlobal 53 | -------------------------------------------------------------------------------- /Visual Studio 2013/libwebsockets/libwebsockets.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {89DA975F-9C5A-4B4C-B9BE-9C77F9A3D4B2} 15 | Win32Proj 16 | libwebsockets 17 | 18 | 19 | 20 | Application 21 | true 22 | v120 23 | Unicode 24 | 25 | 26 | Application 27 | false 28 | v120 29 | true 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | true 44 | 45 | 46 | false 47 | 48 | 49 | 50 | 51 | 52 | Level3 53 | Disabled 54 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 55 | 56 | 57 | Console 58 | true 59 | 60 | 61 | 62 | 63 | Level3 64 | 65 | 66 | MaxSpeed 67 | true 68 | true 69 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 70 | 71 | 72 | Console 73 | true 74 | true 75 | true 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /Visual Studio 2013/libwebsockets/libwebsockets.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | Source Files 44 | 45 | 46 | Source Files 47 | 48 | 49 | Source Files 50 | 51 | 52 | Source Files 53 | 54 | 55 | Source Files 56 | 57 | 58 | Source Files 59 | 60 | 61 | 62 | 63 | Header Files 64 | 65 | 66 | Header Files 67 | 68 | 69 | Header Files 70 | 71 | 72 | Header Files 73 | 74 | 75 | -------------------------------------------------------------------------------- /combine.py: -------------------------------------------------------------------------------- 1 | import os.path as path 2 | import itertools 3 | 4 | root = '' 5 | 6 | def load_file(filename): 7 | with open (filename, "r") as myfile: 8 | return myfile.read() 9 | 10 | def save_file(str, filename): 11 | with open(filename, "w") as myfile: 12 | myfile.write(str) 13 | 14 | def source(filename): 15 | filepath = path.join(root, filename) 16 | return [ 17 | '/***************************************************', 18 | ' * ' + filepath, 19 | ' ***************************************************/', 20 | '', 21 | load_file(filepath), 22 | ] 23 | 24 | # def save_source(str, filename): 25 | # save_file(str, path.join(root, filename)) 26 | 27 | def concat(ls): 28 | return list(itertools.chain(*ls)) 29 | 30 | def flatten(node): 31 | if isinstance(node, list): 32 | return [item for sub_ls in node for item in flatten(sub_ls)] 33 | return [node] 34 | 35 | def combine(ls): 36 | return "\n".join(flatten(ls)) 37 | 38 | # 39 | # jsoncpp 40 | # 41 | 42 | root = 'external/jsoncpp/' 43 | 44 | header = [ 45 | '/// Json-cpp amalgated header (http://jsoncpp.sourceforge.net/).', 46 | '#ifndef JSON_AMALGATED_H_INCLUDED', 47 | '# define JSON_AMALGATED_H_INCLUDED', 48 | '#define JSON_IS_AMALGAMATION', 49 | 50 | source('include/json/config.h'), 51 | source('include/json/forwards.h'), 52 | source('include/json/features.h'), 53 | source('include/json/value.h'), 54 | source('include/json/reader.h'), 55 | source('include/json/writer.h'), 56 | source('include/json/assertions.h'), 57 | 58 | '#endif //ifndef JSON_AMALGATED_H_INCLUDED', 59 | ] 60 | header_result = combine(header) 61 | save_file(header_result, 'src/json.hpp') 62 | 63 | 64 | cpp = [ 65 | '/// Json-cpp amalgated source (http://jsoncpp.sourceforge.net/).', 66 | 67 | '#ifndef GATEY_IS_AMALGAMATION', 68 | '#include "json.hpp"', 69 | '#endif', 70 | 71 | source('src/lib_json/json_tool.h'), 72 | source('src/lib_json/json_reader.cpp'), 73 | source('src/lib_json/json_batchallocator.h'), 74 | source('src/lib_json/json_valueiterator.inl'), 75 | source('src/lib_json/json_value.cpp'), 76 | source('src/lib_json/json_writer.cpp'), 77 | ] 78 | cpp_result = combine(cpp) 79 | save_file(cpp_result, 'src/json.cpp') 80 | 81 | # 82 | # libwebsockets 83 | # 84 | 85 | root = 'external/libwebsockets/' 86 | 87 | header = [ 88 | '/*', 89 | ' * libwebsockets amalgated header (http://jsoncpp.sourceforge.net/).', 90 | ' */', 91 | '', 92 | 93 | '#ifndef WEBSOCKET_AMALGATED_H_INCLUDED', 94 | '#define WEBSOCKET_AMALGATED_H_INCLUDED', 95 | '#define WEBSOCKET_IS_AMALGAMATION', 96 | 97 | source('src/libwebsockets.h'), 98 | 99 | '#endif //ifndef WEBSOCKET_AMALGATED_H_INCLUDED', 100 | ] 101 | header_result = combine(header) 102 | save_file(header_result, 'src/libwebsockets.h') 103 | 104 | cpp = [ 105 | '/*', 106 | ' * libwebsockets amalgated source (http://jsoncpp.sourceforge.net/).', 107 | ' */', 108 | '', 109 | 110 | source('src/lws_config.h'), 111 | source('src/platforms.h'), 112 | 113 | '#ifndef GATEY_IS_AMALGAMATION', 114 | '#include "libwebsockets.h"', 115 | '#endif', 116 | 117 | source('src/private-libwebsockets.h'), 118 | source('src/base64-decode.cpp'), 119 | source('src/context.cpp'), 120 | source('src/handshake.cpp'), 121 | source('src/libwebsockets.cpp'), 122 | source('src/lws-plat-win.cpp'), 123 | source('src/lws-plat-unix.cpp'), 124 | source('src/output.cpp'), 125 | source('src/parsers.cpp'), 126 | source('src/pollfd.cpp'), 127 | source('src/server.cpp'), 128 | source('src/server-handshake.cpp'), 129 | source('src/service.cpp'), 130 | source('src/sha-1.cpp'), 131 | ] 132 | cpp_result = combine(cpp) 133 | save_file(cpp_result, 'src/libwebsockets.cpp') 134 | 135 | # 136 | # libgatey 137 | # 138 | 139 | root = '' 140 | 141 | libwebsockets_note = [ 142 | '', 143 | '/* libwebsockets code', 144 | ' * Copyright (C) 2010-2013 Andy Green ', 145 | ' * Distributed under lesser GPL with static linking exception', 146 | ' */', 147 | '', 148 | ] 149 | 150 | gatey_note = [ 151 | '', 152 | '/* gateY code', 153 | ' * Copyright(C) 2014 Tobias Neukom ', 154 | ' * Distributed under MIT license', 155 | ' */', 156 | '', 157 | ] 158 | 159 | jsoncpp_note = [ 160 | '', 161 | '/* jsoncpp code', 162 | ' * Copyright 2007-2010 Baptiste Lepilleur', 163 | ' * Distributed under MIT license, or public domain if desired and', 164 | ' */', 165 | '', 166 | ] 167 | 168 | header = [ 169 | '// gatey amalgated header (http://jsoncpp.sourceforge.net/).', 170 | '#ifndef GATEY_AMALGATED_H_INCLUDED', 171 | '#define GATEY_AMALGATED_H_INCLUDED', 172 | '#define GATEY_IS_AMALGAMATION', 173 | 174 | jsoncpp_note, 175 | 176 | '#ifndef GATEY_USE_EXTERNAL_JSONCPP', 177 | source('src/json.hpp'), 178 | '#endif //GATEY_USE_EXTERNAL_JSONCPP', 179 | 180 | gatey_note, 181 | 182 | source('src/WebSocketQueue.hpp'), 183 | source('src/Serialize.hpp'), 184 | source('src/GateY.hpp'), 185 | source('src/Variable.hpp'), 186 | 187 | '#endif //ifndef GATEY_AMALGATED_H_INCLUDED', 188 | ] 189 | 190 | 191 | header_result = combine(header) 192 | save_file(header_result, 'gatey.hpp') 193 | 194 | 195 | 196 | cpp = [ 197 | '/*', 198 | ' * gatey amalgated source (http://jsoncpp.sourceforge.net/).', 199 | ' */', 200 | '', 201 | 202 | libwebsockets_note, 203 | 204 | source('src/libwebsockets.h'), 205 | 206 | gatey_note, 207 | 208 | '#include "gatey.hpp"', 209 | 210 | source('src/Log.hpp'), 211 | 212 | source('src/GateY.cpp'), 213 | source('src/Log.cpp'), 214 | source('src/Serialize.cpp'), 215 | source('src/WebSocketQueue.cpp'), 216 | 217 | jsoncpp_note, 218 | 219 | '#ifndef GATEY_USE_EXTERNAL_JSONCPP', 220 | source('src/json.cpp'), 221 | '#endif //GATEY_USE_EXTERNAL_JSONCPP', 222 | 223 | libwebsockets_note, 224 | 225 | source('src/libwebsockets.cpp'), 226 | ] 227 | cpp_result = combine(cpp) 228 | save_file(cpp_result, 'gatey.cpp') -------------------------------------------------------------------------------- /examples/brownian motion/main.cpp: -------------------------------------------------------------------------------- 1 | #include "../../gatey.hpp" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | /* 8 | * Compile together with ../../gatey.cpp 9 | * Windows need ws2_32.lib (Visual Studio will automatically add it because of #pragma comment(lib, "ws2_32.lib") 10 | */ 11 | 12 | int main() { 13 | gatey::global = std::make_shared(); 14 | 15 | std::tuple position(300.0f, 300.0f); 16 | gatey::WriteVariable> gPosition("position"); 17 | gatey::ReadVariable gDt("dt", 0.01f); 18 | 19 | std::mt19937 gen; 20 | std::normal_distribution normal(0, 1); 21 | 22 | while (true) { 23 | std::get<0>(position) += gDt.get() * normal(gen); 24 | std::get<1>(position) += gDt.get() * normal(gen); 25 | gPosition.set(position); 26 | std::this_thread::sleep_for(std::chrono::milliseconds(20)); 27 | } 28 | 29 | return 0; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /examples/heat/main.cpp: -------------------------------------------------------------------------------- 1 | #include "../../gatey.hpp" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | /* 8 | * Compile together with ../../gatey.cpp 9 | * Windows need ws2_32.lib (Visual Studio will automatically add it because of #pragma comment(lib, "ws2_32.lib") 10 | */ 11 | 12 | int main() { 13 | std::chrono::milliseconds dura(20); 14 | gatey::global = std::make_shared(); 15 | 16 | const std::size_t SIZE = 32; 17 | std::array, SIZE> field = { { 0.0 } }; 18 | std::tuple tuple; 19 | gatey::WriteVariable gField("field"); 20 | gatey::WriteVariable gTuple("tuple"); 21 | 22 | field[SIZE / 2][SIZE / 2] = 100000.0; 23 | double alpha = 1.0; 24 | double dt = 1.0 / 30; 25 | while (true) { 26 | std::cout << "Enter key to start heat equation" << std::endl; 27 | char c; 28 | std::cin >> c; 29 | 30 | tuple = std::make_tuple(1, std::string("Hello World")); 31 | gTuple.set(tuple); 32 | 33 | for (unsigned int step = 0; step < 100; ++step) { 34 | std::this_thread::sleep_for(dura); 35 | 36 | decltype(field) copy = { { 0.0 } }; 37 | for (std::size_t x = 1; x < SIZE - 1; ++x) { 38 | for (std::size_t y = 1; y < SIZE - 1; ++y) { 39 | //du/dt = alpha laplace u 40 | //du = dt * alpha laplace u 41 | //u' = u + dt * alpha laplace u 42 | double laplace = field[x - 1][y] + field[x + 1][y] + field[x][y - 1] + field[x][y + 1] - 4 * field[x][y]; 43 | copy[x][y] = field[x][y] + alpha * dt * laplace; 44 | } 45 | } 46 | field = copy; 47 | gField.set(field); 48 | } 49 | } 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | return 0; 58 | 59 | 60 | } 61 | 62 | -------------------------------------------------------------------------------- /examples/sin/main.cpp: -------------------------------------------------------------------------------- 1 | #include "../../gatey.hpp" 2 | #include 3 | #include 4 | #include 5 | 6 | /* 7 | * Compile together with ../../gatey.cpp 8 | * Windows need ws2_32.lib (Visual Studio will automatically add it because of #pragma comment(lib, "ws2_32.lib") 9 | */ 10 | 11 | int main() { 12 | std::chrono::milliseconds dura(20); 13 | gatey::global = std::make_shared(); 14 | 15 | gatey::WriteVariable> gF("y"); 16 | gatey::ReadVariable gDt("dt", 0.01f); 17 | gatey::ReadVariable gC("c", 1.0f); 18 | 19 | 20 | float time = 0.0f; 21 | while (true) { 22 | float y = gC.get() * std::sin(time); 23 | gF.set(std::make_pair(time, y)); 24 | time += gDt.get(); 25 | std::this_thread::sleep_for(dura); 26 | } 27 | 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /examples/spaceship/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #undef main //for VC 3 | 4 | #include "../../gatey.hpp" 5 | #include 6 | 7 | //TODO: Fix framereate (is fixed by vsync, but dependent on system) 8 | 9 | struct Vec2 { 10 | float x, y; 11 | 12 | Vec2(float x, float y) : x(x), y(y) {} 13 | }; 14 | 15 | Vec2 operator+(Vec2 const& l, Vec2 const& r) { 16 | return Vec2 (l.x + r.x, l.y + r.y); 17 | } 18 | 19 | Vec2& operator+=(Vec2& l, Vec2 const& r) { 20 | l = l + r; 21 | return l; 22 | } 23 | 24 | Vec2 operator*(float l, Vec2 const& r) { 25 | return Vec2(l * r.x, l * r.y); 26 | } 27 | 28 | namespace gatey { namespace serialize { 29 | void write(Vec2 const& value, Json::Value& jValue, Info info) { 30 | write(std::make_tuple(value.x, value.y), jValue, info); 31 | } 32 | }} 33 | 34 | double time() { 35 | return (double)SDL_GetPerformanceCounter() / (double)SDL_GetPerformanceFrequency(); 36 | } 37 | 38 | int main(int argc, const char * argv[]) 39 | { 40 | gatey::global = std::make_shared(); 41 | 42 | SDL_Init(SDL_INIT_EVERYTHING); 43 | SDL_Window *win = SDL_CreateWindow("Spaceship", 50, 50, 250, 250, SDL_WINDOW_SHOWN); 44 | SDL_Renderer *renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED); 45 | 46 | Vec2 position(125, 125), velocity(0, 0); 47 | gatey::WriteVariable gPosition("position"), gVelocity("velocity"); 48 | gatey::ReadVariable gPower("power", 20.0f); 49 | 50 | 51 | float dt = 1.0f / 30; 52 | 53 | std::vector trail; 54 | 55 | while (true){ 56 | double tStart = time(); 57 | 58 | SDL_Event e; 59 | while (SDL_PollEvent(&e)) { 60 | if (e.type == SDL_QUIT) 61 | return 0; 62 | } 63 | 64 | Vec2 acceleration(0, 0); 65 | Uint8 const* keyboard = SDL_GetKeyboardState(nullptr); 66 | if(keyboard[SDL_SCANCODE_LEFT]) acceleration += Vec2(-1, 0); 67 | if(keyboard[SDL_SCANCODE_RIGHT]) acceleration += Vec2(1, 0); 68 | if(keyboard[SDL_SCANCODE_UP]) acceleration += Vec2(0, -1); 69 | if(keyboard[SDL_SCANCODE_DOWN]) acceleration += Vec2(0, 1); 70 | 71 | velocity += dt * gPower.get() * acceleration; 72 | position += dt * velocity; 73 | 74 | gVelocity.set(velocity); 75 | gPosition.set(position); 76 | 77 | SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); //black 78 | SDL_RenderClear(renderer); 79 | 80 | SDL_Rect rect = { (int)position.x - 5, (int)position.y - 5, 10, 10 }; 81 | SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); //white 82 | SDL_RenderFillRect(renderer, &rect); 83 | 84 | SDL_RenderPresent(renderer); 85 | 86 | double tEnd = time(); 87 | int tDeltaInMs = (int)(1000.0 * (tEnd - tStart)); 88 | SDL_Delay(std::max(30 - tDeltaInMs, 0)); 89 | } 90 | 91 | return 0; 92 | } 93 | 94 | -------------------------------------------------------------------------------- /external/jsoncpp/AUTHORS: -------------------------------------------------------------------------------- 1 | Baptiste Lepilleur 2 | -------------------------------------------------------------------------------- /external/jsoncpp/LICENSE: -------------------------------------------------------------------------------- 1 | The JsonCpp library's source code, including accompanying documentation, 2 | tests and demonstration applications, are licensed under the following 3 | conditions... 4 | 5 | The author (Baptiste Lepilleur) explicitly disclaims copyright in all 6 | jurisdictions which recognize such a disclaimer. In such jurisdictions, 7 | this software is released into the Public Domain. 8 | 9 | In jurisdictions which do not recognize Public Domain property (e.g. Germany as of 10 | 2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur, and is 11 | released under the terms of the MIT License (see below). 12 | 13 | In jurisdictions which recognize Public Domain property, the user of this 14 | software may choose to accept it either as 1) Public Domain, 2) under the 15 | conditions of the MIT License (see below), or 3) under the terms of dual 16 | Public Domain/MIT License conditions described here, as they choose. 17 | 18 | The MIT License is about as close to Public Domain as a license can get, and is 19 | described in clear, concise terms at: 20 | 21 | http://en.wikipedia.org/wiki/MIT_License 22 | 23 | The full text of the MIT License follows: 24 | 25 | ======================================================================== 26 | Copyright (c) 2007-2010 Baptiste Lepilleur 27 | 28 | Permission is hereby granted, free of charge, to any person 29 | obtaining a copy of this software and associated documentation 30 | files (the "Software"), to deal in the Software without 31 | restriction, including without limitation the rights to use, copy, 32 | modify, merge, publish, distribute, sublicense, and/or sell copies 33 | of the Software, and to permit persons to whom the Software is 34 | furnished to do so, subject to the following conditions: 35 | 36 | The above copyright notice and this permission notice shall be 37 | included in all copies or substantial portions of the Software. 38 | 39 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 40 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 41 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 42 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 43 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 44 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 45 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 46 | SOFTWARE. 47 | ======================================================================== 48 | (END LICENSE TEXT) 49 | 50 | The MIT license is compatible with both the GPL and commercial 51 | software, affording one all of the rights of Public Domain with the 52 | minor nuisance of being required to keep the above copyright notice 53 | and license text in the source code. Note also that by accepting the 54 | Public Domain "license" you can re-license your copy using whatever 55 | license you like. 56 | -------------------------------------------------------------------------------- /external/jsoncpp/NEWS.txt: -------------------------------------------------------------------------------- 1 | New in SVN 2 | ---------- 3 | 4 | * Updated the type system's behavior, in order to better support backwards 5 | compatibility with code that was written before 64-bit integer support was 6 | introduced. Here's how it works now: 7 | 8 | * isInt, isInt64, isUInt, and isUInt64 return true if and only if the 9 | value can be exactly represented as that type. In particular, a value 10 | constructed with a double like 17.0 will now return true for all of 11 | these methods. 12 | 13 | * isDouble and isFloat now return true for all numeric values, since all 14 | numeric values can be converted to a double or float without 15 | truncation. Note however that the conversion may not be exact -- for 16 | example, doubles cannot exactly represent all integers above 2^53 + 1. 17 | 18 | * isBool, isNull, isString, isArray, and isObject now return true if and 19 | only if the value is of that type. 20 | 21 | * isConvertibleTo(fooValue) indicates that it is safe to call asFoo. 22 | (For each type foo, isFoo always implies isConvertibleTo(fooValue).) 23 | asFoo returns an approximate or exact representation as appropriate. 24 | For example, a double value may be truncated when asInt is called. 25 | 26 | * For backwards compatibility with old code, isConvertibleTo(intValue) 27 | may return false even if type() == intValue. This is because the value 28 | may have been constructed with a 64-bit integer larger than maxInt, 29 | and calling asInt() would cause an exception. If you're writing new 30 | code, use isInt64 to find out whether the value is exactly 31 | representable using an Int64, or asDouble() combined with minInt64 and 32 | maxInt64 to figure out whether it is approximately representable. 33 | 34 | * Value 35 | - Patch #10: BOOST_FOREACH compatibility. Made Json::iterator more 36 | standard compliant, added missing iterator_category and value_type 37 | typedefs (contribued by Robert A. Iannucci). 38 | 39 | * Compilation 40 | 41 | - New CMake based build system. Based in part on contribution from 42 | Igor Okulist and Damien Buhl (Patch #14). 43 | 44 | - New header json/version.h now contains version number macros 45 | (JSONCPP_VERSION_MAJOR, JSONCPP_VERSION_MINOR, JSONCPP_VERSION_PATCH 46 | and JSONCPP_VERSION_HEXA). 47 | 48 | - Patch #11: added missing JSON_API on some classes causing link issues 49 | when building as a dynamic library on Windows 50 | (contributed by Francis Bolduc). 51 | 52 | - Visual Studio DLL: suppressed warning "C4251: : 53 | needs to have dll-interface to be used by..." via pragma push/pop 54 | in json-cpp headers. 55 | 56 | - Added Travis CI intregration: https://travis-ci.org/blep/jsoncpp-mirror 57 | 58 | * Bug fixes 59 | - Patch #15: Copy constructor does not initialize allocated_ for stringValue 60 | (contributed by rmongia). 61 | 62 | - Patch #16: Missing field copy in Json::Value::iterator causing infinite 63 | loop when using experimental internal map (#define JSON_VALUE_USE_INTERNAL_MAP) 64 | (contributed by Ming-Lin Kao). 65 | 66 | 67 | New in JsonCpp 0.6.0: 68 | --------------------- 69 | 70 | * Compilation 71 | 72 | - LD_LIBRARY_PATH and LIBRARY_PATH environment variables are now 73 | propagated to the build environment as this is required for some 74 | compiler installation. 75 | 76 | - Added support for Microsoft Visual Studio 2008 (bug #2930462): 77 | The platform "msvc90" has been added. 78 | 79 | Notes: you need to setup the environment by running vcvars32.bat 80 | (e.g. MSVC 2008 command prompt in start menu) before running scons. 81 | 82 | - Added support for amalgamated source and header generation (a la sqlite). 83 | Refer to README.txt section "Generating amalgamated source and header" 84 | for detail. 85 | 86 | * Value 87 | 88 | - Removed experimental ValueAllocator, it caused static 89 | initialization/destruction order issues (bug #2934500). 90 | The DefaultValueAllocator has been inlined in code. 91 | 92 | - Added support for 64 bits integer: 93 | 94 | Types Json::Int64 and Json::UInt64 have been added. They are aliased 95 | to 64 bits integers on system that support them (based on __int64 on 96 | Microsoft Visual Studio platform, and long long on other platforms). 97 | 98 | Types Json::LargestInt and Json::LargestUInt have been added. They are 99 | aliased to the largest integer type supported: 100 | either Json::Int/Json::UInt or Json::Int64/Json::UInt64 respectively. 101 | 102 | Json::Value::asInt() and Json::Value::asUInt() still returns plain 103 | "int" based types, but asserts if an attempt is made to retrieve 104 | a 64 bits value that can not represented as the return type. 105 | 106 | Json::Value::asInt64() and Json::Value::asUInt64() have been added 107 | to obtain the 64 bits integer value. 108 | 109 | Json::Value::asLargestInt() and Json::Value::asLargestUInt() returns 110 | the integer as a LargestInt/LargestUInt respectively. Those functions 111 | functions are typically used when implementing writer. 112 | 113 | The reader attempts to read number as 64 bits integer, and fall back 114 | to reading a double if the number is not in the range of 64 bits 115 | integer. 116 | 117 | Warning: Json::Value::asInt() and Json::Value::asUInt() now returns 118 | long long. This changes break code that was passing the return value 119 | to *printf() function. 120 | 121 | Support for 64 bits integer can be disabled by defining the macro 122 | JSON_NO_INT64 (uncomment it in json/config.h for example), though 123 | it should have no impact on existing usage. 124 | 125 | - The type Json::ArrayIndex is used for indexes of a JSON value array. It 126 | is an unsigned int (typically 32 bits). 127 | 128 | - Array index can be passed as int to operator[], allowing use of literal: 129 | Json::Value array; 130 | array.append( 1234 ); 131 | int value = array[0].asInt(); // did not compile previously 132 | 133 | - Added float Json::Value::asFloat() to obtain a floating point value as a 134 | float (avoid lost of precision warning caused by used of asDouble() 135 | to initialize a float). 136 | 137 | * Reader 138 | 139 | - Renamed Reader::getFormatedErrorMessages() to getFormattedErrorMessages. 140 | Bug #3023708 (Formatted has 2 't'). The old member function is deprecated 141 | but still present for backward compatibility. 142 | 143 | * Tests 144 | 145 | - Added test to ensure that the escape sequence "\/" is corrected handled 146 | by the parser. 147 | 148 | * Bug fixes 149 | 150 | - Bug #3139677: JSON [1 2 3] was incorrectly parsed as [1, 3]. Error is now 151 | correctly detected. 152 | 153 | - Bug #3139678: stack buffer overflow when parsing a double with a 154 | length of 32 characters. 155 | 156 | - Fixed Value::operator <= implementation (had the semantic of operator >=). 157 | Found when adding unit tests for comparison operators. 158 | 159 | - Value::compare() is now const and has an actual implementation with 160 | unit tests. 161 | 162 | - Bug #2407932: strpbrk() can fail for NULL pointer. 163 | 164 | - Bug #3306345: Fixed minor typo in Path::resolve(). 165 | 166 | - Bug #3314841/#3306896: errors in amalgamate.py 167 | 168 | - Fixed some Coverity warnings and line-endings. 169 | 170 | * License 171 | 172 | - See file LICENSE for details. Basically JsonCpp is now licensed under 173 | MIT license, or public domain if desired and recognized in your jurisdiction. 174 | Thanks to Stephan G. Beal [http://wanderinghorse.net/home/stephan/]) who 175 | helped figuring out the solution to the public domain issue. 176 | -------------------------------------------------------------------------------- /external/jsoncpp/include/json/assertions.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED 7 | #define CPPTL_JSON_ASSERTIONS_H_INCLUDED 8 | 9 | #include 10 | 11 | #if !defined(JSON_IS_AMALGAMATION) 12 | #include "config.h" 13 | #endif // if !defined(JSON_IS_AMALGAMATION) 14 | 15 | #if JSON_USE_EXCEPTION 16 | #include 17 | #define JSON_ASSERT(condition) \ 18 | assert(condition); // @todo <= change this into an exception throw 19 | #define JSON_FAIL_MESSAGE(message) throw std::runtime_error(message); 20 | #else // JSON_USE_EXCEPTION 21 | #define JSON_ASSERT(condition) assert(condition); 22 | 23 | // The call to assert() will show the failure message in debug builds. In 24 | // release bugs we write to invalid memory in order to crash hard, so that a 25 | // debugger or crash reporter gets the chance to take over. We still call exit() 26 | // afterward in order to tell the compiler that this macro doesn't return. 27 | #define JSON_FAIL_MESSAGE(message) \ 28 | { \ 29 | assert(false &&message); \ 30 | strcpy(reinterpret_cast(666), message); \ 31 | exit(123); \ 32 | } 33 | 34 | #endif 35 | 36 | #define JSON_ASSERT_MESSAGE(condition, message) \ 37 | if (!(condition)) { \ 38 | JSON_FAIL_MESSAGE(message) \ 39 | } 40 | 41 | #endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED 42 | -------------------------------------------------------------------------------- /external/jsoncpp/include/json/autolink.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef JSON_AUTOLINK_H_INCLUDED 7 | #define JSON_AUTOLINK_H_INCLUDED 8 | 9 | #include "config.h" 10 | 11 | #ifdef JSON_IN_CPPTL 12 | #include 13 | #endif 14 | 15 | #if !defined(JSON_NO_AUTOLINK) && !defined(JSON_DLL_BUILD) && \ 16 | !defined(JSON_IN_CPPTL) 17 | #define CPPTL_AUTOLINK_NAME "json" 18 | #undef CPPTL_AUTOLINK_DLL 19 | #ifdef JSON_DLL 20 | #define CPPTL_AUTOLINK_DLL 21 | #endif 22 | #include "autolink.h" 23 | #endif 24 | 25 | #endif // JSON_AUTOLINK_H_INCLUDED 26 | -------------------------------------------------------------------------------- /external/jsoncpp/include/json/config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef JSON_CONFIG_H_INCLUDED 7 | #define JSON_CONFIG_H_INCLUDED 8 | 9 | /// If defined, indicates that json library is embedded in CppTL library. 10 | //# define JSON_IN_CPPTL 1 11 | 12 | /// If defined, indicates that json may leverage CppTL library 13 | //# define JSON_USE_CPPTL 1 14 | /// If defined, indicates that cpptl vector based map should be used instead of 15 | /// std::map 16 | /// as Value container. 17 | //# define JSON_USE_CPPTL_SMALLMAP 1 18 | /// If defined, indicates that Json specific container should be used 19 | /// (hash table & simple deque container with customizable allocator). 20 | /// THIS FEATURE IS STILL EXPERIMENTAL! There is know bugs: See #3177332 21 | //# define JSON_VALUE_USE_INTERNAL_MAP 1 22 | /// Force usage of standard new/malloc based allocator instead of memory pool 23 | /// based allocator. 24 | /// The memory pools allocator used optimization (initializing Value and 25 | /// ValueInternalLink 26 | /// as if it was a POD) that may cause some validation tool to report errors. 27 | /// Only has effects if JSON_VALUE_USE_INTERNAL_MAP is defined. 28 | //# define JSON_USE_SIMPLE_INTERNAL_ALLOCATOR 1 29 | 30 | // If non-zero, the library uses exceptions to report bad input instead of C 31 | // assertion macros. The default is to use exceptions. 32 | #ifndef JSON_USE_EXCEPTION 33 | #define JSON_USE_EXCEPTION 1 34 | #endif 35 | 36 | /// If defined, indicates that the source file is amalgated 37 | /// to prevent private header inclusion. 38 | /// Remarks: it is automatically defined in the generated amalgated header. 39 | // #define JSON_IS_AMALGAMATION 40 | 41 | #ifdef JSON_IN_CPPTL 42 | #include 43 | #ifndef JSON_USE_CPPTL 44 | #define JSON_USE_CPPTL 1 45 | #endif 46 | #endif 47 | 48 | #ifdef JSON_IN_CPPTL 49 | #define JSON_API CPPTL_API 50 | #elif defined(JSON_DLL_BUILD) 51 | #if defined(_MSC_VER) 52 | #define JSON_API __declspec(dllexport) 53 | #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING 54 | #endif // if defined(_MSC_VER) 55 | #elif defined(JSON_DLL) 56 | #if defined(_MSC_VER) 57 | #define JSON_API __declspec(dllimport) 58 | #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING 59 | #endif // if defined(_MSC_VER) 60 | #endif // ifdef JSON_IN_CPPTL 61 | #if !defined(JSON_API) 62 | #define JSON_API 63 | #endif 64 | 65 | // If JSON_NO_INT64 is defined, then Json only support C++ "int" type for 66 | // integer 67 | // Storages, and 64 bits integer support is disabled. 68 | // #define JSON_NO_INT64 1 69 | 70 | #if defined(_MSC_VER) && _MSC_VER <= 1200 // MSVC 6 71 | // Microsoft Visual Studio 6 only support conversion from __int64 to double 72 | // (no conversion from unsigned __int64). 73 | #define JSON_USE_INT64_DOUBLE_CONVERSION 1 74 | // Disable warning 4786 for VS6 caused by STL (identifier was truncated to '255' 75 | // characters in the debug information) 76 | // All projects I've ever seen with VS6 were using this globally (not bothering 77 | // with pragma push/pop). 78 | #pragma warning(disable : 4786) 79 | #endif // if defined(_MSC_VER) && _MSC_VER < 1200 // MSVC 6 80 | 81 | #if defined(_MSC_VER) && _MSC_VER >= 1500 // MSVC 2008 82 | /// Indicates that the following function is deprecated. 83 | #define JSONCPP_DEPRECATED(message) __declspec(deprecated(message)) 84 | #endif 85 | 86 | #if !defined(JSONCPP_DEPRECATED) 87 | #define JSONCPP_DEPRECATED(message) 88 | #endif // if !defined(JSONCPP_DEPRECATED) 89 | 90 | namespace Json { 91 | typedef int Int; 92 | typedef unsigned int UInt; 93 | #if defined(JSON_NO_INT64) 94 | typedef int LargestInt; 95 | typedef unsigned int LargestUInt; 96 | #undef JSON_HAS_INT64 97 | #else // if defined(JSON_NO_INT64) 98 | // For Microsoft Visual use specific types as long long is not supported 99 | #if defined(_MSC_VER) // Microsoft Visual Studio 100 | typedef __int64 Int64; 101 | typedef unsigned __int64 UInt64; 102 | #else // if defined(_MSC_VER) // Other platforms, use long long 103 | typedef long long int Int64; 104 | typedef unsigned long long int UInt64; 105 | #endif // if defined(_MSC_VER) 106 | typedef Int64 LargestInt; 107 | typedef UInt64 LargestUInt; 108 | #define JSON_HAS_INT64 109 | #endif // if defined(JSON_NO_INT64) 110 | } // end namespace Json 111 | 112 | #endif // JSON_CONFIG_H_INCLUDED 113 | -------------------------------------------------------------------------------- /external/jsoncpp/include/json/features.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef CPPTL_JSON_FEATURES_H_INCLUDED 7 | #define CPPTL_JSON_FEATURES_H_INCLUDED 8 | 9 | #if !defined(JSON_IS_AMALGAMATION) 10 | #include "forwards.h" 11 | #endif // if !defined(JSON_IS_AMALGAMATION) 12 | 13 | namespace Json { 14 | 15 | /** \brief Configuration passed to reader and writer. 16 | * This configuration object can be used to force the Reader or Writer 17 | * to behave in a standard conforming way. 18 | */ 19 | class JSON_API Features { 20 | public: 21 | /** \brief A configuration that allows all features and assumes all strings 22 | * are UTF-8. 23 | * - C & C++ comments are allowed 24 | * - Root object can be any JSON value 25 | * - Assumes Value strings are encoded in UTF-8 26 | */ 27 | static Features all(); 28 | 29 | /** \brief A configuration that is strictly compatible with the JSON 30 | * specification. 31 | * - Comments are forbidden. 32 | * - Root object must be either an array or an object value. 33 | * - Assumes Value strings are encoded in UTF-8 34 | */ 35 | static Features strictMode(); 36 | 37 | /** \brief Initialize the configuration like JsonConfig::allFeatures; 38 | */ 39 | Features(); 40 | 41 | /// \c true if comments are allowed. Default: \c true. 42 | bool allowComments_; 43 | 44 | /// \c true if root must be either an array or an object value. Default: \c 45 | /// false. 46 | bool strictRoot_; 47 | 48 | /// \c true if dropped null placeholders are allowed. Default: \c false. 49 | bool allowDroppedNullPlaceholders_; 50 | 51 | /// \c true if numeric object key are allowed. Default: \c false. 52 | bool allowNumericKeys_; 53 | }; 54 | 55 | } // namespace Json 56 | 57 | #endif // CPPTL_JSON_FEATURES_H_INCLUDED 58 | -------------------------------------------------------------------------------- /external/jsoncpp/include/json/forwards.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef JSON_FORWARDS_H_INCLUDED 7 | #define JSON_FORWARDS_H_INCLUDED 8 | 9 | #if !defined(JSON_IS_AMALGAMATION) 10 | #include "config.h" 11 | #endif // if !defined(JSON_IS_AMALGAMATION) 12 | 13 | namespace Json { 14 | 15 | // writer.h 16 | class FastWriter; 17 | class StyledWriter; 18 | 19 | // reader.h 20 | class Reader; 21 | 22 | // features.h 23 | class Features; 24 | 25 | // value.h 26 | typedef unsigned int ArrayIndex; 27 | class StaticString; 28 | class Path; 29 | class PathArgument; 30 | class Value; 31 | class ValueIteratorBase; 32 | class ValueIterator; 33 | class ValueConstIterator; 34 | #ifdef JSON_VALUE_USE_INTERNAL_MAP 35 | class ValueMapAllocator; 36 | class ValueInternalLink; 37 | class ValueInternalArray; 38 | class ValueInternalMap; 39 | #endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP 40 | 41 | } // namespace Json 42 | 43 | #endif // JSON_FORWARDS_H_INCLUDED 44 | -------------------------------------------------------------------------------- /external/jsoncpp/include/json/json.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef JSON_JSON_H_INCLUDED 7 | #define JSON_JSON_H_INCLUDED 8 | 9 | #include "autolink.h" 10 | #include "value.h" 11 | #include "reader.h" 12 | #include "writer.h" 13 | #include "features.h" 14 | 15 | #endif // JSON_JSON_H_INCLUDED 16 | -------------------------------------------------------------------------------- /external/jsoncpp/include/json/version.h: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is generated by CMake from "version" 2 | // and "version.h.in" files. 3 | // Run CMake configure step to update it. 4 | #ifndef JSON_VERSION_H_INCLUDED 5 | # define JSON_VERSION_H_INCLUDED 6 | 7 | # define JSONCPP_VERSION_STRING "0.6.0-dev" 8 | # define JSONCPP_VERSION_MAJOR 0 9 | # define JSONCPP_VERSION_MINOR 6 10 | # define JSONCPP_VERSION_PATCH 0 11 | # define JSONCPP_VERSION_QUALIFIER -dev 12 | # define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8)) 13 | 14 | #endif // JSON_VERSION_H_INCLUDED 15 | -------------------------------------------------------------------------------- /external/jsoncpp/include/json/writer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef JSON_WRITER_H_INCLUDED 7 | #define JSON_WRITER_H_INCLUDED 8 | 9 | #if !defined(JSON_IS_AMALGAMATION) 10 | #include "value.h" 11 | #endif // if !defined(JSON_IS_AMALGAMATION) 12 | #include 13 | #include 14 | 15 | // Disable warning C4251: : needs to have dll-interface to 16 | // be used by... 17 | #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) 18 | #pragma warning(push) 19 | #pragma warning(disable : 4251) 20 | #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) 21 | 22 | namespace Json { 23 | 24 | class Value; 25 | 26 | /** \brief Abstract class for writers. 27 | */ 28 | class JSON_API Writer { 29 | public: 30 | virtual ~Writer(); 31 | 32 | virtual std::string write(const Value &root) = 0; 33 | }; 34 | 35 | /** \brief Outputs a Value in JSON format 36 | *without formatting (not human friendly). 37 | * 38 | * The JSON document is written in a single line. It is not intended for 'human' 39 | *consumption, 40 | * but may be usefull to support feature such as RPC where bandwith is limited. 41 | * \sa Reader, Value 42 | */ 43 | class JSON_API FastWriter : public Writer { 44 | public: 45 | FastWriter(); 46 | virtual ~FastWriter() {} 47 | 48 | void enableYAMLCompatibility(); 49 | 50 | /** \brief Drop the "null" string from the writer's output for nullValues. 51 | * Strictly speaking, this is not valid JSON. But when the output is being 52 | * fed to a browser's Javascript, it makes for smaller output and the 53 | * browser can handle the output just fine. 54 | */ 55 | void dropNullPlaceholders(); 56 | 57 | public: // overridden from Writer 58 | virtual std::string write(const Value &root); 59 | 60 | private: 61 | void writeValue(const Value &value); 62 | 63 | std::string document_; 64 | bool yamlCompatiblityEnabled_; 65 | bool dropNullPlaceholders_; 66 | }; 67 | 68 | /** \brief Writes a Value in JSON format in a 69 | *human friendly way. 70 | * 71 | * The rules for line break and indent are as follow: 72 | * - Object value: 73 | * - if empty then print {} without indent and line break 74 | * - if not empty the print '{', line break & indent, print one value per 75 | *line 76 | * and then unindent and line break and print '}'. 77 | * - Array value: 78 | * - if empty then print [] without indent and line break 79 | * - if the array contains no object value, empty array or some other value 80 | *types, 81 | * and all the values fit on one lines, then print the array on a single 82 | *line. 83 | * - otherwise, it the values do not fit on one line, or the array contains 84 | * object or non empty array, then print one value per line. 85 | * 86 | * If the Value have comments then they are outputed according to their 87 | *#CommentPlacement. 88 | * 89 | * \sa Reader, Value, Value::setComment() 90 | */ 91 | class JSON_API StyledWriter : public Writer { 92 | public: 93 | StyledWriter(); 94 | virtual ~StyledWriter() {} 95 | 96 | public: // overridden from Writer 97 | /** \brief Serialize a Value in JSON format. 98 | * \param root Value to serialize. 99 | * \return String containing the JSON document that represents the root value. 100 | */ 101 | virtual std::string write(const Value &root); 102 | 103 | private: 104 | void writeValue(const Value &value); 105 | void writeArrayValue(const Value &value); 106 | bool isMultineArray(const Value &value); 107 | void pushValue(const std::string &value); 108 | void writeIndent(); 109 | void writeWithIndent(const std::string &value); 110 | void indent(); 111 | void unindent(); 112 | void writeCommentBeforeValue(const Value &root); 113 | void writeCommentAfterValueOnSameLine(const Value &root); 114 | bool hasCommentForValue(const Value &value); 115 | static std::string normalizeEOL(const std::string &text); 116 | 117 | typedef std::vector ChildValues; 118 | 119 | ChildValues childValues_; 120 | std::string document_; 121 | std::string indentString_; 122 | int rightMargin_; 123 | int indentSize_; 124 | bool addChildValues_; 125 | }; 126 | 127 | /** \brief Writes a Value in JSON format in a 128 | human friendly way, 129 | to a stream rather than to a string. 130 | * 131 | * The rules for line break and indent are as follow: 132 | * - Object value: 133 | * - if empty then print {} without indent and line break 134 | * - if not empty the print '{', line break & indent, print one value per 135 | line 136 | * and then unindent and line break and print '}'. 137 | * - Array value: 138 | * - if empty then print [] without indent and line break 139 | * - if the array contains no object value, empty array or some other value 140 | types, 141 | * and all the values fit on one lines, then print the array on a single 142 | line. 143 | * - otherwise, it the values do not fit on one line, or the array contains 144 | * object or non empty array, then print one value per line. 145 | * 146 | * If the Value have comments then they are outputed according to their 147 | #CommentPlacement. 148 | * 149 | * \param indentation Each level will be indented by this amount extra. 150 | * \sa Reader, Value, Value::setComment() 151 | */ 152 | class JSON_API StyledStreamWriter { 153 | public: 154 | StyledStreamWriter(std::string indentation = "\t"); 155 | ~StyledStreamWriter() {} 156 | 157 | public: 158 | /** \brief Serialize a Value in JSON format. 159 | * \param out Stream to write to. (Can be ostringstream, e.g.) 160 | * \param root Value to serialize. 161 | * \note There is no point in deriving from Writer, since write() should not 162 | * return a value. 163 | */ 164 | void write(std::ostream &out, const Value &root); 165 | 166 | private: 167 | void writeValue(const Value &value); 168 | void writeArrayValue(const Value &value); 169 | bool isMultineArray(const Value &value); 170 | void pushValue(const std::string &value); 171 | void writeIndent(); 172 | void writeWithIndent(const std::string &value); 173 | void indent(); 174 | void unindent(); 175 | void writeCommentBeforeValue(const Value &root); 176 | void writeCommentAfterValueOnSameLine(const Value &root); 177 | bool hasCommentForValue(const Value &value); 178 | static std::string normalizeEOL(const std::string &text); 179 | 180 | typedef std::vector ChildValues; 181 | 182 | ChildValues childValues_; 183 | std::ostream *document_; 184 | std::string indentString_; 185 | int rightMargin_; 186 | std::string indentation_; 187 | bool addChildValues_; 188 | }; 189 | 190 | #if defined(JSON_HAS_INT64) 191 | std::string JSON_API valueToString(Int value); 192 | std::string JSON_API valueToString(UInt value); 193 | #endif // if defined(JSON_HAS_INT64) 194 | std::string JSON_API valueToString(LargestInt value); 195 | std::string JSON_API valueToString(LargestUInt value); 196 | std::string JSON_API valueToString(double value); 197 | std::string JSON_API valueToString(bool value); 198 | std::string JSON_API valueToQuotedString(const char *value); 199 | 200 | /// \brief Output using the StyledStreamWriter. 201 | /// \see Json::operator>>() 202 | JSON_API std::ostream &operator<<(std::ostream &, const Value &root); 203 | 204 | } // namespace Json 205 | 206 | #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) 207 | #pragma warning(pop) 208 | #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) 209 | 210 | #endif // JSON_WRITER_H_INCLUDED 211 | -------------------------------------------------------------------------------- /external/jsoncpp/src/lib_json/json_batchallocator.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef JSONCPP_BATCHALLOCATOR_H_INCLUDED 7 | #define JSONCPP_BATCHALLOCATOR_H_INCLUDED 8 | 9 | #include 10 | #include 11 | 12 | #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION 13 | 14 | namespace Json { 15 | 16 | /* Fast memory allocator. 17 | * 18 | * This memory allocator allocates memory for a batch of object (specified by 19 | * the page size, the number of object in each page). 20 | * 21 | * It does not allow the destruction of a single object. All the allocated 22 | * objects can be destroyed at once. The memory can be either released or reused 23 | * for future allocation. 24 | * 25 | * The in-place new operator must be used to construct the object using the 26 | * pointer returned by allocate. 27 | */ 28 | template 29 | class BatchAllocator { 30 | public: 31 | BatchAllocator(unsigned int objectsPerPage = 255) 32 | : freeHead_(0), objectsPerPage_(objectsPerPage) { 33 | // printf( "Size: %d => %s\n", sizeof(AllocatedType), 34 | // typeid(AllocatedType).name() ); 35 | assert(sizeof(AllocatedType) * objectPerAllocation >= 36 | sizeof(AllocatedType *)); // We must be able to store a slist in the 37 | // object free space. 38 | assert(objectsPerPage >= 16); 39 | batches_ = allocateBatch(0); // allocated a dummy page 40 | currentBatch_ = batches_; 41 | } 42 | 43 | ~BatchAllocator() { 44 | for (BatchInfo *batch = batches_; batch;) { 45 | BatchInfo *nextBatch = batch->next_; 46 | free(batch); 47 | batch = nextBatch; 48 | } 49 | } 50 | 51 | /// allocate space for an array of objectPerAllocation object. 52 | /// @warning it is the responsability of the caller to call objects 53 | /// constructors. 54 | AllocatedType *allocate() { 55 | if (freeHead_) // returns node from free list. 56 | { 57 | AllocatedType *object = freeHead_; 58 | freeHead_ = *(AllocatedType **)object; 59 | return object; 60 | } 61 | if (currentBatch_->used_ == currentBatch_->end_) { 62 | currentBatch_ = currentBatch_->next_; 63 | while (currentBatch_ && currentBatch_->used_ == currentBatch_->end_) 64 | currentBatch_ = currentBatch_->next_; 65 | 66 | if (!currentBatch_) // no free batch found, allocate a new one 67 | { 68 | currentBatch_ = allocateBatch(objectsPerPage_); 69 | currentBatch_->next_ = batches_; // insert at the head of the list 70 | batches_ = currentBatch_; 71 | } 72 | } 73 | AllocatedType *allocated = currentBatch_->used_; 74 | currentBatch_->used_ += objectPerAllocation; 75 | return allocated; 76 | } 77 | 78 | /// Release the object. 79 | /// @warning it is the responsability of the caller to actually destruct the 80 | /// object. 81 | void release(AllocatedType *object) { 82 | assert(object != 0); 83 | *(AllocatedType **)object = freeHead_; 84 | freeHead_ = object; 85 | } 86 | 87 | private: 88 | struct BatchInfo { 89 | BatchInfo *next_; 90 | AllocatedType *used_; 91 | AllocatedType *end_; 92 | AllocatedType buffer_[objectPerAllocation]; 93 | }; 94 | 95 | // disabled copy constructor and assignement operator. 96 | BatchAllocator(const BatchAllocator &); 97 | void operator=(const BatchAllocator &); 98 | 99 | static BatchInfo *allocateBatch(unsigned int objectsPerPage) { 100 | const unsigned int mallocSize = 101 | sizeof(BatchInfo) - sizeof(AllocatedType) * objectPerAllocation + 102 | sizeof(AllocatedType) * objectPerAllocation * objectsPerPage; 103 | BatchInfo *batch = static_cast(malloc(mallocSize)); 104 | batch->next_ = 0; 105 | batch->used_ = batch->buffer_; 106 | batch->end_ = batch->buffer_ + objectsPerPage; 107 | return batch; 108 | } 109 | 110 | BatchInfo *batches_; 111 | BatchInfo *currentBatch_; 112 | /// Head of a single linked list within the allocated space of freeed object 113 | AllocatedType *freeHead_; 114 | unsigned int objectsPerPage_; 115 | }; 116 | 117 | } // namespace Json 118 | 119 | #endif // ifndef JSONCPP_DOC_INCLUDE_IMPLEMENTATION 120 | 121 | #endif // JSONCPP_BATCHALLOCATOR_H_INCLUDED 122 | // vim: et ts=2 sts=2 sw=2 tw=0 123 | -------------------------------------------------------------------------------- /external/jsoncpp/src/lib_json/json_tool.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef LIB_JSONCPP_JSON_TOOL_H_INCLUDED 7 | #define LIB_JSONCPP_JSON_TOOL_H_INCLUDED 8 | 9 | /* This header provides common string manipulation support, such as UTF-8, 10 | * portable conversion from/to string... 11 | * 12 | * It is an internal header that must not be exposed. 13 | */ 14 | 15 | namespace Json { 16 | 17 | /// Converts a unicode code-point to UTF-8. 18 | static inline std::string codePointToUTF8(unsigned int cp) { 19 | std::string result; 20 | 21 | // based on description from http://en.wikipedia.org/wiki/UTF-8 22 | 23 | if (cp <= 0x7f) { 24 | result.resize(1); 25 | result[0] = static_cast(cp); 26 | } else if (cp <= 0x7FF) { 27 | result.resize(2); 28 | result[1] = static_cast(0x80 | (0x3f & cp)); 29 | result[0] = static_cast(0xC0 | (0x1f & (cp >> 6))); 30 | } else if (cp <= 0xFFFF) { 31 | result.resize(3); 32 | result[2] = static_cast(0x80 | (0x3f & cp)); 33 | result[1] = 0x80 | static_cast((0x3f & (cp >> 6))); 34 | result[0] = 0xE0 | static_cast((0xf & (cp >> 12))); 35 | } else if (cp <= 0x10FFFF) { 36 | result.resize(4); 37 | result[3] = static_cast(0x80 | (0x3f & cp)); 38 | result[2] = static_cast(0x80 | (0x3f & (cp >> 6))); 39 | result[1] = static_cast(0x80 | (0x3f & (cp >> 12))); 40 | result[0] = static_cast(0xF0 | (0x7 & (cp >> 18))); 41 | } 42 | 43 | return result; 44 | } 45 | 46 | /// Returns true if ch is a control character (in range [0,32[). 47 | static inline bool isControlCharacter(char ch) { return ch > 0 && ch <= 0x1F; } 48 | 49 | enum { 50 | /// Constant that specify the size of the buffer that must be passed to 51 | /// uintToString. 52 | uintToStringBufferSize = 3 * sizeof(LargestUInt) + 1 53 | }; 54 | 55 | // Defines a char buffer for use with uintToString(). 56 | typedef char UIntToStringBuffer[uintToStringBufferSize]; 57 | 58 | /** Converts an unsigned integer to string. 59 | * @param value Unsigned interger to convert to string 60 | * @param current Input/Output string buffer. 61 | * Must have at least uintToStringBufferSize chars free. 62 | */ 63 | static inline void uintToString(LargestUInt value, char *¤t) { 64 | *--current = 0; 65 | do { 66 | *--current = char(value % 10) + '0'; 67 | value /= 10; 68 | } while (value != 0); 69 | } 70 | 71 | /** Change ',' to '.' everywhere in buffer. 72 | * 73 | * We had a sophisticated way, but it did not work in WinCE. 74 | * @see https://github.com/open-source-parsers/jsoncpp/pull/9 75 | */ 76 | static inline void fixNumericLocale(char* begin, char* end) { 77 | while (begin < end) { 78 | if (*begin == ',') { 79 | *begin = '.'; 80 | } 81 | ++begin; 82 | } 83 | } 84 | 85 | } // namespace Json { 86 | 87 | #endif // LIB_JSONCPP_JSON_TOOL_H_INCLUDED 88 | // vim: et ts=2 sts=2 sw=2 tw=0 89 | -------------------------------------------------------------------------------- /external/jsoncpp/src/lib_json/version.h.in: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is generated by CMake from "version" 2 | // and "version.h.in" files. 3 | // Run CMake configure step to update it. 4 | #ifndef JSON_VERSION_H_INCLUDED 5 | # define JSON_VERSION_H_INCLUDED 6 | 7 | # define JSONCPP_VERSION_STRING "@JSONCPP_VERSION@" 8 | # define JSONCPP_VERSION_MAJOR @JSONCPP_VERSION_MAJOR@ 9 | # define JSONCPP_VERSION_MINOR @JSONCPP_VERSION_MINOR@ 10 | # define JSONCPP_VERSION_PATCH @JSONCPP_VERSION_PATCH@ 11 | # define JSONCPP_VERSION_QUALIFIER @JSONCPP_VERSION_QUALIFIER@ 12 | # define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8)) 13 | 14 | #endif // JSON_VERSION_H_INCLUDED 15 | -------------------------------------------------------------------------------- /external/jsoncpp/version: -------------------------------------------------------------------------------- 1 | 0.6.0-dev -------------------------------------------------------------------------------- /external/libwebsockets/README: -------------------------------------------------------------------------------- 1 | This is the libwebsockets C library for lightweight websocket clients and 2 | servers. For support, visit 3 | 4 | http://libwebsockets.org 5 | 6 | and consider joining the project mailing list at 7 | 8 | http://ml.libwebsockets.org/mailman/listinfo/libwebsockets 9 | 10 | You can get the latest version of the library from git 11 | 12 | http://git.libwebsockets.org 13 | https://github.com/warmcat/libwebsockets 14 | 15 | for more information: 16 | 17 | README.build - information on building the library 18 | README.coding - information for writing code using the library 19 | README.test-apps - information about the test apps built with the library 20 | 21 | -------------------------------------------------------------------------------- /external/libwebsockets/README.build: -------------------------------------------------------------------------------- 1 | Introduction to CMake 2 | --------------------- 3 | 4 | CMake is a multi-platform build tool that can generate build files for many 5 | different target platforms. See more info at http://www.cmake.org 6 | 7 | CMake also allows/recommends you to do "out of source"-builds, that is, 8 | the build files are separated from your sources, so there is no need to 9 | create elaborate clean scripts to get a clean source tree, instead you 10 | simply remove your build directory. 11 | 12 | Libwebsockets has been tested to build successfully on the following platforms 13 | with SSL support (both OpenSSL/CyaSSL): 14 | 15 | - Windows 16 | - Linux (x86 and ARM) 17 | - OSX 18 | - NetBSD 19 | 20 | Building the library and test apps 21 | ---------------------------------- 22 | 23 | The project settings used by CMake to generate the platform specific build 24 | files is called CMakeLists.txt. CMake then uses one of its "Generators" to 25 | output a Visual Studio project or Make file for instance. To see a list of 26 | the available generators for your platform, simply run the "cmake" command. 27 | 28 | Note that by default OpenSSL will be linked, if you don't want SSL support 29 | see below on how to toggle compile options. 30 | 31 | Building on Unix: 32 | ----------------- 33 | 34 | 1. Install CMake 2.6 or greater: http://cmake.org/cmake/resources/software.html 35 | (Most Unix distributions comes with a packaged version also) 36 | 37 | 2. Install OpenSSL. 38 | 39 | 3. Generate the build files (default is Make files): 40 | 41 | cd /path/to/src 42 | mkdir build 43 | cd build 44 | cmake .. 45 | 46 | (NOTE: The build/ directory can have any name and be located anywhere 47 | on your filesystem, and that the argument ".." given to cmake is simply 48 | the source directory of libwebsockets containing the CMakeLists.txt 49 | project file. All examples in this file assumes you use "..") 50 | 51 | NOTE2 52 | A common option you may want to give is to set the install path, same 53 | as --prefix= with autotools. It defaults to /usr/local. 54 | You can do this by, eg 55 | 56 | cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/usr 57 | 58 | NOTE3 59 | On machines that want libraries in lib64, you can also add the 60 | following to the cmake line 61 | 62 | -DLIB_SUFFIX=64 63 | 64 | NOTE4 65 | If you are building against a non-distro OpenSSL (eg, in order to get 66 | access to ALPN support only in newer OpenSSL versions) the nice way to 67 | express that in one cmake command is eg, 68 | 69 | -DOPENSSL_ROOT_DIR=/usr/local/ssl 70 | 71 | 4. Finally you can build using the generated Makefile: 72 | 73 | make 74 | 75 | 76 | Quirk of cmake 77 | -------------- 78 | 79 | When changing cmake options, for some reason the only way to get it to see the 80 | changes sometimes is delete the contents of your build directory and do the 81 | cmake from scratch. 82 | 83 | 84 | Building on Windows (Visual Studio) 85 | ----------------------------------- 86 | 1. Install CMake 2.6 or greater: http://cmake.org/cmake/resources/software.html 87 | 88 | 2. Install OpenSSL binaries. http://www.openssl.org/related/binaries.html 89 | (Preferably in the default location to make it easier for CMake to find them) 90 | 91 | 3. Generate the Visual studio project by opening the Visual Studio cmd prompt: 92 | 93 | cd 94 | md build 95 | cd build 96 | cmake -G "Visual Studio 10" .. 97 | 98 | (NOTE: There is also a cmake-gui available on Windows if you prefer that) 99 | 100 | 4. Now you should have a generated Visual Studio Solution in your 101 | /build directory, which can be used to build. 102 | 103 | Setting compile options 104 | ----------------------- 105 | 106 | To set compile time flags you can either use one of the CMake gui applications 107 | or do it via command line. 108 | 109 | Command line 110 | ------------ 111 | To list avaialable options (ommit the H if you don't want the help text): 112 | 113 | cmake -LH .. 114 | 115 | Then to set an option and build (for example turn off SSL support): 116 | 117 | cmake -DLWS_WITH_SSL=0 .. 118 | or 119 | cmake -DLWS_WITH_SSL:BOOL=OFF .. 120 | 121 | Unix GUI 122 | -------- 123 | If you have a curses enabled build you simply type: 124 | (not all packages include this, my debian install does not for example). 125 | 126 | ccmake 127 | 128 | Windows GUI 129 | ----------- 130 | On windows CMake comes with a gui application: 131 | Start -> Programs -> CMake -> CMake (cmake-gui) 132 | 133 | CyaSSL replacement for OpenSSL 134 | ------------------------------ 135 | CyaSSL is a lightweight SSL library targeted at embedded system: 136 | http://www.yassl.com/yaSSL/Products-cyassl.html 137 | 138 | It contains a OpenSSL compatability layer which makes it possible to pretty 139 | much link to it instead of OpenSSL, giving a much smaller footprint. 140 | 141 | NOTE: cyassl needs to be compiled using the --enable-opensslextra flag for 142 | this to work. 143 | 144 | Compiling libwebsockets with CyaSSL 145 | ----------------------------------- 146 | 147 | cmake .. -DLWS_USE_CYASSL=1 \ 148 | -DLWS_CYASSL_INCLUDE_DIRS=/path/to/cyassl \ 149 | -DLWS_CYASSL_LIB=/path/to/cyassl/cyassl.a .. 150 | 151 | NOTE: On windows use the .lib file extension for LWS_CYASSL_LIB instead. 152 | 153 | Cross compiling 154 | --------------- 155 | To enable cross compiling libwebsockets using CMake you need to create 156 | a "Toolchain file" that you supply to CMake when generating your build files. 157 | CMake will then use the cross compilers and build paths specified in this file 158 | to look for dependencies and such. 159 | 160 | Libwebsockets includes an example toolchain file cross-arm-linux-gnueabihf.cmake 161 | you can use as a starting point. 162 | 163 | The commandline to configure for cross with this would look like 164 | 165 | cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/usr \ 166 | -DCMAKE_TOOLCHAIN_FILE=../cross-arm-linux-gnueabihf.cmake \ 167 | -DWITHOUT_EXTENSIONS=1 -DWITH_SSL=0 168 | 169 | The example shows how to build with no external cross lib dependencies, you 170 | need to proide the cross libraries otherwise. 171 | 172 | NOTE: start from an EMPTY build directory if you had a non-cross build in there 173 | before the settings will be cached and your changes ignored. 174 | 175 | Additional information on cross compilation with CMake: 176 | http://www.vtk.org/Wiki/CMake_Cross_Compiling 177 | 178 | 179 | Memory efficiency 180 | ----------------- 181 | 182 | Embedded server-only configuration without extensions (ie, no compression 183 | on websocket connections), but with full v13 websocket features and http 184 | server, built on ARM Cortex-A9: 185 | 186 | Update at 8dac94d (2013-02-18) 187 | 188 | ./configure --without-client --without-extensions --disable-debug --without-daemonize 189 | 190 | Context Creation, 1024 fd limit[2]: 16720 (includes 12 bytes per fd) 191 | Per-connection [3]: 72 bytes, +1328 during headers 192 | 193 | .text .rodata .data .bss 194 | 11512 2784 288 4 195 | 196 | This shows the impact of the major configuration with/without options at 197 | 13ba5bbc633ea962d46d using Ubuntu ARM on a PandaBoard ES. 198 | 199 | These are accounting for static allocations from the library elf, there are 200 | additional dynamic allocations via malloc. These are a bit old now but give 201 | the right idea for relative "expense" of features. 202 | 203 | Static allocations, ARM9 204 | .text .rodata .data .bss 205 | All (no without) 35024 9940 336 4104 206 | without client 25684 7144 336 4104 207 | without client, exts 21652 6288 288 4104 208 | without client, exts, debug[1] 19756 3768 288 4104 209 | without server 30304 8160 336 4104 210 | without server, exts 25382 7204 288 4104 211 | without server, exts, debug[1] 23712 4256 288 4104 212 | 213 | [1] --disable-debug only removes messages below lwsl_notice. Since that is 214 | the default logging level the impact is not noticable, error, warn and notice 215 | logs are all still there. 216 | 217 | [2] 1024 fd per process is the default limit (set by ulimit) in at least Fedora 218 | and Ubuntu. You can make significant savings tailoring this to actual expected 219 | peak fds, ie, at a limit of 20, context creation allocation reduces to 4432 + 220 | 240 = 4672) 221 | 222 | [3] known header content is freed after connection establishment 223 | 224 | 225 | 226 | -------------------------------------------------------------------------------- /external/libwebsockets/Readme gateY: -------------------------------------------------------------------------------- 1 | Forked from libwebsockets (licensed under LGPL with static link exception) 2 | Source and header files taken from a minimal build (without client, wihtout daemonize, no extensions) 3 | 4 | Changed includes to: 5 | 6 | #ifndef WEBSOCKET_IS_AMALGAMATION 7 | #include "..." 8 | #endif 9 | 10 | To allow single header / single cpp file script -------------------------------------------------------------------------------- /external/libwebsockets/src/base64-decode.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This code originally came from here 3 | * 4 | * http://base64.sourceforge.net/b64.c 5 | * 6 | * with the following license: 7 | * 8 | * LICENCE: Copyright (c) 2001 Bob Trower, Trantor Standard Systems Inc. 9 | * 10 | * Permission is hereby granted, free of charge, to any person 11 | * obtaining a copy of this software and associated 12 | * documentation files (the "Software"), to deal in the 13 | * Software without restriction, including without limitation 14 | * the rights to use, copy, modify, merge, publish, distribute, 15 | * sublicense, and/or sell copies of the Software, and to 16 | * permit persons to whom the Software is furnished to do so, 17 | * subject to the following conditions: 18 | * 19 | * The above copyright notice and this permission notice shall 20 | * be included in all copies or substantial portions of the 21 | * Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 24 | * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 25 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 26 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 27 | * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 28 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 29 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 30 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 | * 32 | * VERSION HISTORY: 33 | * Bob Trower 08/04/01 -- Create Version 0.00.00B 34 | * 35 | * I cleaned it up quite a bit to match the (linux kernel) style of the rest 36 | * of libwebsockets; this version is under LGPL2 like the rest of libwebsockets 37 | * since he explictly allows sublicensing, but I give the URL above so you can 38 | * get the original with Bob's super-liberal terms directly if you prefer. 39 | */ 40 | 41 | 42 | #include 43 | #include 44 | 45 | #ifndef WEBSOCKET_IS_AMALGAMATION 46 | #include "private-libwebsockets.h" 47 | #endif 48 | 49 | static const char encode[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 50 | "abcdefghijklmnopqrstuvwxyz0123456789+/"; 51 | static const char decode[] = "|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW" 52 | "$$$$$$XYZ[\\]^_`abcdefghijklmnopq"; 53 | 54 | LWS_VISIBLE int 55 | lws_b64_encode_string(const char *in, int in_len, char *out, int out_size) 56 | { 57 | unsigned char triple[3]; 58 | int i; 59 | int len; 60 | int line = 0; 61 | int done = 0; 62 | 63 | while (in_len) { 64 | len = 0; 65 | for (i = 0; i < 3; i++) { 66 | if (in_len) { 67 | triple[i] = *in++; 68 | len++; 69 | in_len--; 70 | } else 71 | triple[i] = 0; 72 | } 73 | if (!len) 74 | continue; 75 | 76 | if (done + 4 >= out_size) 77 | return -1; 78 | 79 | *out++ = encode[triple[0] >> 2]; 80 | *out++ = encode[((triple[0] & 0x03) << 4) | 81 | ((triple[1] & 0xf0) >> 4)]; 82 | *out++ = (len > 1 ? encode[((triple[1] & 0x0f) << 2) | 83 | ((triple[2] & 0xc0) >> 6)] : '='); 84 | *out++ = (len > 2 ? encode[triple[2] & 0x3f] : '='); 85 | 86 | done += 4; 87 | line += 4; 88 | } 89 | 90 | if (done + 1 >= out_size) 91 | return -1; 92 | 93 | *out++ = '\0'; 94 | 95 | return done; 96 | } 97 | -------------------------------------------------------------------------------- /external/libwebsockets/src/handshake.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libwebsockets - small server side websockets and web server implementation 3 | * 4 | * Copyright (C) 2010-2013 Andy Green 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation: 9 | * version 2.1 of the License. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef WEBSOCKET_IS_AMALGAMATION 23 | #include "private-libwebsockets.h" 24 | #endif 25 | 26 | /* 27 | * -04 of the protocol (actually the 80th version) has a radically different 28 | * handshake. The 04 spec gives the following idea 29 | * 30 | * The handshake from the client looks as follows: 31 | * 32 | * GET /chat HTTP/1.1 33 | * Host: server.example.com 34 | * Upgrade: websocket 35 | * Connection: Upgrade 36 | * Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== 37 | * Sec-WebSocket-Origin: http://example.com 38 | * Sec-WebSocket-Protocol: chat, superchat 39 | * Sec-WebSocket-Version: 4 40 | * 41 | * The handshake from the server looks as follows: 42 | * 43 | * HTTP/1.1 101 Switching Protocols 44 | * Upgrade: websocket 45 | * Connection: Upgrade 46 | * Sec-WebSocket-Accept: me89jWimTRKTWwrS3aRrL53YZSo= 47 | * Sec-WebSocket-Nonce: AQIDBAUGBwgJCgsMDQ4PEC== 48 | * Sec-WebSocket-Protocol: chat 49 | */ 50 | 51 | /* 52 | * We have to take care about parsing because the headers may be split 53 | * into multiple fragments. They may contain unknown headers with arbitrary 54 | * argument lengths. So, we parse using a single-character at a time state 55 | * machine that is completely independent of packet size. 56 | */ 57 | 58 | LWS_VISIBLE int 59 | libwebsocket_read(struct libwebsocket_context *context, 60 | struct libwebsocket *wsi, unsigned char *buf, size_t len) 61 | { 62 | size_t n; 63 | 64 | switch (wsi->state) { 65 | 66 | case WSI_STATE_HTTP_BODY: 67 | http_postbody: 68 | while (len--) { 69 | 70 | if (wsi->u.http.content_length_seen >= wsi->u.http.content_length) 71 | break; 72 | 73 | wsi->u.http.post_buffer[wsi->u.http.body_index++] = *buf++; 74 | wsi->u.http.content_length_seen++; 75 | n = wsi->protocol->rx_buffer_size; 76 | if (!n) 77 | n = LWS_MAX_SOCKET_IO_BUF; 78 | 79 | if (wsi->u.http.body_index != n && 80 | wsi->u.http.content_length_seen != wsi->u.http.content_length) 81 | continue; 82 | 83 | if (wsi->protocol->callback) { 84 | n = wsi->protocol->callback( 85 | wsi->protocol->owning_server, wsi, 86 | LWS_CALLBACK_HTTP_BODY, 87 | wsi->user_space, wsi->u.http.post_buffer, 88 | wsi->u.http.body_index); 89 | wsi->u.http.body_index = 0; 90 | if (n) 91 | goto bail; 92 | } 93 | 94 | if (wsi->u.http.content_length_seen == wsi->u.http.content_length) { 95 | /* he sent the content in time */ 96 | libwebsocket_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); 97 | n = wsi->protocol->callback( 98 | wsi->protocol->owning_server, wsi, 99 | LWS_CALLBACK_HTTP_BODY_COMPLETION, 100 | wsi->user_space, NULL, 0); 101 | wsi->u.http.body_index = 0; 102 | if (n) 103 | goto bail; 104 | } 105 | 106 | } 107 | 108 | /* 109 | * we need to spill here so everything is seen in the case 110 | * there is no content-length 111 | */ 112 | if (wsi->u.http.body_index && wsi->protocol->callback) { 113 | n = wsi->protocol->callback( 114 | wsi->protocol->owning_server, wsi, 115 | LWS_CALLBACK_HTTP_BODY, 116 | wsi->user_space, wsi->u.http.post_buffer, 117 | wsi->u.http.body_index); 118 | wsi->u.http.body_index = 0; 119 | if (n) 120 | goto bail; 121 | } 122 | break; 123 | 124 | case WSI_STATE_HTTP_ISSUING_FILE: 125 | case WSI_STATE_HTTP: 126 | wsi->state = WSI_STATE_HTTP_HEADERS; 127 | wsi->u.hdr.parser_state = WSI_TOKEN_NAME_PART; 128 | wsi->u.hdr.lextable_pos = 0; 129 | /* fallthru */ 130 | case WSI_STATE_HTTP_HEADERS: 131 | 132 | lwsl_parser("issuing %d bytes to parser\n", (int)len); 133 | 134 | if (lws_handshake_client(wsi, &buf, len)) 135 | goto bail; 136 | 137 | switch (lws_handshake_server(context, wsi, &buf, len)) { 138 | case 1: 139 | goto bail; 140 | case 2: 141 | goto http_postbody; 142 | } 143 | break; 144 | 145 | case WSI_STATE_AWAITING_CLOSE_ACK: 146 | case WSI_STATE_ESTABLISHED: 147 | if (lws_handshake_client(wsi, &buf, len)) 148 | goto bail; 149 | switch (wsi->mode) { 150 | case LWS_CONNMODE_WS_SERVING: 151 | 152 | if (libwebsocket_interpret_incoming_packet(wsi, buf, len) < 0) { 153 | lwsl_info("interpret_incoming_packet has bailed\n"); 154 | goto bail; 155 | } 156 | break; 157 | } 158 | break; 159 | default: 160 | lwsl_err("libwebsocket_read: Unhandled state\n"); 161 | break; 162 | } 163 | 164 | return 0; 165 | 166 | bail: 167 | lwsl_debug("closing connection at libwebsocket_read bail:\n"); 168 | 169 | libwebsocket_close_and_free_session(context, wsi, 170 | LWS_CLOSE_STATUS_NOSTATUS); 171 | 172 | return -1; 173 | } 174 | -------------------------------------------------------------------------------- /external/libwebsockets/src/lws_config.h: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define to 1 to use CyaSSL as a replacement for OpenSSL. 4 | * LWS_OPENSSL_SUPPORT needs to be set also for this to work. */ 5 | /* #undef USE_CYASSL */ 6 | 7 | /* The Libwebsocket version */ 8 | #define LWS_LIBRARY_VERSION "1.3" 9 | 10 | /* The current git commit hash that we're building from */ 11 | /* #undef LWS_BUILD_HASH */ 12 | 13 | /* Build with OpenSSL support */ 14 | /* #undef LWS_OPENSSL_SUPPORT */ 15 | 16 | /* The client should load and trust CA root certs it finds in the OS */ 17 | #define LWS_SSL_CLIENT_USE_OS_CA_CERTS 18 | 19 | /* Sets the path where the client certs should be installed. */ 20 | #define LWS_OPENSSL_CLIENT_CERTS "../share" 21 | 22 | /* Turn off websocket extensions */ 23 | #define LWS_NO_EXTENSIONS 24 | 25 | /* Enable libev io loop */ 26 | /* #undef LWS_USE_LIBEV */ 27 | 28 | /* Build with support for ipv6 */ 29 | /* #undef LWS_USE_IPV6 */ 30 | 31 | /* Build with support for HTTP2 */ 32 | /* #undef LWS_USE_HTTP2 */ 33 | 34 | /* Turn on latency measuring code */ 35 | /* #undef LWS_LATENCY */ 36 | 37 | /* Don't build the daemonizeation api */ 38 | #define LWS_NO_DAEMONIZE 39 | 40 | /* Build without server support */ 41 | /* #undef LWS_NO_SERVER */ 42 | 43 | /* Build without client support */ 44 | #define LWS_NO_CLIENT 45 | 46 | /* If we should compile with MinGW support */ 47 | /* #undef LWS_MINGW_SUPPORT */ 48 | 49 | /* Use the BSD getifaddrs that comes with libwebsocket, for uclibc support */ 50 | //#define LWS_BUILTIN_GETIFADDRS 51 | 52 | /* Define to 1 if you have the `bzero' function. */ 53 | /* #undef HAVE_BZERO */ 54 | 55 | /* Define to 1 if you have the header file. */ 56 | /* #undef HAVE_DLFCN_H */ 57 | 58 | /* Define to 1 if you have the header file. */ 59 | //#define HAVE_FCNTL_H 60 | 61 | /* Define to 1 if you have the `fork' function. */ 62 | /* #undef HAVE_FORK */ 63 | 64 | /* Define to 1 if you have the `getenv’ function. */ 65 | #define HAVE_GETENV 66 | 67 | /* Define to 1 if you have the header file. */ 68 | /* #undef HAVE_IN6ADDR_H */ 69 | 70 | /* Define to 1 if you have the header file. */ 71 | #define HAVE_INTTYPES_H 72 | 73 | /* Define to 1 if you have the `ssl' library (-lssl). */ 74 | /* #undef HAVE_LIBSSL */ 75 | 76 | /* Define to 1 if your system has a GNU libc compatible `malloc' function, and 77 | to 0 otherwise. */ 78 | #define HAVE_MALLOC 79 | 80 | /* Define to 1 if you have the header file. */ 81 | #define HAVE_MEMORY_H 82 | 83 | /* Define to 1 if you have the `memset' function. */ 84 | #define HAVE_MEMSET 85 | 86 | /* Define to 1 if you have the header file. */ 87 | /* #undef HAVE_NETINET_IN_H */ 88 | 89 | /* Define to 1 if your system has a GNU libc compatible `realloc' function, 90 | and to 0 otherwise. */ 91 | #define HAVE_REALLOC 92 | 93 | /* Define to 1 if you have the `socket' function. */ 94 | /* #undef HAVE_SOCKET */ 95 | 96 | /* Define to 1 if you have the header file. */ 97 | #define HAVE_STDINT_H 98 | 99 | /* Define to 1 if you have the header file. */ 100 | #define HAVE_STDLIB_H 101 | 102 | /* Define to 1 if you have the `strerror' function. */ 103 | #define HAVE_STRERROR 104 | 105 | /* Define to 1 if you have the header file. */ 106 | /* #undef HAVE_STRINGS_H */ 107 | 108 | /* Define to 1 if you have the header file. */ 109 | #define HAVE_STRING_H 110 | 111 | /* Define to 1 if you have the header file. */ 112 | /* #undef HAVE_SYS_PRCTL_H */ 113 | 114 | /* Define to 1 if you have the header file. */ 115 | /* #undef HAVE_SYS_SOCKET_H */ 116 | 117 | /* Define to 1 if you have the header file. */ 118 | #define HAVE_SYS_STAT_H 119 | 120 | /* Define to 1 if you have the header file. */ 121 | #define HAVE_SYS_TYPES_H 122 | 123 | /* Define to 1 if you have the header file. */ 124 | /* #undef HAVE_UNISTD_H */ 125 | 126 | /* Define to 1 if you have the `vfork' function. */ 127 | /* #undef HAVE_VFORK */ 128 | 129 | /* Define to 1 if you have the header file. */ 130 | /* #undef HAVE_VFORK_H */ 131 | 132 | /* Define to 1 if `fork' works. */ 133 | #define HAVE_WORKING_FORK 134 | 135 | /* Define to 1 if `vfork' works. */ 136 | #define HAVE_WORKING_VFORK 137 | 138 | /* Define to 1 if you have the header file. */ 139 | /* #undef HAVE_ZLIB_H */ 140 | 141 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 142 | */ 143 | #undef LT_OBJDIR // We're not using libtool 144 | 145 | /* Define to 1 if you have the ANSI C header files. */ 146 | #define STDC_HEADERS 147 | 148 | /* Version number of package */ 149 | #define VERSION 150 | 151 | /* Define to rpl_malloc if the replacement function should be used. */ 152 | /* #undef malloc */ 153 | 154 | /* Define to `int' if does not define. */ 155 | //#define pid_t 156 | 157 | /* Define to rpl_realloc if the replacement function should be used. */ 158 | /* #undef realloc */ 159 | 160 | /* Define to `unsigned int' if does not define. */ 161 | /* #undef size_t */ 162 | 163 | /* Define to 1 if we have getifaddrs */ 164 | /* #undef HAVE_GETIFADDRS */ 165 | 166 | /* Define as `fork' if `vfork' does not work. */ 167 | /* #undef vfork */ -------------------------------------------------------------------------------- /external/libwebsockets/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | return 0; 5 | } -------------------------------------------------------------------------------- /external/libwebsockets/src/platforms.h: -------------------------------------------------------------------------------- 1 | #if defined(_MSC_VER) 2 | #pragma comment(lib, "ws2_32.lib") 3 | #pragma warning(disable: 4996) //'strcpy': This function or variable may be unsafe. 4 | #pragma warning(disable: 4244) // '=' : conversion from 'unsigned short' to 'unsigned char', possible loss of data 5 | #pragma warning(disable: 4018) // '<' : signed/unsigned mismatch 6 | #endif 7 | 8 | #if defined(__GNUC__) 9 | #pragma GCC diagnostic ignored "-Wmissing-field-initializers" 10 | #endif -------------------------------------------------------------------------------- /external/libwebsockets/src/pollfd.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libwebsockets - small server side websockets and web server implementation 3 | * 4 | * Copyright (C) 2010-2014 Andy Green 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation: 9 | * version 2.1 of the License. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef WEBSOCKET_IS_AMALGAMATION 23 | #include "private-libwebsockets.h" 24 | #endif 25 | 26 | int 27 | insert_wsi_socket_into_fds(struct libwebsocket_context *context, 28 | struct libwebsocket *wsi) 29 | { 30 | struct libwebsocket_pollargs pa = { wsi->sock, LWS_POLLIN, 0 }; 31 | 32 | if (context->fds_count >= context->max_fds) { 33 | lwsl_err("Too many fds (%d)\n", context->max_fds); 34 | return 1; 35 | } 36 | 37 | if (wsi->sock >= context->max_fds) { 38 | lwsl_err("Socket fd %d is too high (%d)\n", 39 | wsi->sock, context->max_fds); 40 | return 1; 41 | } 42 | 43 | assert(wsi); 44 | assert(wsi->sock >= 0); 45 | 46 | lwsl_info("insert_wsi_socket_into_fds: wsi=%p, sock=%d, fds pos=%d\n", 47 | wsi, wsi->sock, context->fds_count); 48 | 49 | context->protocols[0].callback(context, wsi, 50 | LWS_CALLBACK_LOCK_POLL, 51 | wsi->user_space, (void *) &pa, 0); 52 | 53 | context->lws_lookup[wsi->sock] = wsi; 54 | wsi->position_in_fds_table = context->fds_count; 55 | context->fds[context->fds_count].fd = wsi->sock; 56 | context->fds[context->fds_count].events = LWS_POLLIN; 57 | 58 | lws_plat_insert_socket_into_fds(context, wsi); 59 | 60 | /* external POLL support via protocol 0 */ 61 | context->protocols[0].callback(context, wsi, 62 | LWS_CALLBACK_ADD_POLL_FD, 63 | wsi->user_space, (void *) &pa, 0); 64 | 65 | context->protocols[0].callback(context, wsi, 66 | LWS_CALLBACK_UNLOCK_POLL, 67 | wsi->user_space, (void *)&pa, 0); 68 | 69 | return 0; 70 | } 71 | 72 | int 73 | remove_wsi_socket_from_fds(struct libwebsocket_context *context, 74 | struct libwebsocket *wsi) 75 | { 76 | int m; 77 | struct libwebsocket_pollargs pa = { wsi->sock, 0, 0 }; 78 | 79 | lws_libev_io(context, wsi, LWS_EV_STOP | LWS_EV_READ | LWS_EV_WRITE); 80 | 81 | if (!--context->fds_count) { 82 | context->protocols[0].callback(context, wsi, 83 | LWS_CALLBACK_LOCK_POLL, 84 | wsi->user_space, (void *) &pa, 0); 85 | goto do_ext; 86 | } 87 | 88 | if (wsi->sock > context->max_fds) { 89 | lwsl_err("Socket fd %d too high (%d)\n", 90 | wsi->sock, context->max_fds); 91 | return 1; 92 | } 93 | 94 | lwsl_info("%s: wsi=%p, sock=%d, fds pos=%d\n", __func__, 95 | wsi, wsi->sock, wsi->position_in_fds_table); 96 | 97 | context->protocols[0].callback(context, wsi, 98 | LWS_CALLBACK_LOCK_POLL, 99 | wsi->user_space, (void *)&pa, 0); 100 | 101 | m = wsi->position_in_fds_table; /* replace the contents for this */ 102 | 103 | /* have the last guy take up the vacant slot */ 104 | context->fds[m] = context->fds[context->fds_count]; 105 | 106 | lws_plat_delete_socket_from_fds(context, wsi, m); 107 | 108 | /* 109 | * end guy's fds_lookup entry remains unchanged 110 | * (still same fd pointing to same wsi) 111 | */ 112 | /* end guy's "position in fds table" changed */ 113 | context->lws_lookup[context->fds[context->fds_count].fd]-> 114 | position_in_fds_table = m; 115 | /* deletion guy's lws_lookup entry needs nuking */ 116 | context->lws_lookup[wsi->sock] = NULL; 117 | /* removed wsi has no position any more */ 118 | wsi->position_in_fds_table = -1; 119 | 120 | do_ext: 121 | /* remove also from external POLL support via protocol 0 */ 122 | if (wsi->sock) { 123 | context->protocols[0].callback(context, wsi, 124 | LWS_CALLBACK_DEL_POLL_FD, wsi->user_space, 125 | (void *) &pa, 0); 126 | } 127 | context->protocols[0].callback(context, wsi, 128 | LWS_CALLBACK_UNLOCK_POLL, 129 | wsi->user_space, (void *) &pa, 0); 130 | return 0; 131 | } 132 | 133 | int 134 | lws_change_pollfd(struct libwebsocket *wsi, int _and, int _or) 135 | { 136 | struct libwebsocket_context *context = wsi->protocol->owning_server; 137 | int tid; 138 | int sampled_tid; 139 | struct libwebsocket_pollfd *pfd; 140 | struct libwebsocket_pollargs pa; 141 | 142 | pfd = &context->fds[wsi->position_in_fds_table]; 143 | pa.fd = wsi->sock; 144 | 145 | context->protocols[0].callback(context, wsi, 146 | LWS_CALLBACK_LOCK_POLL, wsi->user_space, (void *) &pa, 0); 147 | 148 | pa.prev_events = pfd->events; 149 | pa.events = pfd->events = (pfd->events & ~_and) | _or; 150 | 151 | context->protocols[0].callback(context, wsi, 152 | LWS_CALLBACK_CHANGE_MODE_POLL_FD, 153 | wsi->user_space, (void *) &pa, 0); 154 | 155 | /* 156 | * if we changed something in this pollfd... 157 | * ... and we're running in a different thread context 158 | * than the service thread... 159 | * ... and the service thread is waiting ... 160 | * then cancel it to force a restart with our changed events 161 | */ 162 | if (pa.prev_events != pa.events) { 163 | 164 | if (lws_plat_change_pollfd(context, wsi, pfd)) { 165 | lwsl_info("%s failed\n", __func__); 166 | return 1; 167 | } 168 | 169 | sampled_tid = context->service_tid; 170 | if (sampled_tid) { 171 | tid = context->protocols[0].callback(context, NULL, 172 | LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0); 173 | if (tid != sampled_tid) 174 | libwebsocket_cancel_service(context); 175 | } 176 | } 177 | 178 | context->protocols[0].callback(context, wsi, 179 | LWS_CALLBACK_UNLOCK_POLL, wsi->user_space, (void *) &pa, 0); 180 | 181 | return 0; 182 | } 183 | 184 | 185 | /** 186 | * libwebsocket_callback_on_writable() - Request a callback when this socket 187 | * becomes able to be written to without 188 | * blocking 189 | * 190 | * @context: libwebsockets context 191 | * @wsi: Websocket connection instance to get callback for 192 | */ 193 | 194 | LWS_VISIBLE int 195 | libwebsocket_callback_on_writable(struct libwebsocket_context *context, 196 | struct libwebsocket *wsi) 197 | { 198 | if (lws_ext_callback_for_each_active(wsi, 199 | LWS_EXT_CALLBACK_REQUEST_ON_WRITEABLE, NULL, 0)) 200 | return 1; 201 | 202 | if (wsi->position_in_fds_table < 0) { 203 | lwsl_err("%s: failed to find socket %d\n", __func__, wsi->sock); 204 | return -1; 205 | } 206 | 207 | if (lws_change_pollfd(wsi, 0, LWS_POLLOUT)) 208 | return -1; 209 | 210 | lws_libev_io(context, wsi, LWS_EV_START | LWS_EV_WRITE); 211 | 212 | return 1; 213 | } 214 | 215 | /** 216 | * libwebsocket_callback_on_writable_all_protocol() - Request a callback for 217 | * all connections using the given protocol when it 218 | * becomes possible to write to each socket without 219 | * blocking in turn. 220 | * 221 | * @protocol: Protocol whose connections will get callbacks 222 | */ 223 | 224 | LWS_VISIBLE int 225 | libwebsocket_callback_on_writable_all_protocol( 226 | const struct libwebsocket_protocols *protocol) 227 | { 228 | struct libwebsocket_context *context = protocol->owning_server; 229 | int n; 230 | struct libwebsocket *wsi; 231 | 232 | for (n = 0; n < context->fds_count; n++) { 233 | wsi = context->lws_lookup[context->fds[n].fd]; 234 | if (!wsi) 235 | continue; 236 | if (wsi->protocol == protocol) 237 | libwebsocket_callback_on_writable(context, wsi); 238 | } 239 | 240 | return 0; 241 | } 242 | -------------------------------------------------------------------------------- /images/browser screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tneukom/libgateY/6743b9c213c88773e28123344434ec6b839bc3eb/images/browser screenshot.png -------------------------------------------------------------------------------- /images/chrome_256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tneukom/libgateY/6743b9c213c88773e28123344434ec6b839bc3eb/images/chrome_256x256.png -------------------------------------------------------------------------------- /images/firefox_256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tneukom/libgateY/6743b9c213c88773e28123344434ec6b839bc3eb/images/firefox_256x256.png -------------------------------------------------------------------------------- /images/internet-explorer_256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tneukom/libgateY/6743b9c213c88773e28123344434ec6b839bc3eb/images/internet-explorer_256x256.png -------------------------------------------------------------------------------- /images/native screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tneukom/libgateY/6743b9c213c88773e28123344434ec6b839bc3eb/images/native screenshot.png -------------------------------------------------------------------------------- /images/safari_256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tneukom/libgateY/6743b9c213c88773e28123344434ec6b839bc3eb/images/safari_256x256.png -------------------------------------------------------------------------------- /images/spaceship.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tneukom/libgateY/6743b9c213c88773e28123344434ec6b839bc3eb/images/spaceship.png -------------------------------------------------------------------------------- /js/.idea/.name: -------------------------------------------------------------------------------- 1 | js -------------------------------------------------------------------------------- /js/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /js/.idea/js.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /js/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /js/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /js/.idea/scopes/scope_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /js/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /js/brownian_motion.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 30 |
31 | 32 | 33 | -------------------------------------------------------------------------------- /js/gateY.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by tneukom on 21.08.2014. 3 | */ 4 | "use strict"; 5 | 6 | //TODO: Don't auto connect! 7 | 8 | var gatey = {} 9 | 10 | gatey.GateY = function(address) { 11 | address = address || 'ws://127.0.0.1:9000'; 12 | this.websocket = new WebSocket(address, 'gatey'); 13 | this.websocket.binaryType = "arraybuffer"; 14 | this.connected = false; 15 | this.subscriptions = []; 16 | this.remoteSubscriptions = []; 17 | this.emitters = []; 18 | this.remoteEmitters = []; 19 | 20 | this.sendQueue = []; 21 | 22 | var self = this; 23 | 24 | this.websocket.onopen = function () { 25 | self.connected = true; 26 | console.log('gateY connected!'); 27 | 28 | self.sendCommand({cmd: 'init'}); 29 | self.processSendQueue(); 30 | }; 31 | 32 | this.websocket.onerror = function () { 33 | console.log('gateY connection error'); 34 | }; 35 | 36 | this.websocket.onclose = function() { 37 | console.log('gateY disconnected'); 38 | }; 39 | 40 | this.websocket.onmessage = function (socketMessage) { 41 | var message = JSON.parse(socketMessage.data); 42 | //console.log("receiving: ", JSON.stringify(message)); 43 | 44 | if(message.cmd == 'state') { 45 | self.remoteSubscriptions = message.subscriptions; 46 | self.remoteEmitters = message.emitters; 47 | } else if(message.cmd == 'message') { 48 | var found = gatey.firstWithProperties(self.subscriptions, { name: message.name }); 49 | 50 | if(found && found.value.onReceive) { 51 | found.value.onReceive(message.content); 52 | } 53 | } 54 | }; 55 | } 56 | 57 | gatey.hasProperties = function(obj, properties) { 58 | //TODO: direct properties? Use for of 59 | for(var property in properties) { 60 | if(!properties.hasOwnProperty(property)) { 61 | continue; 62 | } 63 | 64 | if(obj[property] != properties[property]) { 65 | return false; 66 | } 67 | } 68 | 69 | return true; 70 | } 71 | 72 | // Removes all elements with properties from ls, returns the removed items 73 | gatey.keepWithProperties = function(ls, properties) { 74 | var kept = []; 75 | var rest = []; 76 | //TODO: Use for.. of 77 | for(var obj in ls) { 78 | if(gatey.hasProperties(obj, properties)) { 79 | kept.push(obj); 80 | } else { 81 | rest.push(obj); 82 | } 83 | } 84 | 85 | return { kept: kept, rest: rest }; 86 | } 87 | 88 | gatey.removeWithProperties = function(ls, properties) { 89 | var keep = keepWithProperties(ls, properties); 90 | return { rest: keep.kept, removed: keep.rest }; 91 | } 92 | 93 | gatey.firstWithProperties = function(ls, properties) { 94 | //TODO: Use for..of 95 | for(var i = 0; i < ls.length; ++i) { 96 | var obj = ls[i]; 97 | if(gatey.hasProperties(obj, properties)) { 98 | return { index: i, value: obj }; 99 | } 100 | } 101 | 102 | return undefined; 103 | } 104 | 105 | gatey.GateY.prototype.processSendQueue = function() { 106 | if(!this.connected) 107 | return; 108 | 109 | for(var i = 0; i < this.sendQueue.length; ++i) { 110 | var cmd = this.sendQueue[i]; 111 | var cmdStr = JSON.stringify(cmd); 112 | console.log("sending: ", cmdStr); 113 | this.websocket.send(cmdStr); 114 | } 115 | 116 | this.sendQueue = []; 117 | }; 118 | 119 | gatey.GateY.prototype.sendCommand = function(command) { 120 | this.sendQueue.push(command); 121 | this.processSendQueue(); 122 | }; 123 | 124 | gatey.GateY.prototype.sendState = function() { 125 | var jSubscriptions = []; 126 | //TODO: map 127 | this.subscriptions.forEach(function(subscription) { 128 | var jSubscription = { 129 | name: subscription.name 130 | }; 131 | jSubscriptions.push(jSubscription); 132 | }); 133 | 134 | var jEmitters = []; 135 | this.emitters.forEach(function(emitter) { 136 | var jEmitter = { 137 | name: emitter.name 138 | } 139 | jEmitters.push(jEmitter); 140 | }); 141 | 142 | var cmd = {cmd: 'state', subscriptions: jSubscriptions, emitters: jEmitters }; 143 | this.sendCommand(cmd); 144 | 145 | }; 146 | 147 | gatey.GateY.prototype.send = function(name, content) { 148 | if(!gatey.firstWithProperties(this.emitters, { name: name })) { 149 | //TODO: improve message 150 | console.warn("not sending message because emitter " + name + " doesn't exist"); 151 | return; 152 | } 153 | 154 | if(!gatey.firstWithProperties(this.remoteSubscriptions, { name: name })) { 155 | //TODO: improve message 156 | console.warn("not sending message because remote subscription to " + name + " doesn't exist"); 157 | return; 158 | } 159 | 160 | var command = {cmd: 'message', name: name, content: content}; 161 | this.sendCommand(command); 162 | }; 163 | 164 | 165 | gatey.GateY.prototype.subscribe = function(name, onReceive, whenConnected) { 166 | var subscription = gatey.firstWithProperties(this.subscriptions, { name: name }); 167 | if(subscription) { 168 | subscription.onReceive = onReceive; 169 | subscription.whenConnected = whenConnected; 170 | return; 171 | } 172 | 173 | this.subscriptions.push({ 174 | name: name, 175 | onReceive: onReceive, 176 | whenConnected: whenConnected 177 | }); 178 | 179 | this.sendState(); 180 | }; 181 | 182 | gatey.GateY.prototype.unsubscribe = function(name) { 183 | var result = gatey.removeWithProperties(this.subscriptions, { name: name }); 184 | if(result.removed.length > 0) { 185 | this.subscriptions = result.rest; 186 | this.sendState(); 187 | } 188 | } 189 | 190 | gatey.GateY.prototype.openEmitter = function(name) { 191 | var emitter = gatey.firstWithProperties(this.emitters, { name: name }); 192 | if(emitter) { 193 | return; 194 | } 195 | 196 | this.emitters.push({ 197 | name: name 198 | }); 199 | 200 | this.sendState(); 201 | }; 202 | 203 | gatey.GateY.prototype.closeEmitter = function(name) { 204 | var result = gatey.removeWithProperties(this.emitters, { name: name }); 205 | if(result.removed.length > 0) { 206 | this.emitters = result.rest; 207 | this.sendState(); 208 | } 209 | }; 210 | 211 | /** 212 | * WriteVariable that is connected to a remote ReadVariable, if it is set the remote ReadVariable 213 | * will reflect the change 214 | */ 215 | gatey.WriteVariable = function(name, gateY) { 216 | this.name = name; 217 | this.gateY = gateY || gatey.global; 218 | 219 | this.gateY.openEmitter(this.name); 220 | } 221 | 222 | gatey.WriteVariable.prototype.set = function(value) { 223 | this.gateY.send(this.name, value); 224 | }; 225 | 226 | gatey.WriteVariable.prototype.close = function() { 227 | this.gateY.closeEmitter(this.name); 228 | }; 229 | 230 | gatey.ReadVariable = function(name, value, gateY) { 231 | this.name = name; 232 | this.value = value; 233 | this.onChange = undefined; 234 | this.gateY = gateY || gatey.global; 235 | 236 | var self = this; 237 | this.gateY.subscribe(name, function(value) { 238 | self.value = value; 239 | if(self.onChange) 240 | self.onChange(self.value); 241 | }); 242 | } 243 | 244 | gatey.ReadVariable.prototype.get = function() { 245 | return this.value; 246 | }; 247 | 248 | gatey.ReadVariable.prototype.close = function() { 249 | this.gateY.unsubscribe(this.name); 250 | }; 251 | 252 | gatey.Recorder = function(variable) { 253 | this.variable = variable; 254 | this.history = []; 255 | this.onChange = undefined; 256 | 257 | var self = this; 258 | 259 | variable.onChange = function(value) { 260 | self.history.push(value); 261 | if(self.onChange) 262 | self.onChange(self.value); 263 | } 264 | }; 265 | 266 | 267 | -------------------------------------------------------------------------------- /js/heatmap_d3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 21 | 22 | 23 | 24 | 25 | 83 |

84 | -------------------------------------------------------------------------------- /js/heatmap_highcharts.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 91 |

92 | -------------------------------------------------------------------------------- /js/sin_graph.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 80 |

81 |
82 |
83 | -------------------------------------------------------------------------------- /js/sin_text.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 46 |
47 |
48 |

49 | 50 | -------------------------------------------------------------------------------- /js/spaceship_canvas.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 53 | 54 | -------------------------------------------------------------------------------- /src/GateY.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(C) 2014 Tobias Neukom 3 | * Distributed under MIT license 4 | */ 5 | 6 | #ifndef GATEY_GATEY_H 7 | #define GATEY_GATEY_H 8 | 9 | #ifndef GATEY_IS_AMALGAMATION 10 | #include "Serialize.hpp" 11 | #include "WebSocketQueue.hpp" 12 | #endif 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | namespace gatey { 23 | 24 | struct WebSocketQueue; 25 | 26 | // template< class F, class... Args> 27 | // with(T_MEMBER_FUNCTION f, Args&& a) { 28 | // return [](T const& value) { 29 | // return (value.*f)( 30 | // } 31 | // } 32 | 33 | //TODO: Write function that takes member function without argument and a value comparable with return type 34 | //and returns a functor that takes obj and tests of property is equal to arg 35 | // template 36 | // auto has(T_RETURN T::* memberProperty, T_ARG&& arg) 37 | // -> decltype([memberProperty, arg](T const& value) { 38 | // return (value.*memberProperty)() == arg; 39 | // }) 40 | // { 41 | // return [memberProperty, arg](T const& value) { 42 | // return (value.*memberProperty)() == arg; 43 | // }; 44 | // } 45 | 46 | 47 | //! internal 48 | struct Emitter { 49 | std::string name_; 50 | 51 | //! = default 52 | Emitter() { 53 | } 54 | 55 | Emitter(std::string name) : 56 | name_(std::move(name)) 57 | { 58 | } 59 | 60 | std::string const& name() const { 61 | return name_; 62 | } 63 | }; 64 | 65 | //! internal 66 | struct Subscription { 67 | std::string name_; 68 | // std::string identifier_; maybe in the future 69 | std::function receive_; 70 | 71 | //! = default 72 | Subscription() { 73 | } 74 | 75 | Subscription(std::string name, std::function receive) : 76 | name_(std::move(name)), 77 | receive_(std::move(receive)) 78 | { 79 | } 80 | }; 81 | 82 | //! internal 83 | struct RemoteEmitter { 84 | std::string name_; 85 | SessionId sessionId_; 86 | 87 | //! = default 88 | RemoteEmitter() { 89 | } 90 | 91 | RemoteEmitter(std::string name, SessionId sessionId) : 92 | name_(std::move(name)), 93 | sessionId_(sessionId) 94 | { 95 | } 96 | }; 97 | 98 | //! internal 99 | struct RemoteSubscription { 100 | std::string name_; 101 | SessionId sessionId_; 102 | 103 | //! = default 104 | RemoteSubscription() { 105 | } 106 | 107 | RemoteSubscription(std::string name, SessionId sessionId) : 108 | name_(std::move(name)), 109 | sessionId_(sessionId) 110 | { 111 | } 112 | }; 113 | 114 | //! open and close gates, which come in two forms: receive gates and send gates 115 | //! messages can be sent over send gates and a receive gate on the remote side will 116 | //! process them. 117 | //! If a message is sent over a send gate and the remote side doesn't have a corresponding 118 | //! receive gate, the message is discarded 119 | //! If gates are opened or closes the remote side will be notified automatically 120 | //! Functions with the Unsynced postfix don't lock on mutex_ all other functions lock mutex_ 121 | struct GateY { 122 | private: 123 | //! true if any gates were opened or closed 124 | bool stateModified_; 125 | 126 | //! is true while thread_ is running 127 | bool running_; 128 | 129 | //! WebSocket server which does the actual network stuff 130 | std::unique_ptr webSocket_; 131 | 132 | //! Runs the network and dispatching work 133 | std::thread thread_; 134 | std::mutex mutex_; 135 | 136 | #if defined(_MSC_VER) 137 | //! msvc deadlocks if thread::join is called after main exits, see ~GateY for more details 138 | std::mutex mutexThreadRunning_; 139 | #endif 140 | 141 | std::vector subscriptions_; 142 | std::vector remoteSubscriptions_; 143 | std::vector emitters_; 144 | std::vector remoteEmitters_; 145 | 146 | //! List of callback that have to be called, callbacks aren't called while 147 | //! mutex_ is locked because the callback should be able to call GateY functions 148 | //! They are collected and called at a later time 149 | std::vector> callbacks_; 150 | 151 | //! Send a json package to remote 152 | void sendUnsynced(std::set sessions, Json::Value const& jValue); 153 | 154 | //! Send a json package to all remotes 155 | void broadcastUnsynced(Json::Value const& jValue); 156 | 157 | //! Send a list of open send and receive gates to remote 158 | void sendStateUnsynced(); 159 | 160 | //! Handle a message receive from remote, messages include: 161 | //! - state change 162 | //! - content 163 | //! - init 164 | void handleMessageUnsynced(InMessage const& message); 165 | 166 | 167 | //! Calls all the callbacks_ and clears it 168 | void processCallbacks(); 169 | 170 | //! Handles new messages from webSocket_ 171 | void work(); 172 | 173 | //! Close the receive gate with the given name and sends a state update 174 | void unsubscribeUnsynced(std::string const& name); 175 | 176 | //! Close the send gate with the given name 177 | void closeEmitterUnsynced(std::string const& name); 178 | 179 | //! Start the server 180 | void start(); 181 | 182 | std::vector::iterator findSubscriptionUnsynced(std::string const& name); 183 | 184 | std::vector::iterator findEmitterUnsynced(std::string const& name); 185 | 186 | std::vector::iterator findRemoteEmitterUnsynced(std::string const& name); 187 | 188 | std::vector::iterator findRemoteSubscriptionUnsynced(std::string const& name); 189 | 190 | std::set collectRemoteSubscriptions(std::string const& name); 191 | 192 | void eraseRemoteSubscriptionsUnsynced(SessionId sessionId); 193 | 194 | void eraseRemoteEmitters(SessionId sessionId); 195 | 196 | public: 197 | 198 | //! Starts the server 199 | GateY(); 200 | 201 | //! Stops the server 202 | ~GateY(); 203 | 204 | // Subscribe to receive all messages with the given name 205 | void subscribe(std::string const& name, std::function receive); 206 | 207 | // Unsubscribe from receiving messages with the given name 208 | void unsubscribe(std::string const& name); 209 | 210 | // Send a message with the given name 211 | void emit(std::string const& name, Json::Value const& jValue); 212 | 213 | // Announce the sending of message with the given name 214 | void openEmitter(std::string const& name); 215 | 216 | // Unannounce the sending of messages with the given name 217 | void closeEmitter(std::string const& name); 218 | 219 | }; 220 | 221 | //! global GateY, Variables use this global gateY to open gates 222 | extern std::shared_ptr global; 223 | 224 | } 225 | 226 | 227 | #endif //GATEY_GATEY_H 228 | 229 | -------------------------------------------------------------------------------- /src/Log.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(C) 2014 Tobias Neukom 3 | * Distributed under MIT license 4 | */ 5 | 6 | #ifndef GATEY_IS_AMALGAMATION 7 | #include "Log.hpp" 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | namespace gatey { 14 | void log(const char* str) { 15 | std::cout << str << std::endl; 16 | } 17 | 18 | void log(std::string const& str) { 19 | std::cout << str << std::endl; 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /src/Log.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(C) 2014 Tobias Neukom 3 | * Distributed under MIT license 4 | */ 5 | 6 | #ifndef GATEY_LOG_HPP 7 | #define GATEY_LOG_HPP 8 | 9 | //#define GATEY_LOG_ENABLED 10 | 11 | #ifdef GATEY_LOG_ENABLED 12 | 13 | #include 14 | 15 | namespace gatey { 16 | void log(const char* str); 17 | void log(std::string const& str); 18 | } 19 | 20 | #define GATEY_LOG(str) gatey::log(str) 21 | 22 | #else //GATEY_LOG_ENABLED 23 | #define GATEY_LOG (void) 24 | #endif //GATEY_LOG_ENABLED 25 | 26 | 27 | #endif //GATEY_LOG_HPP -------------------------------------------------------------------------------- /src/Serialize.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(C) 2014 Tobias Neukom 3 | * Distributed under MIT license 4 | */ 5 | 6 | #ifndef GATEY_IS_AMALGAMATION 7 | #include "Serialize.hpp" 8 | #endif 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | //Another fun VS 2012 fix 15 | #if defined(_MSC_VER) && (_MSC_VER < 1800) //1800 is Visual Studio 2013 16 | #include 17 | #define ISFINITE(arg) _finite((arg)) 18 | #else 19 | #define ISFINITE(arg) std::isfinite((arg)) 20 | #endif 21 | 22 | namespace gatey { 23 | 24 | namespace serialize { 25 | 26 | //int 27 | void write(int value, Json::Value& jValue, Info const& info) { 28 | jValue = Json::Value(value); 29 | } 30 | 31 | void read(Json::Value const& jValue, int& value, Info const& info) { 32 | value = jValue.asInt(); 33 | } 34 | 35 | 36 | //float 37 | void write(float value, Json::Value& jValue, Info const& info) { 38 | if (!ISFINITE(value)) { 39 | jValue = Json::Value(0.0f); 40 | std::cerr << "encountered nan or inf" << std::endl; 41 | } 42 | jValue = Json::Value(value); 43 | } 44 | 45 | void read(Json::Value const& jValue, float& value, Info const& info) { 46 | value = jValue.asFloat(); 47 | } 48 | 49 | //double 50 | void write(double value, Json::Value& jValue, Info const& info) { 51 | if (!ISFINITE(value)) { 52 | jValue = Json::Value(0.0f); 53 | std::cerr << "encountered nan or inf" << std::endl; 54 | } 55 | jValue = Json::Value(value); 56 | } 57 | 58 | void read(Json::Value const& jValue, double& value, Info const& info) { 59 | value = jValue.asDouble(); 60 | } 61 | 62 | //char 63 | void write(char value, Json::Value& jValue, Info const& info) { 64 | jValue = Json::Value(std::string(value, 1)); 65 | } 66 | 67 | void read(Json::Value const& jValue, char& value, Info const& info) { 68 | //TODO: Check if single char 69 | value = jValue.asCString()[0]; 70 | } 71 | 72 | //std::string 73 | void write(std::string const& value, Json::Value& jValue, Info const& info) { 74 | jValue = Json::Value(value); 75 | } 76 | 77 | void read(Json::Value const& jValue, std::string& value, Info const& info) { 78 | value = jValue.asString(); 79 | } 80 | 81 | } // namespace serialize 82 | 83 | 84 | 85 | 86 | } // namespace gatey 87 | -------------------------------------------------------------------------------- /src/Variable.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(C) 2014 Tobias Neukom 3 | * Distributed under MIT license 4 | */ 5 | 6 | #ifndef GATEY_VARIABLE_HPP 7 | #define GATEY_VARIABLE_HPP 8 | 9 | #ifndef GATEY_IS_AMALGAMATION 10 | #include "GateY.hpp" 11 | #endif 12 | 13 | #include 14 | #include 15 | 16 | namespace gatey { 17 | 18 | //! WriteVariable of type T that is connected to a remote ReadVariable, if it is set the remote ReadVariable 19 | //! will reflect the change 20 | //TODO: add emplace, for example for tuple: emplace(x, y) instead of set(std::make_tuple(x, y)) 21 | template 22 | struct WriteVariable { 23 | private: 24 | std::string name_; 25 | 26 | //! GateY used to send changes 27 | std::shared_ptr gateY_; 28 | 29 | public: 30 | 31 | //! Using the given gatey or gatey::global as default, opens a send gate with the given name 32 | WriteVariable(std::string name, std::shared_ptr gateY = gatey::global) : 33 | name_(std::move(name)), 34 | gateY_(gateY) 35 | { 36 | gateY_->openEmitter(name_); 37 | } 38 | 39 | //! Closes the send gate with the given name 40 | ~WriteVariable() { 41 | gateY_->closeEmitter(name_); 42 | } 43 | 44 | //! Set the value of this variable, the value is serialized to json using the gatey::serialize function 45 | //! and then sent to remote if it has a corresponding ReadVariable 46 | //TODO: Only serialize if 47 | void set(T const& value) { 48 | Json::Value jValue; 49 | write(value, jValue); 50 | gateY_->emit(name_, jValue); 51 | } 52 | }; 53 | 54 | //! ReadVariable of type T that is connected to a remote WriteVariable, if the remote WriteVariable is 55 | //! changed, the change is reflected in the ReadVariable 56 | template 57 | struct ReadVariable { 58 | private: 59 | std::string name_; 60 | 61 | //! current value 62 | T content_; 63 | 64 | //! to make sure the variable doesn't change while being read 65 | std::recursive_mutex mutex_; 66 | 67 | //! GateY used to receive changes 68 | std::shared_ptr gateY_; 69 | 70 | public: 71 | std::function onChange; 72 | 73 | //! Using the given gatey or gatey::global as default, opens a read gate with the given name, 74 | //! get will return content if the remote WriteVariable was never set. 75 | ReadVariable(std::string name, T content, std::shared_ptr gateY = gatey::global) : 76 | name_(std::move(name)), 77 | content_(std::move(content)), 78 | gateY_(gateY) 79 | { 80 | gateY_->subscribe(name_, [this](Json::Value const& jValue) { 81 | std::lock_guard guard(mutex_); 82 | read(jValue, content_); 83 | if (onChange != nullptr) 84 | onChange(content_); 85 | }); 86 | } 87 | 88 | //! Closes the receive gate with the given name 89 | ~ReadVariable() { 90 | gateY_->unsubscribe(name_); 91 | } 92 | 93 | //! Returns the current value, locks while the variable is being updated 94 | T get() { 95 | std::lock_guard guard(mutex_); 96 | return content_; 97 | } 98 | }; 99 | } 100 | 101 | #endif // GATEY_VARIABLE_HPP 102 | -------------------------------------------------------------------------------- /src/WebSocketQueue.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(C) 2014 Tobias Neukom 3 | * Distributed under MIT license 4 | */ 5 | 6 | #ifndef GATEY_WEBSOCKETQUEUE_H 7 | #define GATEY_WEBSOCKETQUEUE_H 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | struct libwebsocket_context; 18 | struct libwebsocket; 19 | 20 | namespace gatey { 21 | 22 | typedef unsigned long long SessionId; 23 | 24 | struct WebSocketQueue; 25 | 26 | struct OutMessage { 27 | private: 28 | std::string content_; 29 | std::set destionations_; // only defined if Destination == Session 30 | 31 | std::vector buffer_; 32 | std::size_t len_; 33 | 34 | //! = delete 35 | OutMessage(OutMessage const& other); 36 | 37 | //! = delete 38 | OutMessage& operator=(OutMessage const& other); 39 | 40 | public: 41 | 42 | //! = default 43 | OutMessage(); 44 | OutMessage(std::set destinations, std::string content); 45 | 46 | //OutMessage(OutMessage&& other) = default; thanks VS 47 | 48 | //! default move constructor 49 | OutMessage(OutMessage&& other); 50 | 51 | 52 | 53 | //OutMessage& operator=(OutMessage&& other) = default; 54 | 55 | //! default move assignment 56 | OutMessage& operator=(OutMessage&& other); 57 | 58 | std::set const& destinations() const { 59 | return destionations_; 60 | } 61 | 62 | void removeDestination(SessionId sessionId); 63 | 64 | void keepDestinations(std::set const& keep); 65 | 66 | friend struct WebSocketQueue; 67 | }; 68 | 69 | struct InMessage { 70 | private: 71 | SessionId source_; 72 | std::string content_; 73 | 74 | public: 75 | 76 | std::string const& content() const { 77 | return content_; 78 | } 79 | 80 | SessionId source() const { 81 | return source_; 82 | } 83 | 84 | InMessage(); 85 | InMessage(SessionId source, char const* bytes, std::size_t len); 86 | 87 | friend struct WebSocketQueue; 88 | }; 89 | 90 | //! So we don't have to include the libwebsockets header 91 | struct LibWebsocketsCallbackReasonBoxed; 92 | 93 | //! WebSocket server using the libwebsockets library 94 | struct WebSocketQueue { 95 | private: 96 | bool messageSent_; 97 | SessionId nextUniqueSessionId_; 98 | 99 | unsigned int maxSessionCount_; 100 | 101 | //! List of unique session ids, at the moment only one session at a time is possible 102 | std::set sessions_; 103 | 104 | libwebsocket_context *context_; 105 | 106 | mutable std::mutex mutex_; 107 | 108 | //Using list because resizing is costly 109 | 110 | //! Incoming messages, std::string has a nothrow move constructor, therefore 111 | //! resize should not be a problem 112 | std::deque inMessages_; 113 | 114 | //! Outgoing messages 115 | std::deque outMessages_; 116 | 117 | std::deque::iterator firstMessageWithDestination(SessionId sessionId); 118 | 119 | public: 120 | 121 | std::set sessions() const; 122 | 123 | //TODO: Make private somehow 124 | static int callback(libwebsocket_context *context, libwebsocket *wsi, 125 | LibWebsocketsCallbackReasonBoxed const& reasonBoxed, 126 | void *user, void *in, size_t len); 127 | 128 | //! send, empty, receive can be called from different threads use work only in the one thread 129 | //! Put message on queue to send 130 | void emit(OutMessage message); 131 | 132 | //! returns a list of new messages 133 | std::deque receive(); 134 | 135 | //! call this to do the actual work: send and receiving messages handling network stuff ... 136 | void work(); 137 | 138 | WebSocketQueue(); 139 | ~WebSocketQueue(); 140 | }; 141 | 142 | } 143 | 144 | #endif 145 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "GateY.hpp" 2 | #include "Variable.hpp" 3 | #include 4 | #include 5 | #include 6 | 7 | /* 8 | TODO: 9 | 10 | - Use broadcast for websocket so all clients get updates 11 | - Allow only one connection for the moment 12 | */ 13 | 14 | int main() { 15 | std::chrono::milliseconds dura(100); 16 | gatey::global = std::make_shared(); 17 | 18 | 19 | //const std::size_t SIZE = 32; 20 | //std::array, SIZE> field = { { 0.0 } }; 21 | //std::tuple tuple; 22 | //WriteVariable gField("field"); 23 | //WriteVariable gTuple("tuple"); 24 | 25 | //field[SIZE / 2][SIZE / 2] = 100000.0; 26 | //double alpha = 1.0; 27 | //double dt = 1.0 / 30; 28 | //while (true) { 29 | // char c; 30 | // std::cin >> c; 31 | 32 | // tuple = std::make_tuple(1, std::string("Hello World")); 33 | // gTuple.set(tuple); 34 | 35 | // for (unsigned int step = 0; step < 100; ++step) { 36 | // std::this_thread::sleep_for(dura); 37 | 38 | // decltype(field) copy = { { 0.0 } }; 39 | // for (std::size_t x = 1; x < SIZE - 1; ++x) { 40 | // for (std::size_t y = 1; y < SIZE - 1; ++y) { 41 | // //du/dt = alpha laplace u 42 | // //du = dt * alpha laplace u 43 | // //u' = u + dt * alpha laplace u 44 | // double laplace = field[x - 1][y] + field[x + 1][y] + field[x][y - 1] + field[x][y + 1] - 4 * field[x][y]; 45 | // copy[x][y] = field[x][y] + alpha * dt * laplace; 46 | // } 47 | // } 48 | // field = copy; 49 | // gField.set(field); 50 | // } 51 | //} 52 | 53 | 54 | 55 | gatey::WriteVariable> gF("y"); 56 | gatey::ReadVariable gDt("dt", 0.01f); 57 | gatey::ReadVariable gC("c", 1.0f); 58 | 59 | 60 | float time = 0.0f; 61 | while (true) { 62 | float y = gC.get() * std::sin(time); 63 | gF.set(std::make_pair(time, y)); 64 | time += gDt.get(); 65 | std::this_thread::sleep_for(dura); 66 | } 67 | 68 | 69 | // gateY.start(); 70 | 71 | //WriteVariable> gXs("xs"); 72 | // ReadVariable gFreq("freq", 1.0f); 73 | 74 | // std::chrono::milliseconds dura(20); 75 | 76 | // std::vector xs(4000); 77 | // for(std::size_t i = 0; i < 4000; ++i) 78 | // xs[i] = i; 79 | 80 | // float time = 0; 81 | // while (true) { 82 | // std::this_thread::sleep_for(dura); 83 | // float delta = 1.0f / gFreq.get(); 84 | // gXs.set(xs); 85 | // time += delta; 86 | // } 87 | 88 | return 0; 89 | 90 | 91 | } 92 | 93 | --------------------------------------------------------------------------------