├── .gitignore
├── .travis.yml
├── CMakeLists.txt
├── COPYING
├── README.md
├── cysboard.pro
├── deps
└── bin
│ ├── libsciter-gtk-64.so
│ └── packfolder.bin
├── includes
├── sciter
│ ├── aux-asset.h
│ ├── aux-cvt.h
│ ├── aux-platform.h
│ ├── aux-slice.h
│ ├── behaviors
│ │ ├── behavior_camera_capture.cpp
│ │ ├── behavior_drawing-gdi.cpp
│ │ ├── behavior_drawing-opengl.cpp
│ │ ├── behavior_drawing.cpp
│ │ ├── behavior_tabs.cpp
│ │ ├── behavior_video_generator.cpp
│ │ └── camera
│ │ │ ├── camera-capture.cpp
│ │ │ └── camera-capture.h
│ ├── sciter-gtk-main.cpp
│ ├── sciter-osx-main.mm
│ ├── sciter-win-main.cpp
│ ├── sciter-x-api.h
│ ├── sciter-x-behavior.h
│ ├── sciter-x-debug.h
│ ├── sciter-x-def.h
│ ├── sciter-x-dom.h
│ ├── sciter-x-dom.hpp
│ ├── sciter-x-graphics.h
│ ├── sciter-x-graphics.hpp
│ ├── sciter-x-host-callback.h
│ ├── sciter-x-lite.hpp
│ ├── sciter-x-msg.h
│ ├── sciter-x-request.h
│ ├── sciter-x-request.hpp
│ ├── sciter-x-script.h
│ ├── sciter-x-threads.h
│ ├── sciter-x-types.h
│ ├── sciter-x-value.h
│ ├── sciter-x-video-api.h
│ ├── sciter-x-window.hpp
│ ├── sciter-x.h
│ ├── tiscript-streams.hpp
│ ├── tiscript.h
│ ├── tiscript.hpp
│ ├── value.h
│ └── value.hpp
└── spdlog
│ ├── async_logger.h
│ ├── common.h
│ ├── details
│ ├── async_log_helper.h
│ ├── async_logger_impl.h
│ ├── file_helper.h
│ ├── format.cc
│ ├── format.h
│ ├── line_logger_fwd.h
│ ├── line_logger_impl.h
│ ├── log_msg.h
│ ├── logger_impl.h
│ ├── mpmc_bounded_q.h
│ ├── null_mutex.h
│ ├── os.h
│ ├── pattern_formatter_impl.h
│ ├── registry.h
│ └── spdlog_impl.h
│ ├── formatter.h
│ ├── logger.h
│ ├── sinks
│ ├── android_sink.h
│ ├── ansicolor_sink.h
│ ├── base_sink.h
│ ├── dist_sink.h
│ ├── file_sinks.h
│ ├── msvc_sink.h
│ ├── null_sink.h
│ ├── ostream_sink.h
│ ├── sink.h
│ ├── stdout_sinks.h
│ └── syslog_sink.h
│ ├── spdlog.h
│ └── tweakme.h
└── sources
├── call_program.h
├── ccpuid.h
├── cpucoreobject.h
├── cpuinfo.h
├── cpuinfo_linux.cpp
├── cpuinfo_win32.cpp
├── cpuobject.h
├── cysboard.h
├── default_theme.cpp
├── diskinfo.h
├── diskinfo_linux.cpp
├── diskobject.h
├── linuxutil.cpp
├── linuxutil.h
├── main.cpp
├── meminfo.h
├── meminfo_linux.cpp
├── memoryobject.h
├── osinfo.h
├── osinfo_linux.cpp
├── osobject.h
├── resources
├── default.htm
└── default_exports.js
├── util.h
├── win32util.cpp
└── win32util.h
/.gitignore:
--------------------------------------------------------------------------------
1 | debug/
2 | release/
3 | .idea/
4 | *.o
5 | *.user
6 | .qmake.stash
7 | build
8 | Cysboard.cbp
9 | CMakeCache.txt
10 | CMakeFiles
11 | CMakeScripts
12 | Makefile
13 | cmake_install.cmake
14 | install_manifest.txt
15 | compile_commands.json
16 | CTestTestfile.cmake
17 |
18 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: cpp
2 |
3 | sudo: required
4 |
5 | dist: trusty
6 |
7 | before_install:
8 | - sudo apt-get -qq update
9 | - sudo apt-get install libgtk-3-dev
10 |
11 |
12 | addons:
13 | apt:
14 | sources:
15 | - ubuntu-toolchain-r-test
16 | packages:
17 | - g++-6
18 | - gcc-6
19 |
20 | compiler: gcc
21 |
22 | script:
23 | - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 90
24 | - mkdir build
25 | - cmake . && make
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required (VERSION 3.1)
2 | project (Cysboard)
3 | #version
4 | set(Cysboard_VERSION_MAJOR 1)
5 | set(Cysboard_VERSION_MINOR 2)
6 | set(CMAKE_CXX_STANDARD 14)
7 |
8 | #includes path
9 | include_directories("includes")
10 |
11 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "build")
12 |
13 | #header files
14 | set (${HEADERS}
15 | sources/ccpuid.h
16 | sources/cpucoreobject.h
17 | sources/cpuinfo.h
18 | sources/cpuobject.h
19 | sources/cysboard.h
20 | sources/diskinfo.h
21 | sources/diskobject.h
22 | sources/iinfoobject.h
23 | sources/linuxutil.h
24 | sources/meminfo.h
25 | sources/memoryobject.h
26 | sources/osinfo.h
27 | sources/osobject.h
28 | sources/util.h
29 | )
30 |
31 | set(SOURCES
32 | sources/cpuinfo_linux.cpp
33 | sources/default_theme.cpp
34 | sources/diskinfo_linux.cpp
35 | sources/linuxutil.cpp
36 | sources/meminfo_linux.cpp
37 | sources/osinfo_linux.cpp
38 | sources/main.cpp
39 | )
40 |
41 | # require gtk on linux
42 | find_package(PkgConfig REQUIRED)
43 | pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
44 | include_directories(${GTK3_INCLUDE_DIRS})
45 |
46 |
47 | add_executable(Cysboard ${SOURCES})
48 | target_link_libraries(Cysboard pthread dl ${GTK3_LIBRARIES})
49 | target_compile_options(Cysboard PRIVATE "-O3" )
50 |
51 | # compile default theme
52 | execute_process(COMMAND echo "Packing resources...")
53 | execute_process(COMMAND deps/bin/packfolder.bin sources/resources sources/default_theme.cpp)
54 | # add static keyword
55 | execute_process(COMMAND sed -i "1i static" sources/default_theme.cpp)
56 | # add sciter library to build directory
57 | execute_process(COMMAND cp deps/bin/libsciter-gtk-64.so build/)
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Cysboard
2 | =========
3 | A lightweight system monitor similar to conky but with html and css for themes
4 |
5 |
6 |
7 | ## Usage
8 | 1. Create a theme file called main.html in ~/.config/cysboard/ (There must be a file name 'main.html').
9 | 2. Add your html code with any of the listed ids below in html tags for device info.
10 | 3. Run cysboard.
11 |
12 | If a 'main.html' file does not exist in the config directory cysboard will start with a default theme.
13 |
14 | ## Compiling
15 | You must have cmake >= 3.1 and gcc >= 5.4 in order to compile
16 |
17 | 1. mkdir build
18 | 2. cmake .
19 | 3. make
20 |
21 |
22 | ## Examples
23 |
28 |
29 | Use ids like the following
30 |
31 | ```html
32 |
33 |
34 | Cysboard
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
45 |
46 |
SYSTEM
47 |
48 |
name:
49 |
distro:
50 |
uptime:
51 |
52 |
53 |
54 |
55 |
CPU
56 |
model:
57 |
vendor:
58 |
arch:
59 |
usage: %
60 |
61 |
62 |
63 |
RAM
64 |
free: KB
65 |
used: KB
66 |
67 |
68 |
Program 1 Output:
69 |
Program 2 Output:
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 | ```
80 | Please see sources/resources/default.html for a working theme.
81 |
82 | ## IDs
83 | A list of currently supported information from sources. Add any of
84 | them as an *id* attribute for a tag in your theme file.
85 |
86 | ID | Info
87 | -------------- | -----------------
88 | cpu_name | The CPU's name
89 | cpu_usage | The total usage of the CPU in percentages
90 | cpu_arch | The CPU's architecture
91 | cpu_vendor | The CPU vendor eg. Intel, AMD
92 | cpu_num_cores | The number of physical cores
93 | mem_free | The amount of free memory in KB, MB or GB
94 | mem_used | The amount of used memory in KB, MB or GB
95 | mem_swap_total | The amount of swap memory in KB, MB or GB
96 | mem_total | The total amount of physical memory available
97 | os_name | The name of the OS
98 | os_distro_name | The distribution name (*Linux only*)
99 | os_uptime | The total amount of time since last boot
100 | os_num_procs | The number of running processes
101 | exec_# | Execute a program and display its output eg. *exec_0, exec_1* etc.
102 | cpu_usage_# | Get a cpu core's usage percentage eg. *cpu_usage_0, cpu_usage_1* etc.
103 |
104 | Some IDs require attributes and can be used like this
105 |
106 | ```html
107 | Free RAM:
108 | ```
109 |
110 | Atrribute | Description | Applicable ID(s)
111 | ----------------| --------------------------------- | ---------------------------------------------
112 | mul | Display value in MB, KB or GB | mem_free, mem_used, mem_swap_total, mem_total
113 | cmd | Path of program to execute | exec_#
114 |
115 | ## Project structure
116 | The source code for the project is located in the source directory.
117 | The header file `cysboard.h` contains the main update function for the program.
118 | Objects for information from or about the cpu, os, memory and others are initialized in this class.
119 | All the other files house classes for gathering information from various sources. For example `cpuinfo_linux.cpp` has functions for gathering cpu info on a system. The header file `util.h` holds functions for common and repetitive tasks.
120 |
121 | ## Known Issues
122 | 1. Program crashes sometimes when editing themes.
123 |
124 | ## Todo
125 | 1. GPU, Disk and Network information.
126 | 2. Add graph and bar controls like conky.
127 | 3. Run commands from theme file.
128 |
--------------------------------------------------------------------------------
/cysboard.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = app
2 | CONFIG += console c++14
3 | CONFIG -= app_bundle
4 | CONFIG -= qt
5 | CONFIG += link_pkgconfig
6 | QMAKE_CXXFLAGS += -Wall
7 | PKGCONFIG += gtk+-3.0
8 |
9 | HEADERS += sources/*.h \
10 | sources/call_program.h
11 |
12 | SOURCES += \
13 | sources/main.cpp \
14 |
15 | unix:SOURCES += sources/cpuinfo_linux.cpp \
16 | sources/osinfo_linux.cpp \
17 | sources/diskinfo_linux.cpp \
18 | sources/meminfo_linux.cpp \
19 |
20 | win32:SOURCES += sources/*_win32.cpp
21 |
22 | INCLUDEPATH += includes
23 |
24 | unix:CONFIG(debug, debug|release):LIBS += -L/usr/lib -ldl
25 | unix:CONFIG(release, debug|release):LIBS += -L/usr/lib -ldl
26 | unix:CONFIG(debug, debug|release):LIBS += -L/usr/lib -lpthread
27 | unix:CONFIG(release, debug|release):LIBS += -L/usr/lib -lpthread
28 |
29 |
30 |
--------------------------------------------------------------------------------
/deps/bin/libsciter-gtk-64.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mik30s/Cysboard/a5bc7707ec9a0a4bd101bf099e6b2b1b2861dc96/deps/bin/libsciter-gtk-64.so
--------------------------------------------------------------------------------
/deps/bin/packfolder.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mik30s/Cysboard/a5bc7707ec9a0a4bd101bf099e6b2b1b2861dc96/deps/bin/packfolder.bin
--------------------------------------------------------------------------------
/includes/sciter/aux-platform.h:
--------------------------------------------------------------------------------
1 | #ifndef __aux_platform_h__
2 | #define __aux_platform_h__
3 |
4 | /*
5 | * Terra Informatica Sciter and HTMLayout Engines
6 | * http://terrainformatica.com/sciter, http://terrainformatica.com/htmlayout
7 | *
8 | * platform primitives.
9 | *
10 | * The code and information provided "as-is" without
11 | * warranty of any kind, either expressed or implied.
12 | *
13 | * (C) 2003-2015, Andrew Fedoniouk (andrew@terrainformatica.com)
14 | */
15 |
16 |
17 | #if defined(_WIN32_WCE) || defined(UNDER_CE)
18 | #define PLATFORM_WINCE
19 | #define WINDOWS
20 | #elif defined(WIN64) || defined(_WIN64) || defined(_M_X64)
21 | #define PLATFORM_DESKTOP
22 | #define WINDOWS
23 | #define X64BITS
24 | #elif defined(WIN32) || defined(_WIN32)
25 | #define PLATFORM_DESKTOP
26 | #define WINDOWS
27 | #elif defined(__APPLE__)
28 | #define PLATFORM_OSX
29 | #define OSX
30 | #define UTF8_CHARS // const char* is UTF8 sequence
31 | #ifdef __x86_64__
32 | #define X64BITS
33 | #endif
34 | #define POSIX
35 | #elif defined( __linux__ )
36 | #define PLATFORM_LINUX
37 | #define LINUX
38 | #ifdef __x86_64__
39 | #define X64BITS
40 | #endif
41 | #define POSIX
42 | #define UTF8_CHARS // const char* is UTF8 sequence
43 | #else
44 | #error "Unknown platform"
45 | #endif
46 |
47 | #if defined(WINDOWS)
48 | #define stricmp _stricmp
49 | #define wcsicmp _wcsicmp
50 | #elif defined(POSIX)
51 | #define stricmp strcasecmp
52 | #define wcsicmp wcscasecmp
53 | #endif
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/includes/sciter/behaviors/behavior_camera_capture.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "sciter-x-dom.hpp"
3 | #include "sciter-x-behavior.h"
4 |
5 | #if TRUE // change it to FALSE to disable camera functionality
6 |
7 | #include "camera/camera-capture.h"
8 | #include "camera/camera-capture.cpp"
9 |
10 | namespace sciter
11 | {
12 | /*
13 |
14 | BEHAVIOR: camera_stream
15 | provides video frames from camera
16 | COMMENTS:
17 |
18 | SAMPLE:
19 | See: samples/video/video-camera-behavior.htm
20 | */
21 |
22 | struct camera_stream: public event_handler
23 | {
24 | com::ptr pcapt;
25 | aux::asset_ptr rendering_site;
26 | // ctor
27 | camera_stream() {}
28 | virtual ~camera_stream() {}
29 |
30 | virtual bool subscription( HELEMENT he, UINT& event_groups )
31 | {
32 | event_groups = HANDLE_BEHAVIOR_EVENT; // we only handle VIDEO_BIND_RQ here
33 | return true;
34 | }
35 |
36 | virtual void attached (HELEMENT he ) { }
37 |
38 | virtual void detached (HELEMENT he ) { delete this; }
39 | virtual bool on_event (HELEMENT he, HELEMENT target, BEHAVIOR_EVENTS type, UINT_PTR reason )
40 | {
41 | if(type != VIDEO_BIND_RQ)
42 | return false;
43 | // we handle only VIDEO_BIND_RQ requests here
44 |
45 | if( !reason )
46 | return true; // first phase, consume the event to mark as we will provide frames
47 |
48 | rendering_site = (sciter::video_destination*) reason;
49 | return true;
50 | }
51 |
52 | sciter::value get_devices() {
53 | camera::device_list devices;
54 | devices.enumerate_devices();
55 | sciter::value r;
56 | for( unsigned n = 0; n < devices.count(); ++n ) {
57 | sciter::string name;
58 | if(devices.get_device_name(n,name))
59 | r.append( sciter::value(name) );
60 | }
61 | return r;
62 | }
63 |
64 | sciter::value stream_from( const sciter::value& device ) // either int (index) or string (name)
65 | {
66 | if(pcapt)
67 | pcapt->end_capture();
68 | pcapt = camera::capture::create_instance(rendering_site,device);
69 | return sciter::value(true);
70 | }
71 |
72 | // scripting methods
73 | BEGIN_FUNCTION_MAP
74 | FUNCTION_0("devices",get_devices) // devices() : (array of strings), get list of names of devices
75 | FUNCTION_1("streamFrom",stream_from) // streamFrom(indexOrName: int | string), start streaming from the camera
76 | END_FUNCTION_MAP
77 |
78 | };
79 |
80 | struct camera_stream_factory: public behavior_factory {
81 |
82 | camera_stream_factory(): behavior_factory("camera") {}
83 |
84 | // the only behavior_factory method:
85 | virtual event_handler* create(HELEMENT he) { return new camera_stream(); }
86 |
87 | };
88 |
89 | // instantiating and attaching it to the global list
90 | camera_stream_factory camera_stream_factory_instance;
91 |
92 |
93 | }
94 |
95 | #endif
--------------------------------------------------------------------------------
/includes/sciter/behaviors/behavior_drawing-gdi.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "sciter-x.h"
3 | #include "sciter-x-behavior.h"
4 | #include "sciter-x-graphics.hpp"
5 |
6 | namespace sciter
7 | {
8 | /*
9 | BEHAVIOR: gdi-drawing
10 | - draws content layer using GDI primitives.
11 |
12 | SAMPLE:
13 | See: samples/behaviors/gdi-drawing.htm
14 | */
15 |
16 | // dib (bitmap) combined with DC
17 |
18 | class dib32
19 | {
20 | const unsigned _width;
21 | const unsigned _height;
22 | void* _bits;
23 | mutable HBITMAP _old_bitmap;
24 | mutable HDC _dc;
25 | HBITMAP _bitmap;
26 |
27 | BITMAPINFO _bitmap_info;
28 |
29 | public:
30 |
31 | dib32(unsigned w, unsigned h) :
32 | _width(w),
33 | _height(h),
34 | _bits(0),
35 | _old_bitmap(0),
36 | _dc(0) {
37 |
38 | memset(&_bitmap_info,0,sizeof(_bitmap_info));
39 | _bitmap_info.bmiHeader.biSize = sizeof(_bitmap_info.bmiHeader);
40 | _bitmap_info.bmiHeader.biWidth = _width;
41 | _bitmap_info.bmiHeader.biHeight = 0 - int(_height);
42 | _bitmap_info.bmiHeader.biPlanes = 1;
43 | _bitmap_info.bmiHeader.biBitCount = 32;
44 | _bitmap_info.bmiHeader.biCompression = BI_RGB;
45 |
46 | _bitmap = ::CreateDIBSection(
47 | NULL, // device context
48 | &_bitmap_info,
49 | DIB_RGB_COLORS,
50 | &_bits,
51 | 0, // file mapping object
52 | 0); // file offset
53 |
54 | if (0 == _bits) {
55 | return;
56 | //throw std::bad_alloc();
57 | }
58 |
59 | memset(_bits,0, _width * _height * 4);
60 |
61 | }
62 |
63 | ~dib32() {
64 | if( _dc )
65 | {
66 | ::SelectObject(_dc,_old_bitmap);
67 | ::DeleteDC(_dc);
68 | }
69 | if( _bitmap )
70 | ::DeleteObject(_bitmap);
71 | }
72 |
73 | void set_white()
74 | {
75 | memset(_bits,0xff, _width * _height * 4);
76 | }
77 |
78 | unsigned width() const { return _width; }
79 | unsigned height() const { return _height; }
80 | void* bits() const { return _bits; }
81 | BYTE* bytes() const { return (BYTE*)_bits; }
82 | HDC DC() const
83 | {
84 | if(!_dc) {
85 | _dc = ::CreateCompatibleDC(NULL);
86 | if (_dc)
87 | _old_bitmap = (HBITMAP)::SelectObject(_dc,_bitmap);
88 | }
89 | return _dc;
90 | }
91 |
92 | HBITMAP detach() { auto r = _bitmap; _bitmap = 0; return r; }
93 |
94 | const BITMAPINFO& get_info() const { return _bitmap_info; }
95 | };
96 |
97 |
98 | struct gdi_drawing: public event_handler
99 | {
100 | // ctor
101 | gdi_drawing() {}
102 | virtual ~gdi_drawing() {}
103 |
104 | virtual bool subscription( HELEMENT he, UINT& event_groups )
105 | {
106 | event_groups = HANDLE_DRAW; // it does drawing
107 | return true;
108 | }
109 |
110 | virtual void attached (HELEMENT he ) { }
111 | virtual void detached (HELEMENT he ) { delete this; }
112 |
113 | virtual bool handle_draw (HELEMENT he, DRAW_PARAMS& params )
114 | {
115 | if( params.cmd != DRAW_CONTENT ) return false; // drawing only content layer
116 |
117 | unsigned w = unsigned(params.area.right - params.area.left);
118 | unsigned h = unsigned(params.area.bottom - params.area.top);
119 |
120 | dib32 buffer(w,h);
121 |
122 | do_draw(buffer.DC(), w,h);
123 |
124 | sciter::image img = sciter::image::create(w,h,false,buffer.bytes());
125 |
126 | sciter::graphics gfx(params.gfx);
127 |
128 | gfx.draw_image(&img, POS(params.area.left), POS(params.area.top));
129 |
130 | return true;
131 |
132 | }
133 |
134 | void do_draw( HDC hdc, unsigned width, unsigned height ) {
135 | RECT rc = { 0,0,width,height };
136 | HBRUSH hbr1 = ::CreateSolidBrush(0x000000);
137 | HBRUSH hbr2 = ::CreateSolidBrush(0x0000FF);
138 | // fill it by black color:
139 | ::FillRect(hdc,&rc,hbr1);
140 | ::InflateRect(&rc,-40,-40);
141 | ::FillRect(hdc,&rc,hbr2);
142 | ::DeleteObject(hbr1);
143 | ::DeleteObject(hbr2);
144 | }
145 |
146 | };
147 |
148 | struct gdi_drawing_factory: public behavior_factory {
149 |
150 | gdi_drawing_factory(): behavior_factory("gdi-drawing") { }
151 |
152 | // the only behavior_factory method:
153 | virtual event_handler* create(HELEMENT he) {
154 | return new gdi_drawing();
155 | }
156 |
157 | };
158 |
159 | // instantiating and attaching it to the global list
160 | gdi_drawing_factory gdi_drawing_factory_instance;
161 |
162 |
163 | }
164 |
--------------------------------------------------------------------------------
/includes/sciter/behaviors/behavior_drawing-opengl.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "sciter-x.h"
3 | #include "sciter-x-behavior.h"
4 | #include "sciter-x-threads.h"
5 |
6 | //#include
7 |
8 | #if defined(WINDOWS)
9 | #define WIN32_LEAN_AND_MEAN
10 | #include
11 | #include
12 | #include
13 | #pragma comment(lib, "OpenGL32.lib")
14 | #pragma comment(lib, "Glu32.lib")
15 | #elif defined(OSX)
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #elif defined(LINUX)
23 | #include
24 | #include
25 | #include
26 | #endif
27 |
28 | struct context {
29 | HWND hwnd;
30 | HGLRC mainGLRC;
31 | bool done;
32 | sciter::sync::event event_draw;
33 | sciter::sync::event event_draw_complete;
34 | };
35 |
36 | void opengl_thread(context* ctx)
37 | {
38 |
39 | HDC hdc = GetDC(ctx->hwnd);
40 | HGLRC hglrc = wglCreateContext(hdc); ;
41 |
42 | wglShareLists(ctx->mainGLRC,hglrc);
43 |
44 | // make it the calling thread's current rendering context
45 | wglMakeCurrent(hdc, hglrc);
46 |
47 | //Set up the orthographic projection so that coordinates (0, 0) are in the top left
48 | //and the minimum and maximum depth is -10 and 10. To enable depth just put in
49 | //glEnable(GL_DEPTH_TEST)
50 | glMatrixMode(GL_PROJECTION);
51 | glLoadIdentity();
52 | glOrtho(0, 640, 480, 0, -10, 10);
53 |
54 | //Back to the modelview so we can draw stuff
55 | glMatrixMode(GL_MODELVIEW);
56 | glLoadIdentity();
57 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Clear the screen and depth buffer
58 |
59 | for(;;) {
60 |
61 | ctx->event_draw.wait();
62 | if(ctx->done)
63 | break;
64 |
65 | wglMakeCurrent(hdc, hglrc); // ?
66 |
67 | //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
68 | glPushMatrix(); //Make sure our transformations don't affect any other transformations in other code
69 | glTranslatef(0, 0, 10); //Translate rectangle to its assigned x and y position
70 | //Put other transformations here
71 | glBegin(GL_QUADS); //We want to draw a quad, i.e. shape with four sides
72 | glColor3f(1, 0, 0); //Set the colour to red
73 | glVertex2f(0, 0); //Draw the four corners of the rectangle
74 | glVertex2f(0, 480);
75 | glVertex2f(640,480);
76 | glVertex2f(640, 0);
77 | glEnd();
78 | glPopMatrix();
79 |
80 | glFlush();
81 |
82 | ctx->event_draw_complete.signal();
83 |
84 | }
85 |
86 | // make the rendering context not current
87 | wglMakeCurrent(NULL, NULL);
88 | // delete the rendering context
89 | wglDeleteContext(hglrc);
90 |
91 | ReleaseDC(ctx->hwnd,hdc);
92 |
93 | //ctx->event_draw_complete.signal();
94 | }
95 |
96 |
97 |
98 | namespace sciter
99 | {
100 | /*
101 | BEHAVIOR: native-clock
102 | - draws content layer using sciter-x-graphics.hpp primitives.
103 |
104 | SAMPLE:
105 | See: samples/behaviors/native-drawing.htm
106 | */
107 |
108 | struct molehill_opengl: public event_handler
109 | {
110 | context* ctx;
111 |
112 | // ctor
113 | molehill_opengl(): ctx(nullptr) {}
114 | virtual ~molehill_opengl() {}
115 |
116 | virtual bool subscription( HELEMENT he, UINT& event_groups )
117 | {
118 | event_groups = HANDLE_DRAW; // it does drawing
119 | return true;
120 | }
121 |
122 | virtual void attached (HELEMENT he )
123 | {
124 | ctx = new context();
125 | ctx->hwnd = dom::element(he).get_element_hwnd(true);
126 | ctx->mainGLRC = wglGetCurrentContext();
127 | sciter::thread(opengl_thread,ctx);
128 | }
129 | virtual void detached (HELEMENT he ) {
130 | ctx->done = true;
131 | ctx->event_draw.signal();
132 | //ctx->event_draw_complete.wait();
133 | //delete ctx;
134 | delete this;
135 | }
136 |
137 | virtual bool handle_draw (HELEMENT he, DRAW_PARAMS& params )
138 | {
139 | if( params.cmd != DRAW_CONTENT ) return false; // drawing only content layer
140 |
141 | ctx->event_draw.signal();
142 | //ctx->event_draw_complete.wait();
143 |
144 | //return false;
145 |
146 | return true; // done drawing
147 |
148 | }
149 |
150 | };
151 |
152 | struct molehill_opengl_factory: public behavior_factory {
153 |
154 | molehill_opengl_factory(): behavior_factory("molehill-opengl") { }
155 |
156 | // the only behavior_factory method:
157 | virtual event_handler* create(HELEMENT he) {
158 | return new molehill_opengl();
159 | }
160 |
161 | };
162 |
163 | // instantiating and attaching it to the global list
164 | molehill_opengl_factory molehill_opengl_factory_instance;
165 |
166 |
167 | }
168 |
--------------------------------------------------------------------------------
/includes/sciter/behaviors/behavior_video_generator.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "sciter-x.h"
3 | #include "sciter-x-behavior.h"
4 | #include "sciter-x-threads.h"
5 | #include "sciter-x-video-api.h"
6 |
7 | namespace sciter
8 | {
9 | /*
10 | BEHAVIOR: video_generated_stream
11 | - provides synthetic video frames.
12 | - this code is here solely for the demo purposes - how
13 | to connect your own video frame stream with the rendering site
14 |
15 | COMMENTS:
16 |
17 | SAMPLE:
18 | See: samples/video/video-generator-behavior.htm
19 | */
20 |
21 | struct video_generated_stream: public event_handler
22 | {
23 | aux::asset_ptr rendering_site;
24 | // ctor
25 | video_generated_stream() {}
26 | virtual ~video_generated_stream() {}
27 |
28 | virtual bool subscription( HELEMENT he, UINT& event_groups )
29 | {
30 | event_groups = HANDLE_BEHAVIOR_EVENT; // we only handle VIDEO_BIND_RQ here
31 | return true;
32 | }
33 |
34 | virtual void attached (HELEMENT he ) {
35 | he = he;
36 | }
37 |
38 | virtual void detached (HELEMENT he ) { delete this; }
39 | virtual bool on_event (HELEMENT he, HELEMENT target, BEHAVIOR_EVENTS type, UINT_PTR reason )
40 | {
41 | if(type != VIDEO_BIND_RQ)
42 | return false;
43 | // we handle only VIDEO_BIND_RQ requests here
44 |
45 | //printf("VIDEO_BIND_RQ %d\n",reason);
46 |
47 | if( !reason )
48 | return true; // first phase, consume the event to mark as we will provide frames
49 |
50 |
51 |
52 | rendering_site = (sciter::video_destination*) reason;
53 | aux::asset_ptr fsite;
54 |
55 | if(rendering_site->get_interface(FRAGMENTED_VIDEO_DESTINATION_INAME,(aux::iasset**)fsite.target()))
56 | {
57 | //start_generation( rendering_site );
58 | sciter::thread(generation_thread,fsite);
59 | }
60 |
61 | return true;
62 | }
63 |
64 | static void generation_thread(sciter::fragmented_video_destination* dst) {
65 | aux::asset_ptr rendering_site = dst;
66 | // simulate video stream
67 | sciter::sync::sleep(100);
68 |
69 | const int VIDEO_WIDTH = 1200;
70 | const int VIDEO_HEIGHT = 800;
71 | const int FRAGMENT_WIDTH = 256;
72 | const int FRAGMENT_HEIGHT = 32;
73 |
74 | srand ((unsigned int)(UINT_PTR)dst);
75 |
76 | // let's pretend that we have 640*480 video frames
77 | rendering_site->start_streaming(VIDEO_WIDTH,VIDEO_HEIGHT,COLOR_SPACE_RGB32);
78 |
79 | unsigned int figure[FRAGMENT_WIDTH*FRAGMENT_HEIGHT];// = {0xFFFF00FF};
80 |
81 | auto generate_fill_color = [&]() {
82 | unsigned color =
83 | 0xff000000 |
84 | ((unsigned(rand()) & 0xff) << 16) |
85 | ((unsigned(rand()) & 0xff) << 8) |
86 | ((unsigned(rand()) & 0xff) << 0);
87 | for( int i = 0; i < FRAGMENT_WIDTH * FRAGMENT_HEIGHT; ++i )
88 | figure[i] = color;
89 | };
90 |
91 | generate_fill_color();
92 |
93 | int xpos = 0;
94 | int ypos = 0;
95 | int stepx = +1;
96 | int stepy = +1;
97 |
98 | while(rendering_site->is_alive())
99 | {
100 | sciter::sync::sleep(40); // simulate 24 FPS rate
101 |
102 | xpos += stepx;
103 | if( xpos < 0 ) { xpos = 0; stepx = -stepx; generate_fill_color(); }
104 | if( xpos >= VIDEO_WIDTH - FRAGMENT_WIDTH) { xpos = VIDEO_WIDTH - FRAGMENT_WIDTH; stepx = -stepx; generate_fill_color(); }
105 |
106 | ypos += stepy;
107 | if( ypos < 0 ) { ypos = 0; stepy = -stepy; generate_fill_color(); }
108 | if( ypos >= VIDEO_HEIGHT - FRAGMENT_HEIGHT ) { ypos = VIDEO_HEIGHT - FRAGMENT_HEIGHT; stepy = -stepy; generate_fill_color(); }
109 |
110 | rendering_site->render_frame_part((const unsigned char*)figure,sizeof(figure),xpos,ypos,FRAGMENT_WIDTH,FRAGMENT_HEIGHT);
111 | }
112 |
113 | }
114 |
115 | };
116 |
117 | struct video_generated_stream_factory: public behavior_factory {
118 |
119 | video_generated_stream_factory(): behavior_factory("video-generator") {
120 |
121 | }
122 |
123 | // the only behavior_factory method:
124 | virtual event_handler* create(HELEMENT he) {
125 | return new video_generated_stream();
126 | }
127 |
128 | };
129 |
130 | // instantiating and attaching it to the global list
131 | video_generated_stream_factory video_generated_stream_factory_instance;
132 |
133 |
134 | }
135 |
--------------------------------------------------------------------------------
/includes/sciter/behaviors/camera/camera-capture.h:
--------------------------------------------------------------------------------
1 |
2 | #pragma once
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include "sciter-x.h"
16 | #include "sciter-x-threads.h"
17 | #include "sciter-x-video-api.h"
18 | #include "aux-asset.h"
19 |
20 | // note mf.dll & friends does not exist on all Windows versions by default
21 |
22 | #pragma comment (lib, "delayimp")
23 | #pragma comment (lib, "mfplat.lib")
24 | #pragma comment (lib, "mf.lib")
25 | #pragma comment (lib, "mfreadwrite.lib")
26 | #pragma comment (lib, "mfuuid.lib")
27 | #pragma comment (lib, "shlwapi.lib")
28 |
29 | //#pragma comment (linker, "/delayload:mf.dll")
30 | //#pragma comment (linker, "/delayload:mfplat.dll")
31 | //#pragma comment (linker, "/delayload:mfreadwrite.dll")
32 | //#pragma comment (linker, "/delayload:shlwapi.dll")
33 |
34 | namespace camera {
35 |
36 | class device_list
37 | {
38 | UINT32 ndevices;
39 | IMFActivate **pp_devices;
40 |
41 | public:
42 | device_list() : pp_devices(NULL), ndevices(0)
43 | {
44 | static bool mf_initialized = false;
45 | if(!mf_initialized) {
46 | // Initialize Media Foundation
47 | MFStartup(MF_VERSION);
48 | mf_initialized = true;
49 | }
50 | }
51 | ~device_list()
52 | {
53 | clear();
54 | }
55 |
56 | unsigned count() const { return ndevices; }
57 |
58 | void clear();
59 | bool enumerate_devices();
60 | bool get_device(unsigned index, com::ptr& pActivate);
61 | bool get_device(const sciter::string& name, com::ptr& pActivate);
62 | bool get_device_name(unsigned index, sciter::string& name);
63 | };
64 |
65 | struct encoding_parameters
66 | {
67 | GUID subtype;
68 | unsigned bitrate;
69 | };
70 |
71 | class capture : public IMFSourceReaderCallback
72 | {
73 | public:
74 | static capture* create_instance(sciter::video_destination* pdst, const sciter::value& source_name_or_index);
75 |
76 | // IUnknown methods
77 | STDMETHODIMP QueryInterface(REFIID iid, void** ppv);
78 | STDMETHODIMP_(ULONG) AddRef();
79 | STDMETHODIMP_(ULONG) Release();
80 |
81 | // IMFSourceReaderCallback methods
82 | STDMETHODIMP OnReadSample(
83 | HRESULT hrStatus,
84 | DWORD dwStreamIndex,
85 | DWORD dwStreamFlags,
86 | LONGLONG llTimestamp,
87 | IMFSample *pSample
88 | );
89 |
90 | STDMETHODIMP OnEvent(DWORD, IMFMediaEvent *)
91 | {
92 | return S_OK;
93 | }
94 |
95 | STDMETHODIMP OnFlush(DWORD)
96 | {
97 | return S_OK;
98 | }
99 |
100 | // methods:
101 |
102 | bool start_capture(IMFActivate *pActivate, const encoding_parameters& param);
103 | bool end_capture();
104 | bool is_capturing();
105 | bool check_device_lost(DEV_BROADCAST_HDR *pHdr, bool& deviceLost);
106 |
107 | protected:
108 |
109 | enum State
110 | {
111 | State_NotReady = 0,
112 | State_Ready,
113 | State_Capturing,
114 | };
115 |
116 | // Constructor is private. Use static CreateInstance method to instantiate.
117 | capture(sciter::video_destination* pdst);
118 |
119 | // Destructor is private. Caller should call Release.
120 | virtual ~capture();
121 |
122 | void NotifyError(HRESULT hr) { /*PostMessage(m_hwndEvent, WM_APP_PREVIEW_ERROR, (WPARAM)hr, 0L);*/ }
123 |
124 | HRESULT OpenMediaSource(IMFMediaSource *pSource);
125 | HRESULT ConfigureCapture(const encoding_parameters& param);
126 |
127 | long m_nRefCount; // Reference count.
128 |
129 | sciter::sync::mutex m_lock;
130 |
131 | com::ptr m_pReader;
132 |
133 | BOOL m_bFirstSample;
134 | LONGLONG m_llBaseTime;
135 |
136 | WCHAR *m_pwszSymbolicLink;
137 |
138 | sciter::COLOR_SPACE m_colorSpace;
139 | unsigned m_width;
140 | unsigned m_height;
141 |
142 | aux::asset_ptr dest;
143 |
144 | };
145 |
146 | }
--------------------------------------------------------------------------------
/includes/sciter/sciter-gtk-main.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // sciter-gtk-main.mm
3 | // sciter
4 | //
5 | // Created by andrew on 2014-12-05.
6 | // Copyright (c) 2014 Andrew Fedoniouk. All rights reserved.
7 | //
8 |
9 | #ifndef SCITER_GTK_MAIN_H
10 | #define SCITER_GTK_MAIN_H
11 |
12 | #include
13 |
14 | #include "sciter-x-window.hpp"
15 |
16 | static std::vector _argv;
17 |
18 | int main (int argc, char *argv[])
19 | {
20 | /* Initialize GTK+ */
21 | g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL);
22 | gtk_init (&argc, &argv);
23 | g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL);
24 |
25 | for( int i = 0; i < argc; ++i ) {
26 | aux::a2w w(argv[i]);
27 | _argv.push_back(sciter::string(w.c_str(),w.length()));
28 | }
29 |
30 | auto message_pump = []() -> int {
31 | gtk_main ();
32 | return 0;
33 | };
34 |
35 | return uimain(message_pump);
36 | }
37 |
38 | namespace sciter {
39 |
40 | GtkWidget* gview(HWINDOW hwnd) { return hwnd; }
41 | GtkWindow* gwindow(HWINDOW hwnd) { return hwnd ? GTK_WINDOW(gtk_widget_get_toplevel(hwnd)): nullptr; }
42 |
43 | namespace application {
44 | HINSTANCE hinstance()
45 | {
46 | return nullptr; // not used
47 | }
48 |
49 | const std::vector& argv() {
50 | return _argv;
51 | }
52 | }
53 |
54 | bool window::load( aux::bytes utf8_html, const WCHAR* base_url)
55 | {
56 | bool val = false;
57 | if(FALSE != SAPI()->SciterLoadHtml(_hwnd,utf8_html.start,utf8_html.length, base_url)){
58 | val = true;
59 | }
60 |
61 | return val;
62 | }
63 | bool window::load( aux::chars utf8_html, const WCHAR* base_url)
64 | {
65 | //return FALSE != SAPI()->SciterLoadHtml(_hwnd,(LPCBYTE)utf8_html.start,utf8_html.length, base_url);
66 |
67 | bool val = false;
68 | if(FALSE != SAPI()->SciterLoadHtml(_hwnd,(LPCBYTE)utf8_html.start,utf8_html.length, base_url)){
69 | val = true;
70 | }
71 |
72 | return val;
73 | }
74 | bool window::load( const WCHAR* url)
75 | {
76 | return FALSE != SAPI()->SciterLoadFile(_hwnd,url);
77 | }
78 |
79 | void window::collapse() {
80 | if(_hwnd) gtk_window_iconify (gwindow(_hwnd));
81 | }
82 | void window::expand( bool maximize) {
83 | if(_hwnd) {
84 | gtk_window_present (gwindow(_hwnd));
85 | gtk_window_set_keep_below(gwindow(_hwnd), true);
86 | }
87 | }
88 |
89 | void window::dismiss() {
90 | if(_hwnd) gtk_window_close (gwindow(_hwnd));
91 | _hwnd = 0; //?
92 | }
93 |
94 | window::window( UINT creationFlags, RECT frame): _hwnd(NULL)
95 | {
96 | _hwnd = SAPI()->SciterCreateWindow(creationFlags, (frame.right - frame.left) > 0 ? &frame: NULL,NULL,this,NULL);
97 | if( _hwnd ) {
98 | add_ref();
99 | setup_callback();
100 | sciter::attach_dom_event_handler(get_hwnd(),this);
101 | }
102 | }
103 |
104 | }
105 |
106 | #endif
107 |
--------------------------------------------------------------------------------
/includes/sciter/sciter-osx-main.mm:
--------------------------------------------------------------------------------
1 | //
2 | // sciter-osx-main.mm
3 | // sciter
4 | //
5 | // Created by andrew on 2014-03-23.
6 | // Copyright (c) 2014 andrew fedoniouk. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | #include "sciter-x-window.hpp"
13 |
14 |
15 | static std::vector _argv;
16 |
17 | #ifndef SKIP_MAIN
18 |
19 | int main(int argc, const char * argv[])
20 | {
21 | NSApplication * application = [NSApplication sharedApplication];
22 |
23 | for( int i = 0; i < argc; ++i ) {
24 | aux::a2w w(argv[i]);
25 | _argv.push_back(sciter::string(w.c_str(),w.length()));
26 | }
27 |
28 | auto message_pump = [&]() -> int {
29 | [application run];
30 | return 0;
31 | };
32 |
33 | return uimain(message_pump);
34 |
35 | //auto message_pump = [&]() -> int {
36 | // return NSApplicationMain(argc,argv);
37 | //};
38 | //return uimain(message_pump);
39 | }
40 | #endif
41 |
42 | namespace sciter {
43 |
44 | NSView* nsview(HWINDOW hwnd) { return (__bridge NSView*) hwnd; }
45 | NSWindow* nswindow(HWINDOW hwnd) { return hwnd ? [nsview(hwnd) window]:nullptr; }
46 |
47 | namespace application {
48 | HINSTANCE hinstance()
49 | {
50 | return nullptr; // not used
51 | }
52 |
53 | const std::vector& argv() {
54 | return _argv;
55 | }
56 |
57 | }
58 |
59 |
60 | bool window::load( aux::bytes utf8_html, const WCHAR* base_url)
61 | {
62 | return FALSE != ::SciterLoadHtml(_hwnd,utf8_html.start,utf8_html.length, base_url);
63 | }
64 | bool window::load( aux::chars utf8_html, const WCHAR* base_url)
65 | {
66 | return FALSE != ::SciterLoadHtml(_hwnd,(LPCBYTE)utf8_html.start,utf8_html.length, base_url);
67 | }
68 | bool window::load( const WCHAR* url)
69 | {
70 | return FALSE != ::SciterLoadFile(_hwnd,url);
71 | }
72 |
73 | void window::collapse() {
74 | if(_hwnd) [nswindow(_hwnd) performMiniaturize:nsview(_hwnd)];
75 | }
76 | void window::expand( bool maximize) {
77 | if(_hwnd) [nswindow(_hwnd) makeKeyAndOrderFront:nil];
78 | }
79 |
80 | void window::dismiss() {
81 | if(_hwnd) [nswindow(_hwnd) close];
82 | _hwnd = 0;
83 | }
84 |
85 | window::window( UINT creationFlags, RECT frame): _hwnd(NULL)
86 | {
87 | _hwnd = ::SciterCreateWindow(creationFlags, (frame.right - frame.left) > 0 ? &frame: NULL,NULL,this,NULL);
88 | if( _hwnd ) {
89 | add_ref();
90 | setup_callback();
91 | sciter::attach_dom_event_handler(get_hwnd(),this);
92 | }
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/includes/sciter/sciter-win-main.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 |
3 | #include
4 |
5 | #include "sciter-x-window.hpp"
6 |
7 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
8 | // Windows Header Files:
9 | #include
10 |
11 | HINSTANCE ghInstance = 0;
12 |
13 | #ifndef SKIP_MAIN
14 |
15 | int APIENTRY wWinMain(HINSTANCE hInstance,
16 | HINSTANCE hPrevInstance,
17 | LPWSTR lpCmdLine,
18 | int nCmdShow)
19 | {
20 | ghInstance = hInstance;
21 | UNREFERENCED_PARAMETER(hPrevInstance);
22 | UNREFERENCED_PARAMETER(lpCmdLine);
23 | UNREFERENCED_PARAMETER(nCmdShow);
24 |
25 | OleInitialize(0); // for system drag-n-drop
26 |
27 | // comment this out if you need system theming
28 | ::SciterSetOption(NULL,SCITER_SET_UX_THEMING,TRUE);
29 |
30 | auto message_pump = []() -> int {
31 | MSG msg;
32 | // Main message loop:
33 | while (GetMessage(&msg, NULL, 0, 0))
34 | {
35 | TranslateMessage(&msg);
36 | DispatchMessage(&msg);
37 | }
38 | return (int) msg.wParam;
39 | };
40 |
41 | int r = uimain(message_pump);
42 |
43 | OleUninitialize();
44 |
45 | return r;
46 |
47 | }
48 |
49 | #endif
50 | namespace sciter {
51 |
52 | namespace application
53 | {
54 | const std::vector& argv() {
55 | static std::vector _argv;
56 | if( _argv.size() == 0 ) {
57 | int argc = 0;
58 | LPWSTR *arglist = CommandLineToArgvW(GetCommandLineW(), &argc);
59 | if( !arglist )
60 | return _argv;
61 | for( int i = 0; i < argc; ++i)
62 | _argv.push_back(arglist[i]);
63 | LocalFree(arglist);
64 | }
65 | return _argv;
66 | }
67 |
68 | HINSTANCE hinstance() {
69 | return ghInstance;
70 | }
71 | }
72 |
73 | bool window::load( aux::bytes utf8_html, const WCHAR* base_url)
74 | {
75 | return FALSE != ::SciterLoadHtml(_hwnd,utf8_html.start,utf8_html.length, base_url);
76 | }
77 | bool window::load( aux::chars utf8_html, const WCHAR* base_url)
78 | {
79 | return FALSE != ::SciterLoadHtml(_hwnd,(LPCBYTE)utf8_html.start,utf8_html.length, base_url);
80 | }
81 | bool window::load( const WCHAR* url)
82 | {
83 | return FALSE != ::SciterLoadFile(_hwnd,url);
84 | }
85 |
86 | LRESULT window::on_message( HWINDOW hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL& pHandled )
87 | {
88 | //switch(msg) {
89 | // case WM_SIZE: on_size(); break;
90 | // case WM_MOVE: on_move(); break;
91 | //}
92 | return 0;
93 | }
94 |
95 | LRESULT SC_CALLBACK window::msg_delegate(HWINDOW hwnd, UINT msg, WPARAM wParam, LPARAM lParam, LPVOID pParam, BOOL* pHandled)
96 | {
97 | window* win = static_cast( pParam );
98 | return win->on_message( hwnd, msg, wParam, lParam,*pHandled);
99 | }
100 |
101 | void window::collapse() {
102 | if(_hwnd) ::ShowWindow(_hwnd, SW_MINIMIZE );
103 | }
104 | void window::expand( bool maximize) {
105 | if(_hwnd) ::ShowWindow(_hwnd, maximize? SW_MAXIMIZE :SW_NORMAL );
106 | }
107 | void window::dismiss() {
108 | if(_hwnd) ::PostMessage(_hwnd, WM_CLOSE, 0, 0 );
109 | }
110 |
111 | window::window( UINT creationFlags, RECT frame): _hwnd(NULL)
112 | {
113 | _hwnd = ::SciterCreateWindow(creationFlags,&frame,&msg_delegate,this,NULL);
114 | if( _hwnd ) {
115 | add_ref();
116 | setup_callback();
117 | sciter::attach_dom_event_handler(get_hwnd(),this);
118 | }
119 | }
120 |
121 | }
122 |
123 |
--------------------------------------------------------------------------------
/includes/sciter/sciter-x-debug.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The Sciter Engine of Terra Informatica Software, Inc.
3 | * http://sciter.com
4 | *
5 | * The code and information provided "as-is" without
6 | * warranty of any kind, either expressed or implied.
7 | *
8 | * (C) 2003-2015, Terra Informatica Software, Inc.
9 | */
10 |
11 | #ifndef __SCITER_X_DEBUG_H__
12 | #define __SCITER_X_DEBUG_H__
13 |
14 | //|
15 | //| Sciter Inspector/Debug API
16 | //|
17 |
18 | #include "sciter-x-api.h"
19 |
20 | inline VOID SCAPI SciterSetupDebugOutput ( HWINDOW hwndOrNull, LPVOID param, DEBUG_OUTPUT_PROC pfOutput) { return SAPI()->SciterSetupDebugOutput ( hwndOrNull,param,pfOutput); }
21 |
22 | #if defined(__cplusplus) && !defined( PLAIN_API_ONLY )
23 |
24 | namespace sciter
25 | {
26 |
27 | struct debug_output
28 | {
29 | debug_output(HWINDOW hwnd = 0)
30 | {
31 | setup_on(hwnd);
32 | }
33 |
34 | void setup_on(HWINDOW hwnd = 0)
35 | {
36 | ::SciterSetupDebugOutput(hwnd,this,_output_debug);
37 | }
38 |
39 | static VOID SC_CALLBACK _output_debug(LPVOID param, UINT subsystem, UINT severity, LPCWSTR text, UINT text_length)
40 | {
41 | static_cast(param)->output((OUTPUT_SUBSYTEMS)subsystem,(OUTPUT_SEVERITY)severity, (const WCHAR*)text,text_length);
42 | }
43 | virtual void output( OUTPUT_SUBSYTEMS subsystem, OUTPUT_SEVERITY severity, const WCHAR* text, unsigned int text_length )
44 | {
45 | switch(severity)
46 | {
47 | case OS_INFO : print("info:"); break;
48 | case OS_WARNING : print("warning:"); break;
49 | case OS_ERROR : print("error:"); break;
50 | }
51 | switch(subsystem)
52 | {
53 | case OT_DOM: print("DOM: "); break;
54 | case OT_CSSS: print("csss!: "); break;
55 | case OT_CSS: print("css: "); break;
56 | case OT_TIS: print("script: "); break;
57 | }
58 | if(text[text_length])
59 | {
60 | //unsigned n = wcslen(text);
61 | assert(false);
62 | }
63 | else
64 | print(text);
65 | }
66 | #if defined(WINDOWS)
67 | virtual void print(const WCHAR* text) { OutputDebugStringW(text); }
68 | virtual void print(const char* text) { OutputDebugStringA(text); }
69 | #elif defined(OSX) || defined(LINUX)
70 | virtual void print(const WCHAR* text) { std::cout << aux::w2a(text).c_str(); }
71 | virtual void print(const char* text) { std::cout << text; }
72 | #endif
73 |
74 | void printf( const char* fmt, ... )
75 | {
76 | char buffer [ 2049 ];
77 | va_list args;
78 | va_start ( args, fmt );
79 | int len = vsnprintf( buffer, sizeof(buffer), fmt, args );
80 | va_end ( args );
81 | buffer [ len ] = 0;
82 | buffer [ 2048 ] = 0;
83 | print(buffer);
84 | }
85 |
86 | /* void printf( const WCHAR* fmt, ... )
87 | {
88 | WCHAR buffer [ 2049 ];
89 | va_list args;
90 | va_start ( args, fmt );
91 | #if defined(WINDOWS)
92 | int len = vswprintf_s( buffer, fmt, args );
93 | #elif defined(OSX)
94 | int len = vswprintf( buffer, 2048, fmt, args );
95 | #endif
96 | va_end ( args );
97 | buffer [ len ] = 0;
98 | buffer [ 2048 ] = 0;
99 | print(buffer);
100 | } */
101 |
102 |
103 | };
104 |
105 | struct debug_output_console: public debug_output
106 | {
107 |
108 | #ifdef _WIN32_WCE
109 | FILE *f;
110 | ~debug_output_console()
111 | {
112 | fclose(f);
113 | }
114 | #endif
115 | debug_output_console():debug_output()
116 | {
117 | #ifdef _WINCE32_WCE
118 | f = 0;
119 | #endif
120 | }
121 | #if !defined(_WIN32_WCE)
122 | virtual void print(const WCHAR* text) /*override*/
123 | {
124 | print(aux::w2oem(text));
125 | }
126 | virtual void print(const char* text) /*override*/
127 | {
128 | #if defined(WINDOWS)
129 | static bool initialized = false;
130 | if(!initialized)
131 | {
132 | AllocConsole();
133 | #pragma warning( push )
134 | #pragma warning(disable:4996)
135 | freopen("conin$", "r", stdin);
136 | freopen("conout$", "w", stdout);
137 | freopen("conout$", "w", stderr);
138 | #pragma warning( pop )
139 | initialized = true;
140 | }
141 | #endif
142 | while(text && *text) {
143 | char c = *text++;
144 | if(c == '\r')
145 | putchar('\n');
146 | else
147 | putchar(c);
148 | }
149 | }
150 | #else
151 | virtual void print(const WCHAR* text) /*override*/
152 | {
153 | if( !f )
154 | f = fopen("\\mosciter.log", "wb");
155 | fputws(text, f);
156 | }
157 | virtual void print(const char* text) /*override*/
158 | {
159 | if( !f )
160 | f = fopen("\\mosciter.log", "wb");
161 | fputs(text, f);
162 | }
163 | #endif
164 | };
165 | }
166 |
167 | #endif
168 |
169 | #endif
170 |
--------------------------------------------------------------------------------
/includes/sciter/sciter-x-lite.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * The Sciter Engine of Terra Informatica Software, Inc.
3 | * http://sciter.com
4 | *
5 | * The code and information provided "as-is" without
6 | * warranty of any kind, either expressed or implied.
7 | *
8 | * (C) 2003-2015, Terra Informatica Software, Inc.
9 | */
10 |
11 | /*
12 | * Sciter windowless engine instance
13 | *
14 | * !!!! NOT READY YET !!!!
15 | */
16 |
17 |
18 | #ifndef __sciter_lite_hpp__
19 | #define __sciter_lite_hpp__
20 |
21 | #include "aux-asset.h"
22 | #include "aux-slice.h"
23 | #include "sciter-x.h"
24 | #include "sciter-x-dom.hpp"
25 |
26 | namespace sciter
27 | {
28 |
29 | //|
30 | //| "windowless" sciter engine API
31 | //|
32 |
33 | class scilite;
34 | class scilite_host;
35 |
36 | // Create scilite, will use internal bitmap buffer
37 | BOOL SCAPI SciliteCreate(scilite** out, scilite_host* in);
38 |
39 | #ifdef SCILITE_USE_D2D
40 | BOOL SCAPI SciliteCreateOnD2DRenderingTarget(scilite** out, scilite_host* in, ID2D1RenderTarget *pRT, ID2D1Factory* pDF, IDWriteFactory* pDWF = 0 );
41 | #endif
42 | #ifdef SCILITE_USE_GDIPLUS
43 | BOOL SCAPI SciliteCreateOnGDIPPGraphics(scilite** out, scilite_host* in,Gdiplus::Graphics* pGfx);
44 | #endif
45 | #ifdef SCILITE_USE_COREGRAPHICS
46 | BOOL SCAPI SciliteCreateOnGDIPPGraphics(scilite** out, scilite_host* in,CGContextRef pGfx);
47 | #endif
48 | #ifdef SCILITE_USE_CAIRO
49 | BOOL SCAPI SciliteCreateOnCairoGraphics(scilite** out, scilite_host* in, cairo_t *cr);
50 | #endif
51 |
52 | #define SCILITE_INAME "scilite.sciter.com"
53 |
54 |
55 | //|
56 | //| that is windowless sciter engine per se
57 | //|
58 |
59 | class scilite: public aux::iasset
60 | {
61 | public:
62 |
63 | virtual bool load_html(LPCBYTE html, UINT html_length, LPCWSTR base_url) = 0;
64 | virtual bool load_file(LPCWSTR base_url) = 0;
65 |
66 | virtual HELEMENT root_element() = 0;
67 |
68 | virtual bool document_min_width(int& width);
69 | virtual bool document_min_height(int& height, int for_width);
70 | virtual bool set_dimensions(int width, int height);
71 |
72 | virtual bool accept_url_data(LPCWSTR url, LPCBYTE data, UINT data_size, LPVOID request_id) = 0;
73 |
74 | virtual bool traverse_mouse_event( UINT mouse_cmd, POINT pt, UINT buttons, UINT alt_state ) = 0;
75 | virtual bool traverse_keyboard_event( UINT mouse_cmd, POINT pt, UINT buttons, UINT alt_state ) = 0;
76 | virtual bool traverse_focus_event( UINT focus_cmd ) = 0;
77 | virtual bool traverse_timer_event( UINT_PTR timer_id ) = 0;
78 |
79 | virtual bool get_invalid_area( RECT& rc_invalid ) = 0;
80 |
81 | };
82 |
83 | #define SCILITE_HOST_INAME "host.scilite.sciter.com"
84 |
85 | //|
86 | //| scilite outbound interface
87 | //|
88 | class scilite_host: public aux::asset
89 | {
90 | public:
91 | virtual bool get_interface(const char* name, iasset** out)
92 | {
93 | if( aux::streq(name,SCILITE_HOST_INAME) ) { this->add_ref(); *out = this; return true; }
94 | return scilite_host::get_interface(name,out);
95 | }
96 |
97 | virtual bool load_data(LPSCN_LOAD_DATA data_rq, bool& discard) = 0;
98 | virtual bool data_loaded(LPSCN_DATA_LOADED data) = 0;
99 | virtual bool attach_behavior(LPSCN_ATTACH_BEHAVIOR data) = 0;
100 |
101 | virtual bool set_timer(UINT_PTR tid, UINT elapse_time, bool should_be_precise ) = 0;
102 | virtual bool set_cursor(UINT cursor_id ) = 0;
103 |
104 | virtual bool start_drawing(RECT rc) = 0;
105 | virtual bool end_drawing() = 0;
106 |
107 | };
108 |
109 | }
110 |
111 | #endif
--------------------------------------------------------------------------------
/includes/sciter/sciter-x-msg.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The Sciter Engine of Terra Informatica Software, Inc.
3 | * http://sciter.com
4 | *
5 | * The code and information provided "as-is" without
6 | * warranty of any kind, either expressed or implied.
7 | *
8 | * (C) Terra Informatica Software, Inc.
9 | */
10 |
11 | /*
12 | * Message definitions to be passed to SciterProcX function
13 | */
14 |
15 |
16 | #ifndef __sciter_x_msg_h__
17 | #define __sciter_x_msg_h__
18 |
19 | #include "sciter-x-types.h"
20 | #include "sciter-x-def.h"
21 |
22 | /** #SCITER_X_MSG_CODE message/function identifier */
23 | enum SCITER_X_MSG_CODE {
24 | SXM_CREATE = 0,
25 | SXM_DESTROY = 1,
26 | SXM_SIZE = 2,
27 | SXM_PAINT = 3,
28 | };
29 |
30 | /** #SCITER_X_MSG common header of message structures passed to SciterProcX */
31 | struct SCITER_X_MSG
32 | {
33 | UINT msg; /**< [in] one of the codes of #SCITER_X_MSG_CODE.*/
34 | #ifdef __cplusplus
35 | SCITER_X_MSG(UINT m) : msg(m) {}
36 | #endif
37 | };
38 |
39 | struct SCITER_X_MSG_CREATE
40 | {
41 | SCITER_X_MSG header;
42 | UINT backend;
43 | BOOL transparent;
44 | #ifdef __cplusplus
45 | SCITER_X_MSG_CREATE(UINT backendType = GFX_LAYER_SKIA_OPENGL, BOOL isTransparent = TRUE )
46 | : header(SXM_CREATE), backend(backendType), transparent(isTransparent) {}
47 | #endif
48 | };
49 |
50 | struct SCITER_X_MSG_DESTROY {
51 | SCITER_X_MSG header;
52 | #ifdef __cplusplus
53 | SCITER_X_MSG_DESTROY() : header(SXM_DESTROY) {}
54 | #endif
55 | };
56 |
57 | struct SCITER_X_MSG_SIZE {
58 | SCITER_X_MSG header;
59 | UINT width;
60 | UINT height;
61 | #ifdef __cplusplus
62 | SCITER_X_MSG_SIZE(UINT w, UINT h) : header(SXM_SIZE), width(w), height(h) {}
63 | #endif
64 | };
65 |
66 |
67 | /** #ELEMENT_BITMAP_RECEIVER - callback function that receives pointer to pixmap and location
68 | * \param[in] bgra \b LPCBYTE, pointer to BGRA bitmap, number of bytes = width * height * 4
69 | * \param[in] x \b INT, position of the bitmap on elements window.
70 | * \param[in] y \b INT, position of the bitmap on elements window.
71 | * \param[in] width \b UINT, width of bitmap (and element's shape).
72 | * \param[in] height \b UINT, height of bitmap (and element's shape).
73 | * \param[in] param \b LPVOID, param that passed as SCITER_X_MSG_PAINT::receiver::param .
74 | **/
75 | typedef VOID SC_CALLBACK ELEMENT_BITMAP_RECEIVER(LPCBYTE rgba, INT x, INT y, UINT width, UINT height, LPVOID param);
76 |
77 | /** #SCITER_X_MSG_CODE message/function identifier */
78 | enum SCITER_PAINT_TARGET_TYPE {
79 | SPT_DEFAULT = 0, /**< default rendering target - window surface */
80 | SPT_RECEIVER = 1, /**< target::receiver fields are valid */
81 | SPT_DC = 2, /**< target::dc is valid */
82 | // ...
83 | };
84 |
85 | struct SCITER_X_MSG_PAINT {
86 | SCITER_X_MSG header;
87 | HELEMENT element; /**< [in] layer #HELEMENT, can be NULL if whole tree (document) needs to be rendered.*/
88 | BOOL isFore; /**< [in] if element is not null tells if that element is fore-layer.*/
89 | UINT targetType; /**< [in] one of #SCITER_PAINT_TARGET_TYPE values */
90 | union {
91 | HDC hdc;
92 | struct {
93 | VOID* param;
94 | ELEMENT_BITMAP_RECEIVER* callback;
95 | } receiver;
96 | } target;
97 |
98 | #ifdef __cplusplus
99 | SCITER_X_MSG_PAINT(HELEMENT layerElement = NULL, BOOL foreLayer = TRUE) : header(SXM_PAINT), element(layerElement), isFore(foreLayer), targetType(SPT_DEFAULT) {}
100 | #endif
101 | };
102 |
103 |
104 |
105 | #endif
106 |
107 |
108 |
--------------------------------------------------------------------------------
/includes/sciter/sciter-x-request.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The Sciter Engine of Terra Informatica Software, Inc.
3 | * http://sciter.com
4 | *
5 | * The code and information provided "as-is" without
6 | * warranty of any kind, either expressed or implied.
7 | *
8 | * (C) Terra Informatica Software, Inc.
9 | */
10 |
11 | /*
12 | * Sciter's get resource request object - represents requests made by Element/View.request() functions.
13 | *
14 | */
15 |
16 |
17 | #ifndef __sciter_request_h__
18 | #define __sciter_request_h__
19 |
20 | #include "sciter-x-types.h"
21 |
22 | #if defined(__cplusplus)
23 | namespace html
24 | {
25 | struct request;
26 | }
27 | typedef html::request* HREQUEST;
28 | #else
29 | typedef void* HREQUEST;
30 | #endif
31 |
32 | enum REQUEST_RESULT
33 | {
34 | REQUEST_PANIC = -1, // e.g. not enough memory
35 | REQUEST_OK = 0,
36 | REQUEST_BAD_PARAM = 1, // bad parameter
37 | REQUEST_FAILURE = 2, // operation failed, e.g. index out of bounds
38 | REQUEST_NOTSUPPORTED = 3 // the platform does not support requested feature
39 | };
40 |
41 | enum REQUEST_RQ_TYPE
42 | {
43 | RRT_GET = 1,
44 | RRT_POST = 2,
45 | RRT_PUT = 3,
46 | RRT_DELETE = 4,
47 |
48 | RRT_FORCE_DWORD = 0xffffffff
49 | };
50 |
51 | typedef enum SciterResourceType
52 | {
53 | RT_DATA_HTML = 0,
54 | RT_DATA_IMAGE = 1,
55 | RT_DATA_STYLE = 2,
56 | RT_DATA_CURSOR = 3,
57 | RT_DATA_SCRIPT = 4,
58 | RT_DATA_RAW = 5,
59 | RT_DATA_FONT,
60 | RT_DATA_SOUND, // wav bytes
61 | RT_DATA_FORCE_DWORD = 0xffffffff
62 | } SciterResourceType;
63 |
64 | enum REQUEST_STATE
65 | {
66 | RS_PENDING = 0,
67 | RS_SUCCESS = 1, // completed successfully
68 | RS_FAILURE = 2, // completed with failure
69 |
70 | RS_FORCE_DWORD = 0xffffffff
71 | };
72 |
73 | struct SciterRequestAPI
74 | {
75 | // a.k.a AddRef()
76 | REQUEST_RESULT
77 | SCFN(RequestUse)( HREQUEST rq );
78 |
79 | // a.k.a Release()
80 | REQUEST_RESULT
81 | SCFN(RequestUnUse)( HREQUEST rq );
82 |
83 | // get requested URL
84 | REQUEST_RESULT
85 | SCFN(RequestUrl)( HREQUEST rq, LPCSTR_RECEIVER* rcv, LPVOID rcv_param );
86 |
87 | // get real, content URL (after possible redirection)
88 | REQUEST_RESULT
89 | SCFN(RequestContentUrl)( HREQUEST rq, LPCSTR_RECEIVER* rcv, LPVOID rcv_param );
90 |
91 | // get requested data type
92 | REQUEST_RESULT
93 | SCFN(RequestGetRequestType)( HREQUEST rq, REQUEST_RQ_TYPE* pType );
94 |
95 | // get requested data type
96 | REQUEST_RESULT
97 | SCFN(RequestGetRequestedDataType)( HREQUEST rq, SciterResourceType* pData );
98 |
99 | // get received data type, string, mime type
100 | REQUEST_RESULT
101 | SCFN(RequestGetReceivedDataType)( HREQUEST rq, LPCSTR_RECEIVER* rcv, LPVOID rcv_param );
102 |
103 |
104 | // get number of request parameters passed
105 | REQUEST_RESULT
106 | SCFN(RequestGetNumberOfParameters)( HREQUEST rq, UINT* pNumber );
107 |
108 | // get nth request parameter name
109 | REQUEST_RESULT
110 | SCFN(RequestGetNthParameterName)( HREQUEST rq, UINT n, LPCWSTR_RECEIVER* rcv, LPVOID rcv_param );
111 |
112 | // get nth request parameter value
113 | REQUEST_RESULT
114 | SCFN(RequestGetNthParameterValue)( HREQUEST rq, UINT n, LPCWSTR_RECEIVER* rcv, LPVOID rcv_param );
115 |
116 | // get request times , ended - started = milliseconds to get the requst
117 | REQUEST_RESULT
118 | SCFN(RequestGetTimes)( HREQUEST rq, UINT* pStarted, UINT* pEnded );
119 |
120 | // get number of request headers
121 | REQUEST_RESULT
122 | SCFN(RequestGetNumberOfRqHeaders)( HREQUEST rq, UINT* pNumber );
123 |
124 | // get nth request header name
125 | REQUEST_RESULT
126 | SCFN(RequestGetNthRqHeaderName)( HREQUEST rq, UINT n, LPCWSTR_RECEIVER* rcv, LPVOID rcv_param );
127 |
128 | // get nth request header value
129 | REQUEST_RESULT
130 | SCFN(RequestGetNthRqHeaderValue)( HREQUEST rq, UINT n, LPCWSTR_RECEIVER* rcv, LPVOID rcv_param );
131 |
132 | // get number of response headers
133 | REQUEST_RESULT
134 | SCFN(RequestGetNumberOfRspHeaders)( HREQUEST rq, UINT* pNumber );
135 |
136 | // get nth response header name
137 | REQUEST_RESULT
138 | SCFN(RequestGetNthRspHeaderName)( HREQUEST rq, UINT n, LPCWSTR_RECEIVER* rcv, LPVOID rcv_param );
139 |
140 | // get nth response header value
141 | REQUEST_RESULT
142 | SCFN(RequestGetNthRspHeaderValue)( HREQUEST rq, UINT n, LPCWSTR_RECEIVER* rcv, LPVOID rcv_param );
143 |
144 | // get completion status (CompletionStatus - http response code : 200, 404, etc.)
145 | REQUEST_RESULT
146 | SCFN(RequestGetCompletionStatus)( HREQUEST rq, REQUEST_STATE* pState, UINT* pCompletionStatus );
147 |
148 | // get proxy host
149 | REQUEST_RESULT
150 | SCFN(RequestGetProxyHost)( HREQUEST rq, LPCSTR_RECEIVER* rcv, LPVOID rcv_param );
151 |
152 | // get proxy port
153 | REQUEST_RESULT
154 | SCFN(RequestGetProxyPort)( HREQUEST rq, UINT* pPort );
155 |
156 | // mark reequest as complete with status and data
157 | REQUEST_RESULT
158 | SCFN(RequestSetSucceeded)( HREQUEST rq, UINT status, LPCBYTE dataOrNull, UINT dataLength);
159 |
160 | // mark reequest as complete with failure and optional data
161 | REQUEST_RESULT
162 | SCFN(RequestSetFailed)( HREQUEST rq, UINT status, LPCBYTE dataOrNull, UINT dataLength );
163 |
164 | // append received data chunk
165 | REQUEST_RESULT
166 | SCFN(RequestAppendDataChunk)( HREQUEST rq, LPCBYTE data, UINT dataLength );
167 |
168 | // set request header (single item)
169 | REQUEST_RESULT
170 | SCFN(RequestSetRqHeader)( HREQUEST rq, LPCWSTR name, LPCWSTR value );
171 |
172 | // set respone header (single item)
173 | REQUEST_RESULT
174 | SCFN(RequestSetRspHeader)( HREQUEST rq, LPCWSTR name, LPCWSTR value );
175 |
176 | // get received (so far) data
177 | REQUEST_RESULT
178 | SCFN(RequestGetData)( HREQUEST rq, LPCBYTE_RECEIVER* rcv, LPVOID rcv_param );
179 |
180 | };
181 |
182 | typedef struct SciterRequestAPI* LPSciterRequestAPI;
183 |
184 | #endif
185 |
--------------------------------------------------------------------------------
/includes/sciter/sciter-x-request.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * The Sciter Engine of Terra Informatica Software, Inc.
3 | * http://sciter.com
4 | *
5 | * The code and information provided "as-is" without
6 | * warranty of any kind, either expressed or implied.
7 | *
8 | * (C) Terra Informatica Software, Inc.
9 | */
10 |
11 | /*
12 | * Sciter's get resource request object - represents requests made by Element/View.request() functions.
13 | *
14 | *
15 | * C++ wrapper
16 | */
17 |
18 |
19 | #ifndef __sciter_request_hpp__
20 | #define __sciter_request_hpp__
21 |
22 | #include "sciter-x-request.h"
23 | #include "sciter-x-api.h"
24 |
25 | #if defined(__cplusplus) && !defined( PLAIN_API_ONLY )
26 |
27 | #include "aux-slice.h"
28 |
29 | namespace sciter
30 | {
31 |
32 | inline VOID SC_CALLBACK _LPCWSTR2STRING( LPCWSTR str, UINT str_length, LPVOID param )
33 | {
34 | sciter::string* s = (sciter::string*)param;
35 | *s = sciter::string(str,str_length);
36 | }
37 | inline VOID SC_CALLBACK _LPCSTR2STRING( LPCSTR str, UINT str_length, LPVOID param )
38 | {
39 | sciter::astring* s = (sciter::astring*)param;
40 | *s = sciter::astring(str,str_length);
41 | }
42 |
43 |
44 | /* struct writer
45 | {
46 | virtual bool write( aux::bytes data ) = 0; // redefine to do actual writing of data.start/data.length
47 | static BOOL SCAPI image_write_function(LPVOID prm, const BYTE* data, UINT data_length)
48 | {
49 | writer* pw = (writer* )prm;
50 | return pw->write( aux::bytes(data,data_length) );
51 | }
52 | }; */
53 |
54 | class request
55 | {
56 | protected:
57 | HREQUEST hrq;
58 |
59 | request(): hrq(0) { ; }
60 |
61 | public:
62 |
63 | request(HREQUEST h): hrq(h) { if(hrq) rapi()->RequestUse(hrq); }
64 | request(const request& im): hrq(im.hrq) { if(hrq) rapi()->RequestUse(hrq); }
65 | request& operator = (const request& im)
66 | {
67 | if(hrq) rapi()->RequestUnUse(hrq);
68 | hrq = im.hrq; rapi()->RequestUse(hrq);
69 | return *this;
70 | }
71 |
72 | bool is_valid() const { return hrq != 0; }
73 |
74 | ~request() {
75 | rapi()->RequestUnUse( hrq );
76 | }
77 |
78 | sciter::astring url() {
79 | sciter::astring rv;
80 | rapi()->RequestUrl( hrq, _LPCSTR2STRING, &rv );
81 | return rv;
82 | }
83 |
84 | sciter::astring content_url() {
85 | sciter::astring rv;
86 | rapi()->RequestContentUrl( hrq, _LPCSTR2STRING, &rv );
87 | return rv;
88 | }
89 |
90 | SciterResourceType requested_type() {
91 | SciterResourceType rv = SciterResourceType();
92 | rapi()->RequestGetRequestedDataType( hrq, &rv );
93 | return rv;
94 | }
95 |
96 | void succeeded( UINT status, LPCBYTE dataOrNull = NULL, UINT dataLength = 0 )
97 | {
98 | rapi()->RequestSetSucceeded( hrq, status, dataOrNull, dataLength);
99 | }
100 |
101 | void failed( UINT status, LPCBYTE dataOrNull = NULL, UINT dataLength = 0 )
102 | {
103 | rapi()->RequestSetFailed( hrq, status, dataOrNull, dataLength);
104 | }
105 |
106 | void append_data( LPCBYTE data, UINT dataLength)
107 | {
108 | rapi()->RequestAppendDataChunk( hrq, data, dataLength);
109 | }
110 |
111 | };
112 |
113 | }
114 |
115 | #endif //defined(__cplusplus) && !defined( PLAIN_API_ONLY )
116 |
117 |
118 | #endif
119 |
120 |
--------------------------------------------------------------------------------
/includes/sciter/sciter-x-script.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The Sciter Engine of Terra Informatica Software, Inc.
3 | * http://sciter.com
4 | *
5 | * The code and information provided "as-is" without
6 | * warranty of any kind, either expressed or implied.
7 | *
8 | * (C) 2003-2015, Terra Informatica Software, Inc.
9 | */
10 |
11 | /*
12 | * Main include file of Sciter script primitives.
13 | */
14 |
15 |
16 | #ifndef __sciter_x_scripting_h__
17 | #define __sciter_x_scripting_h__
18 |
19 | #include "sciter-x.h"
20 | #include "sciter-x-value.h"
21 | #include "tiscript.h"
22 |
23 | typedef tiscript_VM* HVM;
24 |
25 | #if defined(__cplusplus) && !defined( PLAIN_API_ONLY )
26 | #include "tiscript.hpp"
27 | namespace sciter
28 | {
29 | inline SCITER_VALUE v2v(tiscript::VM* vm, tiscript::value val, bool isolate = true)
30 | {
31 | SCITER_VALUE v;
32 | BOOL r = Sciter_v2V(vm,val,(VALUE*)&v, BOOL(isolate));
33 | assert(r); r;
34 | return v;
35 | }
36 | inline tiscript::value v2v(tiscript::VM* vm, const SCITER_VALUE& val)
37 | {
38 | tiscript::value v;
39 | BOOL r = Sciter_V2v(vm,(const VALUE*)&val,&v);
40 | assert(r); r;
41 | return v;
42 | }
43 | }
44 | #endif
45 |
46 |
47 | #endif
48 |
--------------------------------------------------------------------------------
/includes/sciter/sciter-x-value.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The Sciter Engine of Terra Informatica Software, Inc.
3 | * http://sciter.com
4 | *
5 | * The code and information provided "as-is" without
6 | * warranty of any kind, either expressed or implied.
7 | *
8 | * (C) 2003-2015, Terra Informatica Software, Inc.
9 | */
10 |
11 | /*
12 | * sciter::value, aka variant, aka discriminated union
13 | */
14 |
15 |
16 | #ifndef __sciter_x_value_h__
17 | #define __sciter_x_value_h__
18 |
19 | #pragma once
20 |
21 | #define HAS_TISCRIPT
22 |
23 | #include "value.h"
24 |
25 | #if defined(__cplusplus) && !defined( PLAIN_API_ONLY )
26 | typedef sciter::value SCITER_VALUE;
27 | #include "value.hpp"
28 | #else
29 | typedef VALUE SCITER_VALUE;
30 | #endif
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/includes/sciter/sciter-x-video-api.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The Sciter Engine of Terra Informatica Software, Inc.
3 | * http://sciter.com
4 | *
5 | * The code and information provided "as-is" without
6 | * warranty of any kind, either expressed or implied.
7 | *
8 | * (C) 2003-2015, Terra Informatica Software, Inc.
9 | */
10 |
11 | /*
12 | * Sciter's custom video rendering primitives
13 | */
14 |
15 | #pragma once
16 |
17 | #include "aux-asset.h"
18 | #include "sciter-x-types.h"
19 |
20 | namespace sciter {
21 |
22 | enum COLOR_SPACE {
23 | COLOR_SPACE_UNKNOWN,
24 | COLOR_SPACE_YV12,
25 | COLOR_SPACE_IYUV, // a.k.a. I420
26 | COLOR_SPACE_NV12,
27 | COLOR_SPACE_YUY2,
28 | COLOR_SPACE_RGB24,
29 | COLOR_SPACE_RGB555,
30 | COLOR_SPACE_RGB565,
31 | COLOR_SPACE_RGB32 // with alpha, sic!
32 | };
33 |
34 | #define VIDEO_SOURCE_INAME "source.video.sciter.com"
35 |
36 | struct video_source : public aux::iasset
37 | {
38 | virtual bool play() = 0;
39 | virtual bool pause() = 0;
40 | virtual bool stop() = 0;
41 | virtual bool get_is_ended(bool& eos) = 0;
42 | virtual bool get_position(double& seconds) = 0;
43 | virtual bool set_position(double seconds) = 0;
44 | virtual bool get_duration(double& seconds) = 0;
45 | // audio
46 | virtual bool get_volume(double& vol) = 0;
47 | virtual bool set_volume(double vol) = 0;
48 | virtual bool get_balance(double& vol) = 0;
49 | virtual bool set_balance(double vol) = 0;
50 | };
51 |
52 | #define VIDEO_DESTINATION_INAME "destination.video.sciter.com"
53 |
54 | // video_destination interface, represents video rendering site
55 | struct video_destination : public aux::iasset
56 | {
57 | // true if this instance of video_renderer is attached to DOM element and is capable of playing.
58 | virtual bool is_alive() = 0;
59 |
60 | // start streaming/rendering
61 | virtual bool start_streaming( int frame_width // width
62 | , int frame_height // height
63 | , int color_space // COLOR_SPACE above
64 | , video_source* src = 0 ) = 0; // video_source interface implementation, can be null
65 |
66 | // stop streaming, eof.
67 | virtual bool stop_streaming() = 0;
68 |
69 | // render frame request, false - video_destination is not available ( isn't alive, document unloaded etc.)
70 | virtual bool render_frame(const BYTE* frame_data, UINT frame_data_size) = 0;
71 |
72 | };
73 |
74 | #define FRAGMENTED_VIDEO_DESTINATION_INAME "fragmented.destination.video.sciter.com"
75 |
76 | struct fragmented_video_destination : public video_destination
77 | {
78 | // render frame part request, returns false - video_destination is not available ( isn't alive, document unloaded etc.)
79 | virtual bool render_frame_part(const BYTE* frame_data, UINT frame_data_size, int x, int y, int width, int height) = 0;
80 |
81 | };
82 |
83 |
84 | }
--------------------------------------------------------------------------------
/includes/sciter/sciter-x-window.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * The Sciter Engine of Terra Informatica Software, Inc.
3 | * http://sciter.com
4 | *
5 | * The code and information provided "as-is" without
6 | * warranty of any kind, either expressed or implied.
7 | *
8 | * (C) 2003-2015, Terra Informatica Software, Inc.
9 | */
10 |
11 | /*
12 | * sciter::window and sciter::application - high level window wrapper
13 | * Use these if you just need to create basic Sciter windows.
14 | * Check /demos/uminimal and /demos/usciter samples.
15 | */
16 |
17 | #pragma once
18 |
19 | #ifndef __sciter_x_window_hpp__
20 | #define __sciter_x_window_hpp__
21 |
22 | #include "sciter-x-types.h"
23 | #include "sciter-x.h"
24 | #include "sciter-x-dom.h"
25 | #include "sciter-x-api.h"
26 | //#include "sciter-x-threads.h"
27 | #include "sciter-x-dom.hpp"
28 | #include "sciter-x-host-callback.h"
29 | #include "aux-asset.h"
30 | #include "aux-slice.h"
31 | #include
32 |
33 | // main UI application routine
34 | int uimain( std::function run );
35 | // {
36 | // ... initialization and window creation
37 | // int r = run();
38 | // ... optional de-initialization
39 | // return r;
40 | // }
41 |
42 | /**sciter namespace.*/
43 | namespace sciter
44 | {
45 |
46 | namespace application
47 | {
48 | const std::vector& argv();
49 | HINSTANCE hinstance();
50 | }
51 |
52 | class window : public aux::asset
53 | , public sciter::host
54 | , public sciter::event_handler
55 | {
56 | public:
57 | window( UINT creationFlags, RECT frame = RECT() );
58 |
59 | bool is_valid() const { return _hwnd != 0; }
60 |
61 | void collapse(); // minimize
62 | void expand( bool maximize = false); // show or maximize
63 | void dismiss(); // delete the window
64 |
65 | bool load( aux::bytes utf8_html, const WCHAR* base_url = 0 );
66 | bool load( aux::chars utf8_html, const WCHAR* base_url = 0 );
67 | bool load( const WCHAR* url );
68 |
69 | // sciter::host traits:
70 | HWINDOW get_hwnd() const { return _hwnd; }
71 | HINSTANCE get_resource_instance() const { return application::hinstance(); }
72 |
73 | protected:
74 | virtual void detached (HELEMENT /*he*/ ) override /*sciter::event_handler*/
75 | {
76 | // this happens when HWINDOW gets destroyed
77 | _hwnd = 0; asset::release();
78 | }
79 |
80 | #if defined(WINDOWS)
81 | virtual LRESULT on_message( HWINDOW hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL& handled );
82 | static LRESULT SC_CALLBACK msg_delegate(HWINDOW hwnd, UINT msg, WPARAM wParam, LPARAM lParam, LPVOID pParam, BOOL* pHandled);
83 | #endif
84 | private:
85 | HWINDOW _hwnd;
86 | };
87 | }
88 |
89 | #endif
90 |
--------------------------------------------------------------------------------
/includes/sciter/sciter-x.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The Sciter Engine of Terra Informatica Software, Inc.
3 | * http://sciter.com
4 | *
5 | * The code and information provided "as-is" without
6 | * warranty of any kind, either expressed or implied.
7 | *
8 | *
9 | * (C) 2003-2015, Terra Informatica Software, Inc.
10 | */
11 |
12 | /*
13 | * Sciter main include file
14 | */
15 |
16 |
17 | #ifndef __SCITER_X__
18 | #define __SCITER_X__
19 |
20 | #include "sciter-x-types.h"
21 | #include "sciter-x-def.h"
22 | #include "sciter-x-dom.h"
23 | #include "sciter-x-value.h"
24 | #include "sciter-x-api.h"
25 | #include "sciter-x-msg.h"
26 |
27 | #if defined(__cplusplus) && !defined( PLAIN_API_ONLY )
28 |
29 | // C++, namespace sciter things
30 | #include "sciter-x-dom.hpp"
31 | #include "sciter-x-host-callback.h"
32 | #include "sciter-x-debug.h"
33 | //#include "sciter-x-threads.h"
34 | #endif
35 |
36 | #endif
37 |
38 |
--------------------------------------------------------------------------------
/includes/sciter/tiscript-streams.hpp:
--------------------------------------------------------------------------------
1 | #ifndef __tiscript_streams_hpp__
2 | #define __tiscript_streams_hpp__
3 |
4 | #if defined(__cplusplus)
5 |
6 | #include "tiscript.h"
7 | #include "aux-cvt.h"
8 | #include
9 |
10 | namespace tiscript
11 | {
12 |
13 | class stream: public tiscript_stream
14 | {
15 | public:
16 | stream()
17 | {
18 | static tiscript_stream_vtbl methods = { _stream_input, _stream_output, _stream_name, _stream_close };
19 | _vtbl = &methods;
20 | }
21 | virtual ~stream() { close(); }
22 |
23 | // these need to be overrided
24 | virtual const WCHAR* stream_name() { static WCHAR z = 0; return &z; }
25 | virtual int get() { return -1; }
26 | virtual bool put(int) { return false; }
27 | virtual void close() {}
28 |
29 | protected:
30 | inline static bool TISAPI _stream_input(tiscript_stream* tag, int* pv)
31 | { *pv = static_cast(tag)->get(); return *pv >= 0; }
32 | inline static bool TISAPI _stream_output(tiscript_stream* tag, int v)
33 | { return static_cast(tag)->put(v); }
34 | inline static const WCHAR* TISAPI _stream_name(tiscript_stream* tag)
35 | { return static_cast(tag)->stream_name(); }
36 | inline static void TISAPI _stream_close(tiscript_stream* tag)
37 | { static_cast(tag)->close(); }
38 | };
39 |
40 | // various stream implementations
41 | class string_istream: public stream
42 | {
43 | const WCHAR* _pos; const WCHAR* _end;
44 | public:
45 | string_istream(const WCHAR* str, unsigned length = 0): _pos(str),_end(str) { if(length == 0) length = (unsigned int)aux::wcslen(str); _end = _pos + length; }
46 | virtual int get() { return (*_pos && _pos < _end)? *_pos++ : -1; }
47 | };
48 |
49 | class string_ostream: public stream
50 | {
51 | WCHAR *_str, *_p, *_end;
52 | public:
53 | string_ostream() { _p = _str = (WCHAR*)malloc( 128 * sizeof(WCHAR) ); _end = _str + 128; }
54 | virtual bool put(int v)
55 | {
56 | if( _p >= _end )
57 | {
58 | size_t sz = _end - _str; size_t nsz = (sz * 2) / 3; if( nsz < 128 ) nsz = 128;
59 | WCHAR *nstr = (WCHAR*)realloc(_str, nsz * sizeof(WCHAR));
60 | if(!nstr) return false;
61 | _str = nstr; _p = _str + sz; _end = _str + nsz;
62 | }
63 | *_p++ = WCHAR(v);
64 | return true;
65 | }
66 | const WCHAR *c_str() { put(0); --_p; return _str; }
67 | virtual void close() { if(_str) { free(_str); _str = _p = _end = 0; } }
68 | };
69 |
70 | // simple file input stream.
71 | class file_istream: public stream
72 | {
73 | FILE* _file;
74 | std::basic_string _name;
75 | public:
76 | file_istream(const WCHAR* filename) {
77 | #ifdef WINDOWS
78 | _wfopen_s(&_file,filename,L"rb");
79 | #else
80 | _file = fopen(aux::w2a(filename),"rb");
81 | #endif
82 | _name = filename;
83 | }
84 | virtual void close() { if(_file) {fclose(_file);_file = 0;} }
85 |
86 | virtual const WCHAR* stream_name() { return _name.c_str(); }
87 |
88 | virtual int get()
89 | {
90 | if(!_file || feof(_file)) return -1;
91 | return fgetc(_file);
92 | }
93 | bool is_valid() const { return _file != 0; }
94 | };
95 |
96 | inline WCHAR oem2wchar(char c)
97 | {
98 | WCHAR wc = '?';
99 | #ifdef WINDOWS
100 | MultiByteToWideChar(CP_OEMCP,0,&c,1,&wc,1);
101 | #else
102 | wc = c;
103 | #endif
104 | return wc;
105 | }
106 | inline char wchar2oem(WCHAR wc)
107 | {
108 | char c = '?';
109 | #ifdef WINDOWS
110 | WideCharToMultiByte(CP_OEMCP,0,&wc,1,&c,1,0,0);
111 | #else
112 | c = char(wc);
113 | #endif
114 | return c;
115 | }
116 | class console: public stream
117 | {
118 | public:
119 | virtual int get() { int c = getchar(); return c != EOF? oem2wchar(char(c)) : -1; }
120 | virtual bool put(int v)
121 | {
122 | return putchar( wchar2oem(WCHAR(v)) ) != EOF;
123 | }
124 | };
125 |
126 |
127 | }
128 |
129 | #endif
130 |
131 | #endif
132 |
--------------------------------------------------------------------------------
/includes/spdlog/async_logger.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright(c) 2015 Gabi Melman.
3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT)
4 | //
5 |
6 | #pragma once
7 |
8 | // Very fast asynchronous logger (millions of logs per second on an average desktop)
9 | // Uses pre allocated lockfree queue for maximum throughput even under large number of threads.
10 | // Creates a single back thread to pop messages from the queue and log them.
11 | //
12 | // Upon each log write the logger:
13 | // 1. Checks if its log level is enough to log the message
14 | // 2. Push a new copy of the message to a queue (or block the caller until space is available in the queue)
15 | // 3. will throw spdlog_ex upon log exceptions
16 | // Upon destruction, logs all remaining messages in the queue before destructing..
17 |
18 | #include
19 | #include
20 |
21 | #include
22 | #include
23 | #include
24 | #include
25 |
26 | namespace spdlog
27 | {
28 |
29 | namespace details
30 | {
31 | class async_log_helper;
32 | }
33 |
34 | class async_logger :public logger
35 | {
36 | public:
37 | template
38 | async_logger(const std::string& name,
39 | const It& begin,
40 | const It& end,
41 | size_t queue_size,
42 | const async_overflow_policy overflow_policy = async_overflow_policy::block_retry,
43 | const std::function& worker_warmup_cb = nullptr,
44 | const std::chrono::milliseconds& flush_interval_ms = std::chrono::milliseconds::zero(),
45 | const std::function& worker_teardown_cb = nullptr);
46 |
47 | async_logger(const std::string& logger_name,
48 | sinks_init_list sinks,
49 | size_t queue_size,
50 | const async_overflow_policy overflow_policy = async_overflow_policy::block_retry,
51 | const std::function& worker_warmup_cb = nullptr,
52 | const std::chrono::milliseconds& flush_interval_ms = std::chrono::milliseconds::zero(),
53 | const std::function& worker_teardown_cb = nullptr);
54 |
55 | async_logger(const std::string& logger_name,
56 | sink_ptr single_sink,
57 | size_t queue_size,
58 | const async_overflow_policy overflow_policy = async_overflow_policy::block_retry,
59 | const std::function& worker_warmup_cb = nullptr,
60 | const std::chrono::milliseconds& flush_interval_ms = std::chrono::milliseconds::zero(),
61 | const std::function& worker_teardown_cb = nullptr);
62 |
63 |
64 | void flush() override;
65 | protected:
66 | void _log_msg(details::log_msg& msg) override;
67 | void _set_formatter(spdlog::formatter_ptr msg_formatter) override;
68 | void _set_pattern(const std::string& pattern) override;
69 |
70 | private:
71 | std::unique_ptr _async_log_helper;
72 | };
73 | }
74 |
75 |
76 | #include
77 |
--------------------------------------------------------------------------------
/includes/spdlog/common.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright(c) 2015 Gabi Melman.
3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT)
4 | //
5 |
6 | #pragma once
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
15 | #include
16 | #include
17 | #endif
18 |
19 | #include
20 |
21 | //visual studio upto 2013 does not support noexcept nor constexpr
22 | #if defined(_MSC_VER) && (_MSC_VER < 1900)
23 | #define SPDLOG_NOEXCEPT throw()
24 | #define SPDLOG_CONSTEXPR
25 | #else
26 | #define SPDLOG_NOEXCEPT noexcept
27 | #define SPDLOG_CONSTEXPR constexpr
28 | #endif
29 |
30 |
31 | namespace spdlog
32 | {
33 |
34 | class formatter;
35 |
36 | namespace sinks
37 | {
38 | class sink;
39 | }
40 |
41 | using log_clock = std::chrono::system_clock;
42 | using sink_ptr = std::shared_ptr < sinks::sink >;
43 | using sinks_init_list = std::initializer_list < sink_ptr >;
44 | using formatter_ptr = std::shared_ptr;
45 | #if defined(SPDLOG_NO_ATOMIC_LEVELS)
46 | using level_t = details::null_atomic_int;
47 | #else
48 | using level_t = std::atomic_int;
49 | #endif
50 |
51 | //Log level enum
52 | namespace level
53 | {
54 | typedef enum
55 | {
56 | trace = 0,
57 | debug = 1,
58 | info = 2,
59 | notice = 3,
60 | warn = 4,
61 | err = 5,
62 | critical = 6,
63 | alert = 7,
64 | emerg = 8,
65 | off = 9
66 | } level_enum;
67 |
68 | static const char* level_names[] { "trace", "debug", "info", "notice", "warning", "error", "critical", "alert", "emerg", "off"};
69 |
70 | static const char* short_level_names[] { "T", "D", "I", "N", "W", "E", "C", "A", "M", "O"};
71 |
72 | inline const char* to_str(spdlog::level::level_enum l)
73 | {
74 | return level_names[l];
75 | }
76 |
77 | inline const char* to_short_str(spdlog::level::level_enum l)
78 | {
79 | return short_level_names[l];
80 | }
81 | } //level
82 |
83 |
84 | //
85 | // Async overflow policy - block by default.
86 | //
87 | enum class async_overflow_policy
88 | {
89 | block_retry, // Block / yield / sleep until message can be enqueued
90 | discard_log_msg // Discard the message it enqueue fails
91 | };
92 |
93 |
94 | //
95 | // Log exception
96 | //
97 | class spdlog_ex : public std::exception
98 | {
99 | public:
100 | spdlog_ex(const std::string& msg) :_msg(msg) {}
101 | const char* what() const SPDLOG_NOEXCEPT override
102 | {
103 | return _msg.c_str();
104 | }
105 | private:
106 | std::string _msg;
107 |
108 | };
109 |
110 | //
111 | // wchar support for windows file names (SPDLOG_WCHAR_FILENAMES must be defined)
112 | //
113 | #if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
114 | using filename_t = std::wstring;
115 | #else
116 | using filename_t = std::string;
117 | #endif
118 |
119 |
120 | } //spdlog
121 |
--------------------------------------------------------------------------------
/includes/spdlog/details/async_logger_impl.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright(c) 2015 Gabi Melman.
3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT)
4 | //
5 |
6 | #pragma once
7 |
8 | // Async Logger implementation
9 | // Use an async_sink (queue per logger) to perform the logging in a worker thread
10 |
11 | #include
12 | #include
13 |
14 | #include
15 | #include
16 | #include
17 | #include
18 |
19 | template
20 | inline spdlog::async_logger::async_logger(const std::string& logger_name,
21 | const It& begin,
22 | const It& end,
23 | size_t queue_size,
24 | const async_overflow_policy overflow_policy,
25 | const std::function& worker_warmup_cb,
26 | const std::chrono::milliseconds& flush_interval_ms,
27 | const std::function& worker_teardown_cb) :
28 | logger(logger_name, begin, end),
29 | _async_log_helper(new details::async_log_helper(_formatter, _sinks, queue_size, overflow_policy, worker_warmup_cb, flush_interval_ms, worker_teardown_cb))
30 | {
31 | }
32 |
33 | inline spdlog::async_logger::async_logger(const std::string& logger_name,
34 | sinks_init_list sinks,
35 | size_t queue_size,
36 | const async_overflow_policy overflow_policy,
37 | const std::function& worker_warmup_cb,
38 | const std::chrono::milliseconds& flush_interval_ms,
39 | const std::function& worker_teardown_cb) :
40 | async_logger(logger_name, sinks.begin(), sinks.end(), queue_size, overflow_policy, worker_warmup_cb, flush_interval_ms, worker_teardown_cb) {}
41 |
42 | inline spdlog::async_logger::async_logger(const std::string& logger_name,
43 | sink_ptr single_sink,
44 | size_t queue_size,
45 | const async_overflow_policy overflow_policy,
46 | const std::function& worker_warmup_cb,
47 | const std::chrono::milliseconds& flush_interval_ms,
48 | const std::function& worker_teardown_cb) :
49 | async_logger(logger_name,
50 | {
51 | single_sink
52 | }, queue_size, overflow_policy, worker_warmup_cb, flush_interval_ms, worker_teardown_cb) {}
53 |
54 |
55 | inline void spdlog::async_logger::flush()
56 | {
57 |
58 | _async_log_helper->flush();
59 | }
60 |
61 | inline void spdlog::async_logger::_set_formatter(spdlog::formatter_ptr msg_formatter)
62 | {
63 | _formatter = msg_formatter;
64 | _async_log_helper->set_formatter(_formatter);
65 | }
66 |
67 | inline void spdlog::async_logger::_set_pattern(const std::string& pattern)
68 | {
69 | _formatter = std::make_shared(pattern);
70 | _async_log_helper->set_formatter(_formatter);
71 | }
72 |
73 |
74 | inline void spdlog::async_logger::_log_msg(details::log_msg& msg)
75 | {
76 | _async_log_helper->log(msg);
77 | }
78 |
--------------------------------------------------------------------------------
/includes/spdlog/details/file_helper.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright(c) 2015 Gabi Melman.
3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT)
4 | //
5 |
6 | #pragma once
7 |
8 | // Helper class for file sink
9 | // When failing to open a file, retry several times(5) with small delay between the tries(10 ms)
10 | // Can be set to auto flush on every line
11 | // Throw spdlog_ex exception on errors
12 |
13 | #include
14 | #include
15 |
16 | #include
17 | #include
18 | #include
19 | #include
20 |
21 | namespace spdlog
22 | {
23 | namespace details
24 | {
25 |
26 | class file_helper
27 | {
28 |
29 | public:
30 | const int open_tries = 5;
31 | const int open_interval = 10;
32 |
33 | explicit file_helper(bool force_flush) :
34 | _fd(nullptr),
35 | _force_flush(force_flush)
36 | {}
37 |
38 | file_helper(const file_helper&) = delete;
39 | file_helper& operator=(const file_helper&) = delete;
40 |
41 | ~file_helper()
42 | {
43 | close();
44 | }
45 |
46 |
47 | void open(const filename_t& fname, bool truncate = false)
48 | {
49 |
50 | close();
51 | auto *mode = truncate ? SPDLOG_FILENAME_T("wb") : SPDLOG_FILENAME_T("ab");
52 | _filename = fname;
53 | for (int tries = 0; tries < open_tries; ++tries)
54 | {
55 | if (!os::fopen_s(&_fd, fname, mode))
56 | return;
57 |
58 | std::this_thread::sleep_for(std::chrono::milliseconds(open_interval));
59 | }
60 |
61 | throw spdlog_ex("Failed opening file " + os::filename_to_str(_filename) + " for writing");
62 | }
63 |
64 | void reopen(bool truncate)
65 | {
66 | if (_filename.empty())
67 | throw spdlog_ex("Failed re opening file - was not opened before");
68 | open(_filename, truncate);
69 |
70 | }
71 |
72 | void flush()
73 | {
74 | std::fflush(_fd);
75 | }
76 |
77 | void close()
78 | {
79 | if (_fd)
80 | {
81 | std::fclose(_fd);
82 | _fd = nullptr;
83 | }
84 | }
85 |
86 | void write(const log_msg& msg)
87 | {
88 |
89 | size_t msg_size = msg.formatted.size();
90 | auto data = msg.formatted.data();
91 | if (std::fwrite(data, 1, msg_size, _fd) != msg_size)
92 | throw spdlog_ex("Failed writing to file " + os::filename_to_str(_filename));
93 |
94 | if (_force_flush)
95 | std::fflush(_fd);
96 | }
97 |
98 | long size()
99 | {
100 | if (!_fd)
101 | throw spdlog_ex("Cannot use size() on closed file " + os::filename_to_str(_filename));
102 |
103 | auto pos = ftell(_fd);
104 | if (fseek(_fd, 0, SEEK_END) != 0)
105 | throw spdlog_ex("fseek failed on file " + os::filename_to_str(_filename));
106 |
107 | auto file_size = ftell(_fd);
108 |
109 | if(fseek(_fd, pos, SEEK_SET) !=0)
110 | throw spdlog_ex("fseek failed on file " + os::filename_to_str(_filename));
111 |
112 | if (file_size == -1)
113 | throw spdlog_ex("ftell failed on file " + os::filename_to_str(_filename));
114 |
115 | return file_size;
116 | }
117 |
118 | const filename_t& filename() const
119 | {
120 | return _filename;
121 | }
122 |
123 | static bool file_exists(const filename_t& name)
124 | {
125 |
126 | return os::file_exists(name);
127 | }
128 |
129 | private:
130 | FILE* _fd;
131 | filename_t _filename;
132 | bool _force_flush;
133 | };
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/includes/spdlog/details/line_logger_fwd.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright(c) 2015 Gabi Melman.
3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT)
4 | //
5 | #pragma once
6 |
7 | #include
8 | #include
9 |
10 | #include
11 |
12 | // Line logger class - aggregates operator<< calls to fast ostream
13 | // and logs upon destruction
14 |
15 | namespace spdlog
16 | {
17 |
18 | // Forward declaration
19 | class logger;
20 |
21 | namespace details
22 | {
23 | class line_logger
24 | {
25 | public:
26 | line_logger(logger* callback_logger, level::level_enum msg_level, bool enabled);
27 |
28 | // No copy intended. Only move
29 | line_logger(const line_logger& other) = delete;
30 | line_logger& operator=(const line_logger&) = delete;
31 | line_logger& operator=(line_logger&&) = delete;
32 |
33 |
34 | line_logger(line_logger&& other);
35 |
36 | //Log the log message using the callback logger
37 | ~line_logger();
38 |
39 | //
40 | // Support for format string with variadic args
41 | //
42 |
43 |
44 | void write(const char* what);
45 |
46 | template
47 | void write(const char* fmt, const Args&... args);
48 |
49 | //
50 | // Support for operator<<
51 | //
52 | line_logger& operator<<(const char* what);
53 | line_logger& operator<<(const std::string& what);
54 | line_logger& operator<<(int what);
55 | line_logger& operator<<(unsigned int what);
56 | line_logger& operator<<(long what);
57 | line_logger& operator<<(unsigned long what);
58 | line_logger& operator<<(long long what);
59 | line_logger& operator<<(unsigned long long what);
60 | line_logger& operator<<(double what);
61 | line_logger& operator<<(long double what);
62 | line_logger& operator<<(float what);
63 | line_logger& operator<<(char what);
64 | //Support user types which implements operator<<
65 | template
66 | line_logger& operator<<(const T& what);
67 |
68 | void disable();
69 | bool is_enabled() const;
70 |
71 | private:
72 | logger* _callback_logger;
73 | log_msg _log_msg;
74 | bool _enabled;
75 | };
76 | } //Namespace details
77 | } // Namespace spdlog
78 |
79 |
--------------------------------------------------------------------------------
/includes/spdlog/details/line_logger_impl.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright(c) 2015 Gabi Melman.
3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT)
4 | //
5 | #pragma once
6 | #include
7 |
8 | #include
9 | #include
10 | #include
11 |
12 | #include
13 | #include
14 |
15 | // Line logger class - aggregates operator<< calls to fast ostream
16 | // and logs upon destruction
17 |
18 | inline spdlog::details::line_logger::line_logger(logger* callback_logger, level::level_enum msg_level, bool enabled):
19 | _callback_logger(callback_logger),
20 | _log_msg(msg_level),
21 | _enabled(enabled)
22 | {}
23 |
24 | inline spdlog::details::line_logger::line_logger(line_logger&& other) :
25 | _callback_logger(other._callback_logger),
26 | _log_msg(std::move(other._log_msg)),
27 | _enabled(other._enabled)
28 | {
29 | other.disable();
30 | }
31 |
32 | //Log the log message using the callback logger
33 | inline spdlog::details::line_logger::~line_logger()
34 | {
35 | if (_enabled)
36 | {
37 | #ifndef SPDLOG_NO_NAME
38 | _log_msg.logger_name = _callback_logger->name();
39 | #endif
40 | #ifndef SPDLOG_NO_DATETIME
41 | _log_msg.time = os::now();
42 | #endif
43 |
44 | #ifndef SPDLOG_NO_THREAD_ID
45 | _log_msg.thread_id = os::thread_id();
46 | #endif
47 | _callback_logger->_log_msg(_log_msg);
48 | }
49 | }
50 |
51 | //
52 | // Support for format string with variadic args
53 | //
54 |
55 |
56 | inline void spdlog::details::line_logger::write(const char* what)
57 | {
58 | if (_enabled)
59 | _log_msg.raw << what;
60 | }
61 |
62 | template
63 | inline void spdlog::details::line_logger::write(const char* fmt, const Args&... args)
64 | {
65 | if (!_enabled)
66 | return;
67 | try
68 | {
69 | _log_msg.raw.write(fmt, args...);
70 | }
71 | catch (const fmt::FormatError& e)
72 | {
73 | throw spdlog_ex(fmt::format("formatting error while processing format string '{}': {}", fmt, e.what()));
74 | }
75 | }
76 |
77 |
78 | //
79 | // Support for operator<<
80 | //
81 | inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(const char* what)
82 | {
83 | if (_enabled)
84 | _log_msg.raw << what;
85 | return *this;
86 | }
87 |
88 | inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(const std::string& what)
89 | {
90 | if (_enabled)
91 | _log_msg.raw << what;
92 | return *this;
93 | }
94 |
95 | inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(int what)
96 | {
97 | if (_enabled)
98 | _log_msg.raw << what;
99 | return *this;
100 | }
101 |
102 | inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(unsigned int what)
103 | {
104 | if (_enabled)
105 | _log_msg.raw << what;
106 | return *this;
107 | }
108 |
109 |
110 | inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(long what)
111 | {
112 | if (_enabled)
113 | _log_msg.raw << what;
114 | return *this;
115 | }
116 |
117 | inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(unsigned long what)
118 | {
119 | if (_enabled)
120 | _log_msg.raw << what;
121 | return *this;
122 | }
123 |
124 | inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(long long what)
125 | {
126 | if (_enabled)
127 | _log_msg.raw << what;
128 | return *this;
129 | }
130 |
131 | inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(unsigned long long what)
132 | {
133 | if (_enabled)
134 | _log_msg.raw << what;
135 | return *this;
136 | }
137 |
138 | inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(double what)
139 | {
140 | if (_enabled)
141 | _log_msg.raw << what;
142 | return *this;
143 | }
144 |
145 | inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(long double what)
146 | {
147 | if (_enabled)
148 | _log_msg.raw << what;
149 | return *this;
150 | }
151 |
152 | inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(float what)
153 | {
154 | if (_enabled)
155 | _log_msg.raw << what;
156 | return *this;
157 | }
158 |
159 | inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(char what)
160 | {
161 | if (_enabled)
162 | _log_msg.raw << what;
163 | return *this;
164 | }
165 |
166 | //Support user types which implements operator<<
167 | template
168 | inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(const T& what)
169 | {
170 | if (_enabled)
171 | _log_msg.raw.write("{}", what);
172 | return *this;
173 | }
174 |
175 |
176 | inline void spdlog::details::line_logger::disable()
177 | {
178 | _enabled = false;
179 | }
180 |
181 | inline bool spdlog::details::line_logger::is_enabled() const
182 | {
183 | return _enabled;
184 | }
185 |
186 |
--------------------------------------------------------------------------------
/includes/spdlog/details/log_msg.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright(c) 2015 Gabi Melman.
3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT)
4 | //
5 |
6 | #pragma once
7 |
8 | #include
9 | #include
10 |
11 | #include
12 | #include
13 |
14 | namespace spdlog
15 | {
16 | namespace details
17 | {
18 | struct log_msg
19 | {
20 | log_msg() = default;
21 | log_msg(level::level_enum l):
22 | logger_name(),
23 | level(l),
24 | raw(),
25 | formatted() {}
26 |
27 |
28 | log_msg(const log_msg& other) :
29 | logger_name(other.logger_name),
30 | level(other.level),
31 | time(other.time),
32 | thread_id(other.thread_id)
33 | {
34 | if (other.raw.size())
35 | raw << fmt::BasicStringRef(other.raw.data(), other.raw.size());
36 | if (other.formatted.size())
37 | formatted << fmt::BasicStringRef(other.formatted.data(), other.formatted.size());
38 | }
39 |
40 | log_msg(log_msg&& other) :
41 | logger_name(std::move(other.logger_name)),
42 | level(other.level),
43 | time(std::move(other.time)),
44 | thread_id(other.thread_id),
45 | raw(std::move(other.raw)),
46 | formatted(std::move(other.formatted))
47 | {
48 | other.clear();
49 | }
50 |
51 | log_msg& operator=(log_msg&& other)
52 | {
53 | if (this == &other)
54 | return *this;
55 |
56 | logger_name = std::move(other.logger_name);
57 | level = other.level;
58 | time = std::move(other.time);
59 | thread_id = other.thread_id;
60 | raw = std::move(other.raw);
61 | formatted = std::move(other.formatted);
62 | other.clear();
63 | return *this;
64 | }
65 |
66 | void clear()
67 | {
68 | level = level::off;
69 | raw.clear();
70 | formatted.clear();
71 | }
72 |
73 | std::string logger_name;
74 | level::level_enum level;
75 | log_clock::time_point time;
76 | size_t thread_id;
77 | fmt::MemoryWriter raw;
78 | fmt::MemoryWriter formatted;
79 | };
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/includes/spdlog/details/mpmc_bounded_q.h:
--------------------------------------------------------------------------------
1 | /*
2 | A modified version of Bounded MPMC queue by Dmitry Vyukov.
3 |
4 | Original code from:
5 | http://www.1024cores.net/home/lock-free-algorithms/queues/bounded-mpmc-queue
6 |
7 | licensed by Dmitry Vyukov under the terms below:
8 |
9 | Simplified BSD license
10 |
11 | Copyright (c) 2010-2011 Dmitry Vyukov. All rights reserved.
12 | Redistribution and use in source and binary forms, with or without modification,
13 | are permitted provided that the following conditions are met:
14 | 1. Redistributions of source code must retain the above copyright notice, this list of
15 | conditions and the following disclaimer.
16 |
17 | 2. Redistributions in binary form must reproduce the above copyright notice, this list
18 | of conditions and the following disclaimer in the documentation and/or other materials
19 | provided with the distribution.
20 |
21 | THIS SOFTWARE IS PROVIDED BY DMITRY VYUKOV "AS IS" AND ANY EXPRESS OR IMPLIED
22 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 | SHALL DMITRY VYUKOV OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
27 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 |
32 | The views and conclusions contained in the software and documentation are those of the authors and
33 | should not be interpreted as representing official policies, either expressed or implied, of Dmitry Vyukov.
34 | */
35 |
36 | /*
37 | The code in its current form adds the license below:
38 |
39 | Copyright(c) 2015 Gabi Melman.
40 | Distributed under the MIT License (http://opensource.org/licenses/MIT)
41 |
42 | */
43 |
44 | #pragma once
45 |
46 | #include
47 |
48 | #include
49 | #include
50 |
51 | namespace spdlog
52 | {
53 | namespace details
54 | {
55 |
56 | template
57 | class mpmc_bounded_queue
58 | {
59 | public:
60 |
61 | using item_type = T;
62 | mpmc_bounded_queue(size_t buffer_size)
63 | : buffer_(new cell_t [buffer_size]),
64 | buffer_mask_(buffer_size - 1)
65 | {
66 | //queue size must be power of two
67 | if(!((buffer_size >= 2) && ((buffer_size & (buffer_size - 1)) == 0)))
68 | throw spdlog_ex("async logger queue size must be power of two");
69 |
70 | for (size_t i = 0; i != buffer_size; i += 1)
71 | buffer_[i].sequence_.store(i, std::memory_order_relaxed);
72 | enqueue_pos_.store(0, std::memory_order_relaxed);
73 | dequeue_pos_.store(0, std::memory_order_relaxed);
74 | }
75 |
76 | ~mpmc_bounded_queue()
77 | {
78 | delete [] buffer_;
79 | }
80 |
81 |
82 | bool enqueue(T&& data)
83 | {
84 | cell_t* cell;
85 | size_t pos = enqueue_pos_.load(std::memory_order_relaxed);
86 | for (;;)
87 | {
88 | cell = &buffer_[pos & buffer_mask_];
89 | size_t seq = cell->sequence_.load(std::memory_order_acquire);
90 | intptr_t dif = (intptr_t)seq - (intptr_t)pos;
91 | if (dif == 0)
92 | {
93 | if (enqueue_pos_.compare_exchange_weak(pos, pos + 1, std::memory_order_relaxed))
94 | break;
95 | }
96 | else if (dif < 0)
97 | {
98 | return false;
99 | }
100 | else
101 | {
102 | pos = enqueue_pos_.load(std::memory_order_relaxed);
103 | }
104 | }
105 | cell->data_ = std::move(data);
106 | cell->sequence_.store(pos + 1, std::memory_order_release);
107 | return true;
108 | }
109 |
110 | bool dequeue(T& data)
111 | {
112 | cell_t* cell;
113 | size_t pos = dequeue_pos_.load(std::memory_order_relaxed);
114 | for (;;)
115 | {
116 | cell = &buffer_[pos & buffer_mask_];
117 | size_t seq =
118 | cell->sequence_.load(std::memory_order_acquire);
119 | intptr_t dif = (intptr_t)seq - (intptr_t)(pos + 1);
120 | if (dif == 0)
121 | {
122 | if (dequeue_pos_.compare_exchange_weak(pos, pos + 1, std::memory_order_relaxed))
123 | break;
124 | }
125 | else if (dif < 0)
126 | return false;
127 | else
128 | pos = dequeue_pos_.load(std::memory_order_relaxed);
129 | }
130 | data = std::move(cell->data_);
131 | cell->sequence_.store(pos + buffer_mask_ + 1, std::memory_order_release);
132 | return true;
133 | }
134 |
135 | private:
136 | struct cell_t
137 | {
138 | std::atomic sequence_;
139 | T data_;
140 | };
141 |
142 | static size_t const cacheline_size = 64;
143 | typedef char cacheline_pad_t [cacheline_size];
144 |
145 | cacheline_pad_t pad0_;
146 | cell_t* const buffer_;
147 | size_t const buffer_mask_;
148 | cacheline_pad_t pad1_;
149 | std::atomic enqueue_pos_;
150 | cacheline_pad_t pad2_;
151 | std::atomic dequeue_pos_;
152 | cacheline_pad_t pad3_;
153 |
154 | mpmc_bounded_queue(mpmc_bounded_queue const&);
155 | void operator = (mpmc_bounded_queue const&);
156 | };
157 |
158 | } // ns details
159 | } // ns spdlog
160 |
--------------------------------------------------------------------------------
/includes/spdlog/details/null_mutex.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright(c) 2015 Gabi Melman.
3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT)
4 | //
5 |
6 | #pragma once
7 |
8 | #include
9 | // null, no cost dummy "mutex" and dummy "atomic" int
10 |
11 | namespace spdlog
12 | {
13 | namespace details
14 | {
15 | struct null_mutex
16 | {
17 | void lock() {}
18 | void unlock() {}
19 | bool try_lock()
20 | {
21 | return true;
22 | }
23 | };
24 |
25 | struct null_atomic_int
26 | {
27 | int value;
28 | null_atomic_int() = default;
29 |
30 | null_atomic_int(int val):value(val)
31 | {}
32 |
33 | int load(std::memory_order) const
34 | {
35 | return value;
36 | }
37 |
38 | void store(int val)
39 | {
40 | value = val;
41 | }
42 | };
43 |
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/includes/spdlog/details/os.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright(c) 2015 Gabi Melman.
3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT)
4 | //
5 | #pragma once
6 |
7 | #include
8 |
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | #ifdef _WIN32
15 |
16 | #ifndef NOMINMAX
17 | #define NOMINMAX //prevent windows redefining min/max
18 | #endif
19 |
20 | #ifndef WIN32_LEAN_AND_MEAN
21 | #define WIN32_LEAN_AND_MEAN
22 | #endif
23 | #include
24 |
25 | #ifdef __MINGW32__
26 | #include
27 | #endif
28 |
29 | #elif __linux__
30 | #include //Use gettid() syscall under linux to get thread id
31 | #include
32 | #include
33 | #include
34 | #else
35 | #include
36 | #endif
37 |
38 | namespace spdlog
39 | {
40 | namespace details
41 | {
42 | namespace os
43 | {
44 |
45 | inline spdlog::log_clock::time_point now()
46 | {
47 |
48 | #if defined __linux__ && defined SPDLOG_CLOCK_COARSE
49 | timespec ts;
50 | ::clock_gettime(CLOCK_REALTIME_COARSE, &ts);
51 | return std::chrono::time_point(
52 | std::chrono::duration_cast(
53 | std::chrono::seconds(ts.tv_sec) + std::chrono::nanoseconds(ts.tv_nsec)));
54 |
55 |
56 | #else
57 | return log_clock::now();
58 | #endif
59 |
60 | }
61 | inline std::tm localtime(const std::time_t &time_tt)
62 | {
63 |
64 | #ifdef _WIN32
65 | std::tm tm;
66 | localtime_s(&tm, &time_tt);
67 | #else
68 | std::tm tm;
69 | localtime_r(&time_tt, &tm);
70 | #endif
71 | return tm;
72 | }
73 |
74 | inline std::tm localtime()
75 | {
76 | std::time_t now_t = time(nullptr);
77 | return localtime(now_t);
78 | }
79 |
80 |
81 | inline std::tm gmtime(const std::time_t &time_tt)
82 | {
83 |
84 | #ifdef _WIN32
85 | std::tm tm;
86 | gmtime_s(&tm, &time_tt);
87 | #else
88 | std::tm tm;
89 | gmtime_r(&time_tt, &tm);
90 | #endif
91 | return tm;
92 | }
93 |
94 | inline std::tm gmtime()
95 | {
96 | std::time_t now_t = time(nullptr);
97 | return gmtime(now_t);
98 | }
99 | inline bool operator==(const std::tm& tm1, const std::tm& tm2)
100 | {
101 | return (tm1.tm_sec == tm2.tm_sec &&
102 | tm1.tm_min == tm2.tm_min &&
103 | tm1.tm_hour == tm2.tm_hour &&
104 | tm1.tm_mday == tm2.tm_mday &&
105 | tm1.tm_mon == tm2.tm_mon &&
106 | tm1.tm_year == tm2.tm_year &&
107 | tm1.tm_isdst == tm2.tm_isdst);
108 | }
109 |
110 | inline bool operator!=(const std::tm& tm1, const std::tm& tm2)
111 | {
112 | return !(tm1 == tm2);
113 | }
114 |
115 | // eol definition
116 | #if !defined (SPDLOG_EOL)
117 | #ifdef _WIN32
118 | #define SPDLOG_EOL "\r\n"
119 | #else
120 | #define SPDLOG_EOL "\n"
121 | #endif
122 | #endif
123 |
124 | SPDLOG_CONSTEXPR static const char* eol = SPDLOG_EOL;
125 | SPDLOG_CONSTEXPR static int eol_size = sizeof(SPDLOG_EOL) - 1;
126 |
127 |
128 |
129 | //fopen_s on non windows for writing
130 | inline int fopen_s(FILE** fp, const filename_t& filename, const filename_t& mode)
131 | {
132 | #ifdef _WIN32
133 | #ifdef SPDLOG_WCHAR_FILENAMES
134 | *fp = _wfsopen((filename.c_str()), mode.c_str(), _SH_DENYWR);
135 | #else
136 | *fp = _fsopen((filename.c_str()), mode.c_str(), _SH_DENYWR);
137 | #endif
138 | return *fp == nullptr;
139 | #else
140 | *fp = fopen((filename.c_str()), mode.c_str());
141 | return *fp == nullptr;
142 | #endif
143 | }
144 |
145 | inline int remove(const filename_t &filename)
146 | {
147 | #if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
148 | return _wremove(filename.c_str());
149 | #else
150 | return std::remove(filename.c_str());
151 | #endif
152 | }
153 |
154 | inline int rename(const filename_t& filename1, const filename_t& filename2)
155 | {
156 | #if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
157 | return _wrename(filename1.c_str(), filename2.c_str());
158 | #else
159 | return std::rename(filename1.c_str(), filename2.c_str());
160 | #endif
161 | }
162 |
163 |
164 | //Return if file exists
165 | inline bool file_exists(const filename_t& filename)
166 | {
167 | #ifdef _WIN32
168 | #ifdef SPDLOG_WCHAR_FILENAMES
169 | auto attribs = GetFileAttributesW(filename.c_str());
170 | #else
171 | auto attribs = GetFileAttributesA(filename.c_str());
172 | #endif
173 | return (attribs != INVALID_FILE_ATTRIBUTES && !(attribs & FILE_ATTRIBUTE_DIRECTORY));
174 | #elif __linux__
175 | struct stat buffer;
176 | return (stat (filename.c_str(), &buffer) == 0);
177 | #else
178 | auto *file = fopen(filename.c_str(), "r");
179 | if (file != nullptr)
180 | {
181 | fclose(file);
182 | return true;
183 | }
184 | return false;
185 |
186 | #endif
187 | }
188 |
189 | //Return utc offset in minutes or throw spdlog_ex on failure
190 | inline int utc_minutes_offset(const std::tm& tm = details::os::localtime())
191 | {
192 |
193 | #ifdef _WIN32
194 | #if _WIN32_WINNT < _WIN32_WINNT_WS08
195 | TIME_ZONE_INFORMATION tzinfo;
196 | auto rv = GetTimeZoneInformation(&tzinfo);
197 | #else
198 | DYNAMIC_TIME_ZONE_INFORMATION tzinfo;
199 | auto rv = GetDynamicTimeZoneInformation(&tzinfo);
200 | #endif
201 | if (rv == TIME_ZONE_ID_INVALID)
202 | throw spdlog::spdlog_ex("Failed getting timezone info. Last error: " + std::to_string(GetLastError()));
203 |
204 | int offset = -tzinfo.Bias;
205 | if (tm.tm_isdst)
206 | offset -= tzinfo.DaylightBias;
207 | else
208 | offset -= tzinfo.StandardBias;
209 | return offset;
210 | #else
211 | return static_cast(tm.tm_gmtoff / 60);
212 | #endif
213 | }
214 |
215 | //Return current thread id as size_t
216 | //It exists because the std::this_thread::get_id() is much slower(espcially under VS 2013)
217 | inline size_t thread_id()
218 | {
219 | #ifdef _WIN32
220 | return static_cast(::GetCurrentThreadId());
221 | #elif __linux__
222 | # if defined(__ANDROID__) && defined(__ANDROID_API__) && (__ANDROID_API__ < 21)
223 | # define SYS_gettid __NR_gettid
224 | # endif
225 | return static_cast(syscall(SYS_gettid));
226 | #else //Default to standard C++11 (OSX and other Unix)
227 | return static_cast(std::hash()(std::this_thread::get_id()));
228 | #endif
229 |
230 | }
231 |
232 |
233 | // wchar support for windows file names (SPDLOG_WCHAR_FILENAMES must be defined)
234 | #if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
235 | #define SPDLOG_FILENAME_T(s) L ## s
236 | inline std::string filename_to_str(const filename_t& filename)
237 | {
238 | std::wstring_convert, wchar_t> c;
239 | return c.to_bytes(filename);
240 | }
241 | #else
242 | #define SPDLOG_FILENAME_T(s) s
243 | inline std::string filename_to_str(const filename_t& filename)
244 | {
245 | return filename;
246 | }
247 | #endif
248 |
249 | } //os
250 | } //details
251 | } //spdlog
252 |
253 |
254 |
--------------------------------------------------------------------------------
/includes/spdlog/details/registry.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright(c) 2015 Gabi Melman.
3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT)
4 | //
5 |
6 | #pragma once
7 |
8 | // Loggers registy of unique name->logger pointer
9 | // An attempt to create a logger with an already existing name will be ignored
10 | // If user requests a non existing logger, nullptr will be returned
11 | // This class is thread safe
12 |
13 | #include
14 | #include
15 | #include
16 | #include
17 |
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 |
25 | namespace spdlog
26 | {
27 | namespace details
28 | {
29 | template class registry_t
30 | {
31 | public:
32 |
33 | void register_logger(std::shared_ptr logger)
34 | {
35 | std::lock_guard lock(_mutex);
36 | auto logger_name = logger->name();
37 | throw_if_exists(logger_name);
38 | _loggers[logger_name] = logger;
39 | }
40 |
41 |
42 | std::shared_ptr get(const std::string& logger_name)
43 | {
44 | std::lock_guard lock(_mutex);
45 | auto found = _loggers.find(logger_name);
46 | return found == _loggers.end() ? nullptr : found->second;
47 | }
48 |
49 | template
50 | std::shared_ptr create(const std::string& logger_name, const It& sinks_begin, const It& sinks_end)
51 | {
52 | std::lock_guard lock(_mutex);
53 | throw_if_exists(logger_name);
54 | std::shared_ptr new_logger;
55 | if (_async_mode)
56 | new_logger = std::make_shared(logger_name, sinks_begin, sinks_end, _async_q_size, _overflow_policy, _worker_warmup_cb, _flush_interval_ms, _worker_teardown_cb);
57 | else
58 | new_logger = std::make_shared(logger_name, sinks_begin, sinks_end);
59 |
60 | if (_formatter)
61 | new_logger->set_formatter(_formatter);
62 |
63 | new_logger->set_level(_level);
64 | //Add to registry
65 | _loggers[logger_name] = new_logger;
66 | return new_logger;
67 | }
68 |
69 | void drop(const std::string& logger_name)
70 | {
71 | std::lock_guard lock(_mutex);
72 | _loggers.erase(logger_name);
73 | }
74 |
75 | void drop_all()
76 | {
77 | std::lock_guard lock(_mutex);
78 | _loggers.clear();
79 | }
80 | std::shared_ptr create(const std::string& logger_name, sinks_init_list sinks)
81 | {
82 | return create(logger_name, sinks.begin(), sinks.end());
83 | }
84 |
85 | std::shared_ptr create(const std::string& logger_name, sink_ptr sink)
86 | {
87 | return create(logger_name, { sink });
88 | }
89 |
90 |
91 | void formatter(formatter_ptr f)
92 | {
93 | std::lock_guard lock(_mutex);
94 | _formatter = f;
95 | for (auto& l : _loggers)
96 | l.second->set_formatter(_formatter);
97 | }
98 |
99 | void set_pattern(const std::string& pattern)
100 | {
101 | std::lock_guard lock(_mutex);
102 | _formatter = std::make_shared(pattern);
103 | for (auto& l : _loggers)
104 | l.second->set_formatter(_formatter);
105 | }
106 |
107 | void set_level(level::level_enum log_level)
108 | {
109 | std::lock_guard lock(_mutex);
110 | for (auto& l : _loggers)
111 | l.second->set_level(log_level);
112 | _level = log_level;
113 | }
114 |
115 | void set_async_mode(size_t q_size, const async_overflow_policy overflow_policy, const std::function& worker_warmup_cb, const std::chrono::milliseconds& flush_interval_ms, const std::function& worker_teardown_cb)
116 | {
117 | std::lock_guard lock(_mutex);
118 | _async_mode = true;
119 | _async_q_size = q_size;
120 | _overflow_policy = overflow_policy;
121 | _worker_warmup_cb = worker_warmup_cb;
122 | _flush_interval_ms = flush_interval_ms;
123 | _worker_teardown_cb = worker_teardown_cb;
124 | }
125 |
126 | void set_sync_mode()
127 | {
128 | std::lock_guard lock(_mutex);
129 | _async_mode = false;
130 | }
131 |
132 | static registry_t& instance()
133 | {
134 | static registry_t s_instance;
135 | return s_instance;
136 | }
137 |
138 | private:
139 | registry_t() {}
140 | registry_t(const registry_t&) = delete;
141 | registry_t& operator=(const registry_t&) = delete;
142 |
143 | void throw_if_exists(const std::string &logger_name)
144 | {
145 | if (_loggers.find(logger_name) != _loggers.end())
146 | throw spdlog_ex("logger with name '" + logger_name + "' already exists");
147 | }
148 | Mutex _mutex;
149 | std::unordered_map > _loggers;
150 | formatter_ptr _formatter;
151 | level::level_enum _level = level::info;
152 | bool _async_mode = false;
153 | size_t _async_q_size = 0;
154 | async_overflow_policy _overflow_policy = async_overflow_policy::block_retry;
155 | std::function _worker_warmup_cb = nullptr;
156 | std::chrono::milliseconds _flush_interval_ms;
157 | std::function _worker_teardown_cb = nullptr;
158 | };
159 | #ifdef SPDLOG_NO_REGISTRY_MUTEX
160 | typedef registry_t registry;
161 | #else
162 | typedef registry_t registry;
163 | #endif
164 | }
165 | }
166 |
--------------------------------------------------------------------------------
/includes/spdlog/details/spdlog_impl.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright(c) 2015 Gabi Melman.
3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT)
4 | //
5 |
6 | #pragma once
7 |
8 | //
9 | // Global registry functions
10 | //
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 |
18 | #include
19 | #include
20 | #include
21 | #include
22 |
23 | inline void spdlog::register_logger(std::shared_ptr logger)
24 | {
25 | return details::registry::instance().register_logger(logger);
26 | }
27 |
28 | inline std::shared_ptr spdlog::get(const std::string& name)
29 | {
30 | return details::registry::instance().get(name);
31 | }
32 |
33 | inline void spdlog::drop(const std::string &name)
34 | {
35 | details::registry::instance().drop(name);
36 | }
37 |
38 | // Create multi/single threaded rotating file logger
39 | inline std::shared_ptr spdlog::rotating_logger_mt(const std::string& logger_name, const filename_t& filename, size_t max_file_size, size_t max_files, bool force_flush)
40 | {
41 | return create(logger_name, filename, SPDLOG_FILENAME_T("txt"), max_file_size, max_files, force_flush);
42 | }
43 |
44 | inline std::shared_ptr spdlog::rotating_logger_st(const std::string& logger_name, const filename_t& filename, size_t max_file_size, size_t max_files, bool force_flush)
45 | {
46 | return create(logger_name, filename, SPDLOG_FILENAME_T("txt"), max_file_size, max_files, force_flush);
47 | }
48 |
49 | // Create file logger which creates new file at midnight):
50 | inline std::shared_ptr spdlog::daily_logger_mt(const std::string& logger_name, const filename_t& filename, int hour, int minute, bool force_flush)
51 | {
52 | return create(logger_name, filename, SPDLOG_FILENAME_T("txt"), hour, minute, force_flush);
53 | }
54 |
55 | inline std::shared_ptr spdlog::daily_logger_st(const std::string& logger_name, const filename_t& filename, int hour, int minute, bool force_flush)
56 | {
57 | return create(logger_name, filename, SPDLOG_FILENAME_T("txt"), hour, minute, force_flush);
58 | }
59 |
60 | // Create stdout/stderr loggers (with optinal color support)
61 | inline std::shared_ptr create_console_logger(const std::string& logger_name, spdlog::sink_ptr sink, bool color)
62 | {
63 | if (color) //use color wrapper sink
64 | sink = std::make_shared(sink);
65 | return spdlog::details::registry::instance().create(logger_name, sink);
66 | }
67 |
68 | inline std::shared_ptr spdlog::stdout_logger_mt(const std::string& logger_name, bool color)
69 | {
70 | return create_console_logger(logger_name, sinks::stdout_sink_mt::instance(), color);
71 | }
72 |
73 | inline std::shared_ptr spdlog::stdout_logger_st(const std::string& logger_name, bool color)
74 | {
75 | return create_console_logger(logger_name, sinks::stdout_sink_st::instance(), color);
76 | }
77 |
78 | inline std::shared_ptr spdlog::stderr_logger_mt(const std::string& logger_name, bool color)
79 | {
80 | return create_console_logger(logger_name, sinks::stderr_sink_mt::instance(), color);
81 | }
82 |
83 | inline std::shared_ptr spdlog::stderr_logger_st(const std::string& logger_name, bool color)
84 | {
85 | return create_console_logger(logger_name, sinks::stderr_sink_st::instance(), color);
86 | }
87 |
88 | #if defined(__linux__) || defined(__APPLE__)
89 | // Create syslog logger
90 | inline std::shared_ptr spdlog::syslog_logger(const std::string& logger_name, const std::string& syslog_ident, int syslog_option)
91 | {
92 | return create(logger_name, syslog_ident, syslog_option);
93 | }
94 | #endif
95 |
96 |
97 | //Create logger with multiple sinks
98 |
99 | inline std::shared_ptr spdlog::create(const std::string& logger_name, spdlog::sinks_init_list sinks)
100 | {
101 | return details::registry::instance().create(logger_name, sinks);
102 | }
103 |
104 |
105 | template
106 | inline std::shared_ptr spdlog::create(const std::string& logger_name, Args... args)
107 | {
108 | sink_ptr sink = std::make_shared(args...);
109 | return details::registry::instance().create(logger_name, { sink });
110 | }
111 |
112 |
113 | template
114 | inline std::shared_ptr spdlog::create(const std::string& logger_name, const It& sinks_begin, const It& sinks_end)
115 | {
116 | return details::registry::instance().create(logger_name, sinks_begin, sinks_end);
117 | }
118 |
119 | inline void spdlog::set_formatter(spdlog::formatter_ptr f)
120 | {
121 | details::registry::instance().formatter(f);
122 | }
123 |
124 | inline void spdlog::set_pattern(const std::string& format_string)
125 | {
126 | return details::registry::instance().set_pattern(format_string);
127 | }
128 |
129 | inline void spdlog::set_level(level::level_enum log_level)
130 | {
131 | return details::registry::instance().set_level(log_level);
132 | }
133 |
134 |
135 | inline void spdlog::set_async_mode(size_t queue_size, const async_overflow_policy overflow_policy, const std::function& worker_warmup_cb, const std::chrono::milliseconds& flush_interval_ms, const std::function& worker_teardown_cb)
136 | {
137 | details::registry::instance().set_async_mode(queue_size, overflow_policy, worker_warmup_cb, flush_interval_ms, worker_teardown_cb);
138 | }
139 |
140 | inline void spdlog::set_sync_mode()
141 | {
142 | details::registry::instance().set_sync_mode();
143 | }
144 |
145 | inline void spdlog::drop_all()
146 | {
147 | details::registry::instance().drop_all();
148 | }
149 |
--------------------------------------------------------------------------------
/includes/spdlog/formatter.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright(c) 2015 Gabi Melman.
3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT)
4 | //
5 |
6 | #pragma once
7 |
8 | #include
9 |
10 | #include
11 | #include
12 | #include
13 |
14 | namespace spdlog
15 | {
16 | namespace details
17 | {
18 | class flag_formatter;
19 | }
20 |
21 | class formatter
22 | {
23 | public:
24 | virtual ~formatter() {}
25 | virtual void format(details::log_msg& msg) = 0;
26 | };
27 |
28 | class pattern_formatter : public formatter
29 | {
30 |
31 | public:
32 | explicit pattern_formatter(const std::string& pattern);
33 | pattern_formatter(const pattern_formatter&) = delete;
34 | pattern_formatter& operator=(const pattern_formatter&) = delete;
35 | void format(details::log_msg& msg) override;
36 | private:
37 | const std::string _pattern;
38 | std::vector> _formatters;
39 | void handle_flag(char flag);
40 | void compile_pattern(const std::string& pattern);
41 | };
42 | }
43 |
44 | #include
45 |
46 |
--------------------------------------------------------------------------------
/includes/spdlog/logger.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright(c) 2015 Gabi Melman.
3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT)
4 | //
5 |
6 | #pragma once
7 |
8 | // Thread safe logger
9 | // Has name, log level, vector of std::shared sink pointers and formatter
10 | // Upon each log write the logger:
11 | // 1. Checks if its log level is enough to log the message
12 | // 2. Format the message using the formatter function
13 | // 3. Pass the formatted message to its sinks to performa the actual logging
14 |
15 | #include
16 | #include
17 | #include
18 |
19 | #include
20 | #include
21 | #include
22 |
23 | namespace spdlog
24 | {
25 |
26 | class logger
27 | {
28 | public:
29 | logger(const std::string& logger_name, sink_ptr single_sink);
30 | logger(const std::string& name, sinks_init_list);
31 | template
32 | logger(const std::string& name, const It& begin, const It& end);
33 |
34 | virtual ~logger();
35 | logger(const logger&) = delete;
36 | logger& operator=(const logger&) = delete;
37 |
38 | void set_level(level::level_enum);
39 | level::level_enum level() const;
40 |
41 | const std::string& name() const;
42 | bool should_log(level::level_enum) const;
43 |
44 | // automatically call flush() after a message of level log_level or higher is emitted
45 | void flush_on(level::level_enum log_level);
46 |
47 | // logger.info(cppformat_string, arg1, arg2, arg3, ...) call style
48 | template details::line_logger trace(const char* fmt, const Args&... args);
49 | template details::line_logger debug(const char* fmt, const Args&... args);
50 | template details::line_logger info(const char* fmt, const Args&... args);
51 | template details::line_logger notice(const char* fmt, const Args&... args);
52 | template details::line_logger warn(const char* fmt, const Args&... args);
53 | template details::line_logger error(const char* fmt, const Args&... args);
54 | template details::line_logger critical(const char* fmt, const Args&... args);
55 | template details::line_logger alert(const char* fmt, const Args&... args);
56 | template details::line_logger emerg(const char* fmt, const Args&... args);
57 |
58 |
59 | // logger.info(msg) << ".." call style
60 | template details::line_logger trace(const T&);
61 | template details::line_logger debug(const T&);
62 | template