@litmusio/miravo-cli-linux-arm64 0.0.0-stage → 0.15.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +199 -0
- package/NOTICE +9 -0
- package/README.md +6 -2
- package/THIRD_PARTY_LICENSES.txt +15289 -0
- package/THIRD_PARTY_NOTICES.md +995 -0
- package/console-dist/assets/AnimatePresence-DWGUB15i.js +9 -0
- package/console-dist/assets/activity-DruTYzT1.js +1 -0
- package/console-dist/assets/api-V5Tf5xfh.js +57 -0
- package/console-dist/assets/arrow-up-right-DOENs04V.js +1 -0
- package/console-dist/assets/asset-detail-D_icTa2K.js +1 -0
- package/console-dist/assets/asset-detail-actions-DIYego9D.js +1 -0
- package/console-dist/assets/backup-power-Q84DVs_z.js +1 -0
- package/console-dist/assets/badge-CdRB4Nd_.js +1 -0
- package/console-dist/assets/boiler-s_q0j7rz.js +1 -0
- package/console-dist/assets/by-path-Cm2TEP7z.js +1 -0
- package/console-dist/assets/check-BTUv4z-H.js +1 -0
- package/console-dist/assets/chevron-down-CqA_2_CH.js +1 -0
- package/console-dist/assets/chevron-right-CVrgKBLR.js +1 -0
- package/console-dist/assets/chiller-r7DzAhJq.js +1 -0
- package/console-dist/assets/chunk-6KYCQHYJ-ga3Yekab.js +3 -0
- package/console-dist/assets/circle-x-BRkh0A1P.js +1 -0
- package/console-dist/assets/commercial-building-Cezt2R6W.js +1 -0
- package/console-dist/assets/compressor-ChZLMC94.js +1 -0
- package/console-dist/assets/console-panel-BnSjjW6l.js +1 -0
- package/console-dist/assets/dialog-BYkdndf9.js +1 -0
- package/console-dist/assets/district-heating-By_6QdGQ.js +1 -0
- package/console-dist/assets/dom-BxZbg3NX.js +1 -0
- package/console-dist/assets/download-CvjDP5mu.js +1 -0
- package/console-dist/assets/fira-code-cyrillic-ext-wght-normal-DhYMMuQd.woff2 +0 -0
- package/console-dist/assets/fira-code-cyrillic-wght-normal-Y3u8pIsh.woff2 +0 -0
- package/console-dist/assets/fira-code-greek-ext-wght-normal-wWus70Ix.woff2 +0 -0
- package/console-dist/assets/fira-code-greek-wght-normal-B2SviObF.woff2 +0 -0
- package/console-dist/assets/fira-code-latin-ext-wght-normal-Dvfvaomy.woff2 +0 -0
- package/console-dist/assets/fira-code-latin-wght-normal-CHoedHDv.woff2 +0 -0
- package/console-dist/assets/fira-code-symbols2-wght-normal-CE6EOz_n.woff2 +0 -0
- package/console-dist/assets/floor-page-DIUJBBhh.js +1 -0
- package/console-dist/assets/floor-page-E-0txA4z.css +1 -0
- package/console-dist/assets/format-YLUJ7AXt.js +1 -0
- package/console-dist/assets/genset-C6_EUoFo.js +1 -0
- package/console-dist/assets/index-BrlZMcSu.js +15 -0
- package/console-dist/assets/index-eZjXAdLh.css +2 -0
- package/console-dist/assets/loader-circle-w3T2fxvn.js +1 -0
- package/console-dist/assets/login-CpbaxAVs.js +136 -0
- package/console-dist/assets/not-found-CZjkulKD.js +1 -0
- package/console-dist/assets/pharma-cleanroom-CT2M_Mbh.js +1 -0
- package/console-dist/assets/preload-helper-7y9sWmk5.js +1 -0
- package/console-dist/assets/react-DRt7cCXI.js +1 -0
- package/console-dist/assets/rolldown-runtime-BWaJ3C7D.js +1 -0
- package/console-dist/assets/rtu-ByogcRPI.js +1 -0
- package/console-dist/assets/runtime-link-D88Db2wY.js +1 -0
- package/console-dist/assets/schibsted-grotesk-latin-ext-wght-normal-hsMS0n0O.woff2 +0 -0
- package/console-dist/assets/schibsted-grotesk-latin-wght-normal-Bb8VGrTG.woff2 +0 -0
- package/console-dist/assets/server-B0q1NVkV.js +1 -0
- package/console-dist/assets/shallow-mIK1Qu8X.js +1 -0
- package/console-dist/assets/smart-factory-gfMWfMWM.js +1 -0
- package/console-dist/assets/source-host-miravo-BW-SKMTe.js +1 -0
- package/console-dist/assets/stages-EYRT12Yp.js +1 -0
- package/console-dist/assets/status-DQYLUbXs.js +1 -0
- package/console-dist/assets/tank-Btg5piqB.js +1 -0
- package/console-dist/assets/tooltip-Dfmuq2yz.js +1 -0
- package/console-dist/assets/trash-2-BAh5-hxl.js +1 -0
- package/console-dist/assets/triangle-alert-3Ab-dBrN.js +1 -0
- package/console-dist/assets/use-engine-command-mutation-BmSUqrCp.js +1 -0
- package/console-dist/assets/use-transition-navigate-DIfW9U34.js +2 -0
- package/console-dist/assets/useQuery-yLeYL5Es.js +1 -0
- package/console-dist/assets/utils-D6wrZy-b.js +1 -0
- package/console-dist/assets/validation-DEb_QCoK.js +1 -0
- package/console-dist/assets/vendor-charts-Bquh2dWE.js +56 -0
- package/console-dist/assets/vendor-table-5YnGQUhO.js +4 -0
- package/console-dist/assets/vendor-ui-BGeFlRLR.js +1 -0
- package/console-dist/assets/water-treatment-DbSVGWoj.js +1 -0
- package/console-dist/icon.png +0 -0
- package/console-dist/index.html +53 -0
- package/console-dist/miravo-logo.webp +0 -0
- package/licenses/EPL-2.0.txt +80 -0
- package/licenses/GCC-exception-3.1.txt +33 -0
- package/licenses/GPL-2.0-only.txt +117 -0
- package/licenses/GPL-3.0-only.txt +232 -0
- package/licenses/LGPL-2.1-only.txt +176 -0
- package/licenses/MPL-2.0.txt +373 -0
- package/licenses/OFL-1.1.txt +93 -0
- package/licenses/overrides/@headlessui+vue@1.7.23.txt +24 -0
- package/licenses/overrides/@next+env@16.4.6.txt +24 -0
- package/licenses/overrides/@radix-ui+react-compose-refs@1.1.2.txt +24 -0
- package/licenses/overrides/@radix-ui+react-context@1.1.2.txt +24 -0
- package/licenses/overrides/@radix-ui+react-direction@1.1.1.txt +24 -0
- package/licenses/overrides/@radix-ui+react-id@1.1.1.txt +24 -0
- package/licenses/overrides/@radix-ui+react-use-callback-ref@1.1.1.txt +24 -0
- package/licenses/overrides/@radix-ui+react-use-escape-keydown@1.1.1.txt +24 -0
- package/licenses/overrides/@radix-ui+react-use-layout-effect@1.1.1.txt +24 -0
- package/licenses/overrides/@radix-ui+react-use-rect@1.1.1.txt +24 -0
- package/licenses/overrides/@radix-ui+react-use-size@1.1.1.txt +24 -0
- package/licenses/overrides/@radix-ui+rect@1.1.1.txt +24 -0
- package/licenses/overrides/@replit+codemirror-css-color-picker@6.3.0.txt +6 -0
- package/licenses/overrides/@scalar+openapi-types@0.8.0.txt +24 -0
- package/licenses/overrides/@scalar+openapi-types@0.9.10.txt +24 -0
- package/licenses/overrides/@scalar+openapi-types@0.9.7.txt +24 -0
- package/licenses/overrides/@scalar+openapi-types@0.9.9.txt +24 -0
- package/licenses/overrides/@scalar+postman-to-openapi@0.7.1.txt +24 -0
- package/licenses/overrides/@scalar+schemas@0.19.0.txt +24 -0
- package/licenses/overrides/@scalar+workspace-store@0.46.3.txt +24 -0
- package/licenses/overrides/@scalar+workspace-store@0.75.0.txt +24 -0
- package/licenses/overrides/assert-plus@1.0.0.txt +24 -0
- package/licenses/overrides/client-only@0.0.1.txt +24 -0
- package/licenses/overrides/embla-carousel-react@8.6.0.txt +24 -0
- package/licenses/overrides/embla-carousel-reactive-utils@8.6.0.txt +24 -0
- package/licenses/overrides/embla-carousel@8.6.0.txt +24 -0
- package/licenses/overrides/fastdom@1.0.12.txt +12 -0
- package/licenses/overrides/precond@0.2.3.txt +22 -0
- package/licenses/overrides/react-remove-scroll-bar@2.3.8.txt +24 -0
- package/licenses/overrides/strictdom@1.0.1.txt +12 -0
- package/licenses/overrides/victory-vendor@36.9.2.txt +33 -0
- package/licenses/runtime/Bun-1.4.3-LICENSE.md +85 -0
- package/licenses/runtime/ICU-78.1-LICENSE.txt +568 -0
- package/licenses/runtime/bun-components/boringssl.txt +238 -0
- package/licenses/runtime/bun-components/brotli.txt +19 -0
- package/licenses/runtime/bun-components/c-ares.txt +24 -0
- package/licenses/runtime/bun-components/highway.txt +371 -0
- package/licenses/runtime/bun-components/libarchive.txt +65 -0
- package/licenses/runtime/bun-components/libbase64.txt +28 -0
- package/licenses/runtime/bun-components/libdeflate.txt +22 -0
- package/licenses/runtime/bun-components/libjpeg-turbo.txt +147 -0
- package/licenses/runtime/bun-components/libspng.txt +25 -0
- package/licenses/runtime/bun-components/libuv.txt +19 -0
- package/licenses/runtime/bun-components/libwebp.txt +30 -0
- package/licenses/runtime/bun-components/llvm.txt +311 -0
- package/licenses/runtime/bun-components/lol-html.txt +27 -0
- package/licenses/runtime/bun-components/ls-hpack.txt +21 -0
- package/licenses/runtime/bun-components/ls-qpack.txt +21 -0
- package/licenses/runtime/bun-components/lsquic-chrome.txt +32 -0
- package/licenses/runtime/bun-components/lsquic.txt +21 -0
- package/licenses/runtime/bun-components/mimalloc.txt +21 -0
- package/licenses/runtime/bun-components/picohttpparser.txt +24 -0
- package/licenses/runtime/bun-components/simdutf-apache.txt +201 -0
- package/licenses/runtime/bun-components/simdutf-mit.txt +18 -0
- package/licenses/runtime/bun-components/tigerbeetle.txt +177 -0
- package/licenses/runtime/bun-components/tinycc.txt +504 -0
- package/licenses/runtime/bun-components/typescript-go.txt +55 -0
- package/licenses/runtime/bun-components/usockets.txt +201 -0
- package/licenses/runtime/bun-components/uucode.txt +30 -0
- package/licenses/runtime/bun-components/uwebsockets.txt +201 -0
- package/licenses/runtime/bun-components/xxhash.txt +31 -0
- package/licenses/runtime/bun-components/zlib-ng.txt +19 -0
- package/licenses/runtime/bun-components/zstd-copying.txt +339 -0
- package/licenses/runtime/bun-components/zstd.txt +30 -0
- package/licenses/runtime/musl-1.2.6-COPYRIGHT.txt +193 -0
- package/miravo +4 -0
- package/native/S7-NOTICES.txt +11 -0
- package/native/miravo-s7.node +0 -0
- package/native/s7-source/CMakeLists.txt +23 -0
- package/native/s7-source/NODE-SNAP7-LICENSE +24 -0
- package/native/s7-source/addon.cpp +124 -0
- package/native/s7-source/bridge.cpp +150 -0
- package/native/s7-source/node-api-headers/LICENSE +21 -0
- package/native/s7-source/node-api-headers/include/js_native_api.h +591 -0
- package/native/s7-source/node-api-headers/include/js_native_api_types.h +213 -0
- package/native/s7-source/node-api-headers/include/node_api.h +265 -0
- package/native/s7-source/node-api-headers/include/node_api_types.h +58 -0
- package/native/s7-source/node-api-windows.h +78 -0
- package/native/s7-source/snap7/HISTORY.txt +277 -0
- package/native/s7-source/snap7/gpl.txt +674 -0
- package/native/s7-source/snap7/lgpl-3.0.txt +165 -0
- package/native/s7-source/snap7/src/core/miravo_request_validation.h +72 -0
- package/native/s7-source/snap7/src/core/s7_client.cpp +503 -0
- package/native/s7-source/snap7/src/core/s7_client.h +104 -0
- package/native/s7-source/snap7/src/core/s7_firmware.h +1256 -0
- package/native/s7-source/snap7/src/core/s7_isotcp.cpp +541 -0
- package/native/s7-source/snap7/src/core/s7_isotcp.h +271 -0
- package/native/s7-source/snap7/src/core/s7_micro_client.cpp +3328 -0
- package/native/s7-source/snap7/src/core/s7_micro_client.h +364 -0
- package/native/s7-source/snap7/src/core/s7_partner.cpp +1178 -0
- package/native/s7-source/snap7/src/core/s7_partner.h +284 -0
- package/native/s7-source/snap7/src/core/s7_peer.cpp +121 -0
- package/native/s7-source/snap7/src/core/s7_peer.h +58 -0
- package/native/s7-source/snap7/src/core/s7_server.cpp +2161 -0
- package/native/s7-source/snap7/src/core/s7_server.h +261 -0
- package/native/s7-source/snap7/src/core/s7_text.cpp +788 -0
- package/native/s7-source/snap7/src/core/s7_text.h +49 -0
- package/native/s7-source/snap7/src/core/s7_types.h +1066 -0
- package/native/s7-source/snap7/src/lib/snap7.def +129 -0
- package/native/s7-source/snap7/src/lib/snap7_libmain.cpp +1196 -0
- package/native/s7-source/snap7/src/lib/snap7_libmain.h +201 -0
- package/native/s7-source/snap7/src/sys/snap_msgsock.cpp +958 -0
- package/native/s7-source/snap7/src/sys/snap_msgsock.h +339 -0
- package/native/s7-source/snap7/src/sys/snap_platform.h +152 -0
- package/native/s7-source/snap7/src/sys/snap_sysutils.cpp +73 -0
- package/native/s7-source/snap7/src/sys/snap_sysutils.h +39 -0
- package/native/s7-source/snap7/src/sys/snap_tcpsrvr.cpp +487 -0
- package/native/s7-source/snap7/src/sys/snap_tcpsrvr.h +247 -0
- package/native/s7-source/snap7/src/sys/snap_threads.cpp +162 -0
- package/native/s7-source/snap7/src/sys/snap_threads.h +45 -0
- package/native/s7-source/snap7/src/sys/sol_threads.h +208 -0
- package/native/s7-source/snap7/src/sys/unix_threads.h +228 -0
- package/native/s7-source/snap7/src/sys/win_threads.h +159 -0
- package/nodesets/.ignore +1 -0
- package/nodesets/1.02/FTNIR.NodeSet2.xml +819 -0
- package/nodesets/1.02/Opc.Ua.Adi.NodeSet2.xml +8301 -0
- package/nodesets/1.02/Opc.Ua.Di.NodeSet2.xml +1785 -0
- package/nodesets/Opc.ISA95.NodeSet2.xml +3589 -0
- package/nodesets/Opc.Ua.AMB.NodeSet2.xml +1395 -0
- package/nodesets/Opc.Ua.Adi.NodeSet2.xml +8301 -0
- package/nodesets/Opc.Ua.Adi.Types.xsd +104 -0
- package/nodesets/Opc.Ua.AutoID.NodeSet2.xml +6062 -0
- package/nodesets/Opc.Ua.CNC.NodeSet.xml +15875 -0
- package/nodesets/Opc.Ua.CommercialKitchenEquipment.NodeSet2.xml +12096 -0
- package/nodesets/Opc.Ua.Di.NodeSet2.xml +6042 -0
- package/nodesets/Opc.Ua.Di.Types.xsd +161 -0
- package/nodesets/Opc.Ua.Eumabois.Nodeset2.xml +2483 -0
- package/nodesets/Opc.Ua.Gds.NodeSet2.xml +8282 -0
- package/nodesets/Opc.Ua.Glass.NodeSet2.xml +5100 -0
- package/nodesets/Opc.Ua.IA.NodeSet2.xml +1782 -0
- package/nodesets/Opc.Ua.IOLink.NodeSet2.xml +4374 -0
- package/nodesets/Opc.Ua.IOLinkIODD.NodeSet2.xml +139 -0
- package/nodesets/Opc.Ua.IRDI.NodeSet2.xml +2243 -0
- package/nodesets/Opc.Ua.Ijt.Base.NodeSet2.xml +19459 -0
- package/nodesets/Opc.Ua.Ijt.Tightening.NodeSet2.xml +883 -0
- package/nodesets/Opc.Ua.LADS.NodeSet2.xml +7086 -0
- package/nodesets/Opc.Ua.MachineTool.NodeSet2.xml +7884 -0
- package/nodesets/Opc.Ua.MachineVision.NodeSet2.xml +17324 -0
- package/nodesets/Opc.Ua.Machinery.Jobs.Nodeset2.xml +1249 -0
- package/nodesets/Opc.Ua.Machinery.NodeSet2.xml +2099 -0
- package/nodesets/Opc.Ua.Machinery.ProcessValues.NodeSet2.xml +1858 -0
- package/nodesets/Opc.Ua.Machinery_Result.NodeSet2.xml +2640 -0
- package/nodesets/Opc.Ua.MetalForming.NodeSet2.xml +1577 -0
- package/nodesets/Opc.Ua.NodeSet2.xml +81975 -0
- package/nodesets/Opc.Ua.PADIM.NodeSet2.xml +14131 -0
- package/nodesets/Opc.Ua.PackML.NodeSet2.xml +3030 -0
- package/nodesets/Opc.Ua.Robotics.NodeSet2.xml +7409 -0
- package/nodesets/Opc.Ua.Scales.NodeSet2.xml +15817 -0
- package/nodesets/Opc.Ua.Types.bsd +3499 -0
- package/nodesets/Opc.Ua.Weihenstephan.NodeSet2.xml +821 -0
- package/nodesets/Opc.Ua.Woodworking.NodeSet2.xml +17831 -0
- package/nodesets/UANodeSet.xsd +497 -0
- package/nodesets/opc.ua.isa95-jobcontrol.nodeset2.xml +4594 -0
- package/package.json +37 -4
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/*=============================================================================|
|
|
2
|
+
| PROJECT SNAP7 1.3.0 |
|
|
3
|
+
|==============================================================================|
|
|
4
|
+
| Copyright (C) 2013, 2015 Davide Nardella |
|
|
5
|
+
| All rights reserved. |
|
|
6
|
+
|==============================================================================|
|
|
7
|
+
| SNAP7 is free software: you can redistribute it and/or modify |
|
|
8
|
+
| it under the terms of the Lesser GNU General Public License as published by |
|
|
9
|
+
| the Free Software Foundation, either version 3 of the License, or |
|
|
10
|
+
| (at your option) any later version. |
|
|
11
|
+
| |
|
|
12
|
+
| It means that you can distribute your commercial software linked with |
|
|
13
|
+
| SNAP7 without the requirement to distribute the source code of your |
|
|
14
|
+
| application and without the requirement that your application be itself |
|
|
15
|
+
| distributed under LGPL. |
|
|
16
|
+
| |
|
|
17
|
+
| SNAP7 is distributed in the hope that it will be useful, |
|
|
18
|
+
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
19
|
+
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
20
|
+
| Lesser GNU General Public License for more details. |
|
|
21
|
+
| |
|
|
22
|
+
| You should have received a copy of the GNU General Public License and a |
|
|
23
|
+
| copy of Lesser GNU General Public License along with Snap7. |
|
|
24
|
+
| If not, see http://www.gnu.org/licenses/ |
|
|
25
|
+
|=============================================================================*/
|
|
26
|
+
#ifndef snap_tcpsrvr_h
|
|
27
|
+
#define snap_tcpsrvr_h
|
|
28
|
+
//---------------------------------------------------------------------------
|
|
29
|
+
#include "snap_msgsock.h"
|
|
30
|
+
#include "snap_threads.h"
|
|
31
|
+
//---------------------------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
#define MaxWorkers 1024
|
|
34
|
+
#define MaxEvents 1500
|
|
35
|
+
|
|
36
|
+
const int SrvStopped = 0;
|
|
37
|
+
const int SrvRunning = 1;
|
|
38
|
+
const int SrvError = 2;
|
|
39
|
+
|
|
40
|
+
const longword evcServerStarted = 0x00000001;
|
|
41
|
+
const longword evcServerStopped = 0x00000002;
|
|
42
|
+
const longword evcListenerCannotStart = 0x00000004;
|
|
43
|
+
const longword evcClientAdded = 0x00000008;
|
|
44
|
+
const longword evcClientRejected = 0x00000010;
|
|
45
|
+
const longword evcClientNoRoom = 0x00000020;
|
|
46
|
+
const longword evcClientException = 0x00000040;
|
|
47
|
+
const longword evcClientDisconnected = 0x00000080;
|
|
48
|
+
const longword evcClientTerminated = 0x00000100;
|
|
49
|
+
const longword evcClientsDropped = 0x00000200;
|
|
50
|
+
const longword evcReserved_00000400 = 0x00000400;
|
|
51
|
+
const longword evcReserved_00000800 = 0x00000800;
|
|
52
|
+
const longword evcReserved_00001000 = 0x00001000;
|
|
53
|
+
const longword evcReserved_00002000 = 0x00002000;
|
|
54
|
+
const longword evcReserved_00004000 = 0x00004000;
|
|
55
|
+
const longword evcReserved_00008000 = 0x00008000;
|
|
56
|
+
|
|
57
|
+
// Server Interface errors
|
|
58
|
+
const longword errSrvBase = 0x0000FFFF;
|
|
59
|
+
const longword errSrvMask = 0xFFFF0000;
|
|
60
|
+
const longword errSrvCannotStart = 0x00100000;
|
|
61
|
+
|
|
62
|
+
const longword ThTimeout = 2000; // Thread timeout
|
|
63
|
+
const longword WkTimeout = 3000; // Workers termination timeout
|
|
64
|
+
|
|
65
|
+
#pragma pack(1)
|
|
66
|
+
|
|
67
|
+
typedef struct{
|
|
68
|
+
time_t EvtTime; // Timestamp
|
|
69
|
+
int EvtSender; // Sender
|
|
70
|
+
longword EvtCode; // Event code
|
|
71
|
+
word EvtRetCode; // Event result
|
|
72
|
+
word EvtParam1; // Param 1 (if available)
|
|
73
|
+
word EvtParam2; // Param 2 (if available)
|
|
74
|
+
word EvtParam3; // Param 3 (if available)
|
|
75
|
+
word EvtParam4; // Param 4 (if available)
|
|
76
|
+
}TSrvEvent, *PSrvEvent;
|
|
77
|
+
|
|
78
|
+
extern "C"
|
|
79
|
+
{
|
|
80
|
+
typedef void (S7API *pfn_SrvCallBack)(void * usrPtr, PSrvEvent PEvent, int Size);
|
|
81
|
+
}
|
|
82
|
+
#pragma pack()
|
|
83
|
+
|
|
84
|
+
//---------------------------------------------------------------------------
|
|
85
|
+
// EVENTS QUEUE
|
|
86
|
+
//---------------------------------------------------------------------------
|
|
87
|
+
class TMsgEventQueue
|
|
88
|
+
{
|
|
89
|
+
private:
|
|
90
|
+
int IndexIn; // <-- insert index
|
|
91
|
+
int IndexOut; // --> extract index
|
|
92
|
+
int Max; // Buffer upper bound [0..Max]
|
|
93
|
+
int FCapacity; // Queue capacity
|
|
94
|
+
pbyte Buffer;
|
|
95
|
+
int FBlockSize;
|
|
96
|
+
public:
|
|
97
|
+
TMsgEventQueue(const int Capacity, const int BlockSize);
|
|
98
|
+
~TMsgEventQueue();
|
|
99
|
+
void Flush();
|
|
100
|
+
void Insert(void *lpdata);
|
|
101
|
+
bool Extract(void *lpdata);
|
|
102
|
+
bool Empty();
|
|
103
|
+
bool Full();
|
|
104
|
+
};
|
|
105
|
+
typedef TMsgEventQueue *PMsgEventQueue;
|
|
106
|
+
|
|
107
|
+
//---------------------------------------------------------------------------
|
|
108
|
+
// WORKER THREAD
|
|
109
|
+
//---------------------------------------------------------------------------
|
|
110
|
+
class TCustomMsgServer; // forward declaration
|
|
111
|
+
|
|
112
|
+
// It's created when connection is accepted, it will interface with the client.
|
|
113
|
+
class TMsgWorkerThread : public TSnapThread
|
|
114
|
+
{
|
|
115
|
+
private:
|
|
116
|
+
TCustomMsgServer *FServer;
|
|
117
|
+
protected:
|
|
118
|
+
TMsgSocket *WorkerSocket;
|
|
119
|
+
public:
|
|
120
|
+
int Index;
|
|
121
|
+
friend class TCustomMsgServer;
|
|
122
|
+
TMsgWorkerThread(TMsgSocket *Socket, TCustomMsgServer *Server);
|
|
123
|
+
void Execute();
|
|
124
|
+
};
|
|
125
|
+
typedef TMsgWorkerThread *PMsgWorkerThread;
|
|
126
|
+
|
|
127
|
+
//---------------------------------------------------------------------------
|
|
128
|
+
// LISTENER THREAD
|
|
129
|
+
//---------------------------------------------------------------------------
|
|
130
|
+
// It listens for incoming connection.
|
|
131
|
+
class TMsgListenerThread : public TSnapThread
|
|
132
|
+
{
|
|
133
|
+
private:
|
|
134
|
+
TMsgSocket *FListener;
|
|
135
|
+
TCustomMsgServer *FServer;
|
|
136
|
+
public:
|
|
137
|
+
TMsgListenerThread(TMsgSocket *Listener, TCustomMsgServer *Server);
|
|
138
|
+
void Execute();
|
|
139
|
+
};
|
|
140
|
+
typedef TMsgListenerThread *PMsgListenerThread;
|
|
141
|
+
|
|
142
|
+
//---------------------------------------------------------------------------
|
|
143
|
+
// TCP SERVER
|
|
144
|
+
//---------------------------------------------------------------------------
|
|
145
|
+
typedef TMsgSocket *PWorkerSocket;
|
|
146
|
+
|
|
147
|
+
class TCustomMsgServer
|
|
148
|
+
{
|
|
149
|
+
private:
|
|
150
|
+
int FLastError;
|
|
151
|
+
char FLocalAddress[16];
|
|
152
|
+
// Socket listener
|
|
153
|
+
PMsgSocket SockListener;
|
|
154
|
+
// Server listener
|
|
155
|
+
PMsgListenerThread ServerThread;
|
|
156
|
+
// Critical section to lock Workers list activities
|
|
157
|
+
PSnapCriticalSection CSList;
|
|
158
|
+
// Event queue
|
|
159
|
+
PMsgEventQueue FEventQueue;
|
|
160
|
+
// Callback related
|
|
161
|
+
pfn_SrvCallBack OnEvent;
|
|
162
|
+
void *FUsrPtr;
|
|
163
|
+
// private methods
|
|
164
|
+
int StartListener();
|
|
165
|
+
void LockList();
|
|
166
|
+
void UnlockList();
|
|
167
|
+
int FirstFree();
|
|
168
|
+
protected:
|
|
169
|
+
bool Destroying;
|
|
170
|
+
// Critical section to lock Event activities
|
|
171
|
+
PSnapCriticalSection CSEvent;
|
|
172
|
+
// Workers list
|
|
173
|
+
void *Workers[MaxWorkers];
|
|
174
|
+
// Terminates all worker threads
|
|
175
|
+
virtual void TerminateAll();
|
|
176
|
+
// Kills all worker threads that are unresponsive
|
|
177
|
+
void KillAll();
|
|
178
|
+
// if (true the connection is accepted, otherwise the connection
|
|
179
|
+
// is closed gracefully
|
|
180
|
+
virtual bool CanAccept(socket_t Socket);
|
|
181
|
+
// Returns the class of the worker socket, override it for real servers
|
|
182
|
+
virtual PWorkerSocket CreateWorkerSocket(socket_t Sock);
|
|
183
|
+
// Handles the event
|
|
184
|
+
virtual void DoEvent(int Sender, longword Code, word RetCode, word Param1,
|
|
185
|
+
word Param2, word Param3, word Param4);
|
|
186
|
+
// Delete the worker from the list (It's invoked by Worker Thread)
|
|
187
|
+
void Delete(int Index);
|
|
188
|
+
// Incoming connection (It's invoked by ServerThread, the listener)
|
|
189
|
+
virtual void Incoming(socket_t Sock);
|
|
190
|
+
public:
|
|
191
|
+
friend class TMsgWorkerThread;
|
|
192
|
+
friend class TMsgListenerThread;
|
|
193
|
+
word LocalPort;
|
|
194
|
+
longword LocalBind;
|
|
195
|
+
longword LogMask;
|
|
196
|
+
longword EventMask;
|
|
197
|
+
int Status;
|
|
198
|
+
int ClientsCount;
|
|
199
|
+
int MaxClients;
|
|
200
|
+
TCustomMsgServer();
|
|
201
|
+
virtual ~TCustomMsgServer();
|
|
202
|
+
// Starts the server
|
|
203
|
+
int Start();
|
|
204
|
+
int StartTo(const char *Address, word Port);
|
|
205
|
+
// Stops the server
|
|
206
|
+
void Stop();
|
|
207
|
+
// Sets Event callback
|
|
208
|
+
int SetEventsCallBack(pfn_SrvCallBack PCallBack, void *UsrPtr);
|
|
209
|
+
// Pick an event from the circular queue
|
|
210
|
+
bool PickEvent(void *pEvent);
|
|
211
|
+
// Returns true if (the Event queue is empty
|
|
212
|
+
bool EventEmpty();
|
|
213
|
+
// Flushes Event queue
|
|
214
|
+
void EventsFlush();
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
//---------------------------------------------------------------------------
|
|
218
|
+
// TCP WORKER
|
|
219
|
+
//---------------------------------------------------------------------------
|
|
220
|
+
// Default worker class, a simply tcp echo to test the connection and
|
|
221
|
+
// data I/O to use the server outside the project
|
|
222
|
+
class TEcoTcpWorker : public TMsgSocket
|
|
223
|
+
{
|
|
224
|
+
public:
|
|
225
|
+
bool Execute()
|
|
226
|
+
{
|
|
227
|
+
byte Buffer[4096];
|
|
228
|
+
int Size;
|
|
229
|
+
|
|
230
|
+
if (CanRead(WorkInterval)) // Small time to avoid time wait during the close
|
|
231
|
+
{
|
|
232
|
+
Receive(&Buffer,sizeof(Buffer),Size);
|
|
233
|
+
if ((LastTcpError==0) && (Size>0))
|
|
234
|
+
{
|
|
235
|
+
SendPacket(&Buffer,Size);
|
|
236
|
+
return LastTcpError==0;
|
|
237
|
+
}
|
|
238
|
+
else
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
else
|
|
242
|
+
return true;
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
//---------------------------------------------------------------------------
|
|
247
|
+
#endif // snap_tcpsrvr_h
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/*=============================================================================|
|
|
2
|
+
| PROJECT SNAP7 1.3.0 |
|
|
3
|
+
|==============================================================================|
|
|
4
|
+
| Copyright (C) 2013, 2015 Davide Nardella |
|
|
5
|
+
| All rights reserved. |
|
|
6
|
+
|==============================================================================|
|
|
7
|
+
| SNAP7 is free software: you can redistribute it and/or modify |
|
|
8
|
+
| it under the terms of the Lesser GNU General Public License as published by |
|
|
9
|
+
| the Free Software Foundation, either version 3 of the License, or |
|
|
10
|
+
| (at your option) any later version. |
|
|
11
|
+
| |
|
|
12
|
+
| It means that you can distribute your commercial software linked with |
|
|
13
|
+
| SNAP7 without the requirement to distribute the source code of your |
|
|
14
|
+
| application and without the requirement that your application be itself |
|
|
15
|
+
| distributed under LGPL. |
|
|
16
|
+
| |
|
|
17
|
+
| SNAP7 is distributed in the hope that it will be useful, |
|
|
18
|
+
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
19
|
+
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
20
|
+
| Lesser GNU General Public License for more details. |
|
|
21
|
+
| |
|
|
22
|
+
| You should have received a copy of the GNU General Public License and a |
|
|
23
|
+
| copy of Lesser GNU General Public License along with Snap7. |
|
|
24
|
+
| If not, see http://www.gnu.org/licenses/ |
|
|
25
|
+
|=============================================================================*/
|
|
26
|
+
|
|
27
|
+
#include "snap_threads.h"
|
|
28
|
+
//---------------------------------------------------------------------------
|
|
29
|
+
#ifdef OS_WINDOWS
|
|
30
|
+
DWORD WINAPI ThreadProc(LPVOID param)
|
|
31
|
+
#else
|
|
32
|
+
|
|
33
|
+
void* ThreadProc(void* param)
|
|
34
|
+
#endif
|
|
35
|
+
{
|
|
36
|
+
PSnapThread Thread;
|
|
37
|
+
// Unix but not Solaris
|
|
38
|
+
#if (defined(POSIX) || defined(OS_OSX)) && (!defined(OS_SOLARIS_NATIVE_THREADS))
|
|
39
|
+
int last_type, last_state;
|
|
40
|
+
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &last_type);
|
|
41
|
+
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &last_state);
|
|
42
|
+
#endif
|
|
43
|
+
Thread = PSnapThread(param);
|
|
44
|
+
|
|
45
|
+
if (!Thread->Terminated)
|
|
46
|
+
try
|
|
47
|
+
{
|
|
48
|
+
Thread->Execute();
|
|
49
|
+
} catch (...)
|
|
50
|
+
{
|
|
51
|
+
};
|
|
52
|
+
Thread->Closed = true;
|
|
53
|
+
if (Thread->FreeOnTerminate)
|
|
54
|
+
{
|
|
55
|
+
delete Thread;
|
|
56
|
+
};
|
|
57
|
+
#ifdef OS_WINDOWS
|
|
58
|
+
ExitThread(0);
|
|
59
|
+
#endif
|
|
60
|
+
#if defined(POSIX) && (!defined(OS_SOLARIS_NATIVE_THREADS))
|
|
61
|
+
pthread_exit((void*)0);
|
|
62
|
+
#endif
|
|
63
|
+
#if defined(OS_OSX)
|
|
64
|
+
pthread_exit((void*)0);
|
|
65
|
+
#endif
|
|
66
|
+
#ifdef OS_SOLARIS_NATIVE_THREADS
|
|
67
|
+
thr_exit((void*)0);
|
|
68
|
+
#endif
|
|
69
|
+
return 0; // never reach, only to avoid compiler warning
|
|
70
|
+
}
|
|
71
|
+
//---------------------------------------------------------------------------
|
|
72
|
+
TSnapThread::TSnapThread()
|
|
73
|
+
{
|
|
74
|
+
Started = false;
|
|
75
|
+
Closed=false;
|
|
76
|
+
Terminated = false;
|
|
77
|
+
FreeOnTerminate = false;
|
|
78
|
+
}
|
|
79
|
+
//---------------------------------------------------------------------------
|
|
80
|
+
TSnapThread::~TSnapThread()
|
|
81
|
+
{
|
|
82
|
+
if (Started && !Closed)
|
|
83
|
+
{
|
|
84
|
+
Terminate();
|
|
85
|
+
Join();
|
|
86
|
+
};
|
|
87
|
+
#ifdef OS_WINDOWS
|
|
88
|
+
if (Started)
|
|
89
|
+
CloseHandle(th);
|
|
90
|
+
#endif
|
|
91
|
+
}
|
|
92
|
+
//---------------------------------------------------------------------------
|
|
93
|
+
void TSnapThread::ThreadCreate()
|
|
94
|
+
{
|
|
95
|
+
#ifdef OS_WINDOWS
|
|
96
|
+
th = CreateThread(0, 0, ThreadProc, this, 0, 0);
|
|
97
|
+
#endif
|
|
98
|
+
#if defined(POSIX) && (!defined(OS_SOLARIS_NATIVE_THREADS))
|
|
99
|
+
pthread_attr_t a;
|
|
100
|
+
pthread_attr_init(&a);
|
|
101
|
+
pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED);
|
|
102
|
+
pthread_create(&th, &a, &ThreadProc, this);
|
|
103
|
+
#endif
|
|
104
|
+
#if defined(OS_OSX)
|
|
105
|
+
pthread_create(&th, 0, &ThreadProc, this);
|
|
106
|
+
#endif
|
|
107
|
+
#ifdef OS_SOLARIS_NATIVE_THREADS
|
|
108
|
+
thr_create(0, // default stack base
|
|
109
|
+
0, // default stack size
|
|
110
|
+
&ThreadProc, // Thread routine
|
|
111
|
+
this, // argument
|
|
112
|
+
0,
|
|
113
|
+
&th);
|
|
114
|
+
#endif
|
|
115
|
+
}
|
|
116
|
+
//---------------------------------------------------------------------------
|
|
117
|
+
void TSnapThread::Start()
|
|
118
|
+
{
|
|
119
|
+
if (!Started)
|
|
120
|
+
{
|
|
121
|
+
ThreadCreate();
|
|
122
|
+
Started = true;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//---------------------------------------------------------------------------
|
|
126
|
+
void TSnapThread::Terminate()
|
|
127
|
+
{
|
|
128
|
+
Terminated = true;
|
|
129
|
+
}
|
|
130
|
+
//---------------------------------------------------------------------------
|
|
131
|
+
void TSnapThread::Kill()
|
|
132
|
+
{
|
|
133
|
+
if (Started && !Closed)
|
|
134
|
+
{
|
|
135
|
+
ThreadKill();
|
|
136
|
+
Closed = true;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
//---------------------------------------------------------------------------
|
|
140
|
+
void TSnapThread::Join()
|
|
141
|
+
{
|
|
142
|
+
if (Started && !Closed)
|
|
143
|
+
{
|
|
144
|
+
ThreadJoin();
|
|
145
|
+
Closed = true;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
//---------------------------------------------------------------------------
|
|
149
|
+
longword TSnapThread::WaitFor(uint64_t Timeout)
|
|
150
|
+
{
|
|
151
|
+
if (Started)
|
|
152
|
+
{
|
|
153
|
+
if (!Closed)
|
|
154
|
+
return ThreadWait(Timeout);
|
|
155
|
+
else
|
|
156
|
+
return WAIT_OBJECT_0;
|
|
157
|
+
}
|
|
158
|
+
else
|
|
159
|
+
return WAIT_OBJECT_0;
|
|
160
|
+
}
|
|
161
|
+
//---------------------------------------------------------------------------
|
|
162
|
+
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*=============================================================================|
|
|
2
|
+
| PROJECT SNAP7 1.3.0 |
|
|
3
|
+
|==============================================================================|
|
|
4
|
+
| Copyright (C) 2013, 2015 Davide Nardella |
|
|
5
|
+
| All rights reserved. |
|
|
6
|
+
|==============================================================================|
|
|
7
|
+
| SNAP7 is free software: you can redistribute it and/or modify |
|
|
8
|
+
| it under the terms of the Lesser GNU General Public License as published by |
|
|
9
|
+
| the Free Software Foundation, either version 3 of the License, or |
|
|
10
|
+
| (at your option) any later version. |
|
|
11
|
+
| |
|
|
12
|
+
| It means that you can distribute your commercial software linked with |
|
|
13
|
+
| SNAP7 without the requirement to distribute the source code of your |
|
|
14
|
+
| application and without the requirement that your application be itself |
|
|
15
|
+
| distributed under LGPL. |
|
|
16
|
+
| |
|
|
17
|
+
| SNAP7 is distributed in the hope that it will be useful, |
|
|
18
|
+
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
19
|
+
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
20
|
+
| Lesser GNU General Public License for more details. |
|
|
21
|
+
| |
|
|
22
|
+
| You should have received a copy of the GNU General Public License and a |
|
|
23
|
+
| copy of Lesser GNU General Public License along with Snap7. |
|
|
24
|
+
| If not, see http://www.gnu.org/licenses/ |
|
|
25
|
+
|=============================================================================*/
|
|
26
|
+
#ifndef snap_threads_h
|
|
27
|
+
#define snap_threads_h
|
|
28
|
+
//---------------------------------------------------------------------------
|
|
29
|
+
#include "snap_platform.h"
|
|
30
|
+
|
|
31
|
+
#ifdef OS_WINDOWS
|
|
32
|
+
# include "win_threads.h"
|
|
33
|
+
#endif
|
|
34
|
+
#if defined(POSIX) && (!defined(OS_SOLARIS_NATIVE_THREADS))
|
|
35
|
+
# include "unix_threads.h"
|
|
36
|
+
#endif
|
|
37
|
+
#ifdef OS_SOLARIS_NATIVE_THREADS
|
|
38
|
+
# include "sol_threads.h"
|
|
39
|
+
#endif
|
|
40
|
+
#if defined(OS_OSX)
|
|
41
|
+
# include "unix_threads.h"
|
|
42
|
+
#endif
|
|
43
|
+
|
|
44
|
+
//---------------------------------------------------------------------------
|
|
45
|
+
#endif // snap_threads_h
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/*=============================================================================|
|
|
2
|
+
| PROJECT SNAP7 1.3.0 |
|
|
3
|
+
|==============================================================================|
|
|
4
|
+
| Copyright (C) 2013, 2015 Davide Nardella |
|
|
5
|
+
| All rights reserved. |
|
|
6
|
+
|==============================================================================|
|
|
7
|
+
| SNAP7 is free software: you can redistribute it and/or modify |
|
|
8
|
+
| it under the terms of the Lesser GNU General Public License as published by |
|
|
9
|
+
| the Free Software Foundation, either version 3 of the License, or |
|
|
10
|
+
| (at your option) any later version. |
|
|
11
|
+
| |
|
|
12
|
+
| It means that you can distribute your commercial software linked with |
|
|
13
|
+
| SNAP7 without the requirement to distribute the source code of your |
|
|
14
|
+
| application and without the requirement that your application be itself |
|
|
15
|
+
| distributed under LGPL. |
|
|
16
|
+
| |
|
|
17
|
+
| SNAP7 is distributed in the hope that it will be useful, |
|
|
18
|
+
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
19
|
+
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
20
|
+
| Lesser GNU General Public License for more details. |
|
|
21
|
+
| |
|
|
22
|
+
| You should have received a copy of the GNU General Public License and a |
|
|
23
|
+
| copy of Lesser GNU General Public License along with Snap7. |
|
|
24
|
+
| If not, see http://www.gnu.org/licenses/ |
|
|
25
|
+
|==============================================================================|
|
|
26
|
+
| |
|
|
27
|
+
| Solaris 11 Threads support |
|
|
28
|
+
| |
|
|
29
|
+
|=============================================================================*/
|
|
30
|
+
#ifndef sol_threads_h
|
|
31
|
+
#define sol_threads_h
|
|
32
|
+
//---------------------------------------------------------------------------
|
|
33
|
+
#include "snap_platform.h"
|
|
34
|
+
#include "snap_sysutils.h"
|
|
35
|
+
#include <thread.h>
|
|
36
|
+
#include <synch.h>
|
|
37
|
+
//---------------------------------------------------------------------------
|
|
38
|
+
|
|
39
|
+
class TSnapCriticalSection {
|
|
40
|
+
private:
|
|
41
|
+
mutex_t mx;
|
|
42
|
+
int result;
|
|
43
|
+
public:
|
|
44
|
+
|
|
45
|
+
TSnapCriticalSection() {
|
|
46
|
+
mutex_init(&mx, USYNC_THREAD, 0);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
~TSnapCriticalSection() {
|
|
50
|
+
mutex_destroy(&mx);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
void Enter() {
|
|
54
|
+
mutex_lock(&mx);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
void Leave() {
|
|
58
|
+
mutex_unlock(&mx);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
bool TryEnter() {
|
|
62
|
+
return mutex_trylock(&mx) == 0;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
typedef TSnapCriticalSection *PSnapCriticalSection;
|
|
66
|
+
|
|
67
|
+
//---------------------------------------------------------------------------
|
|
68
|
+
const longword WAIT_OBJECT_0 = 0x00000000L;
|
|
69
|
+
const longword WAIT_ABANDONED = 0x00000080L;
|
|
70
|
+
const longword WAIT_TIMEOUT = 0x00000102L;
|
|
71
|
+
const longword WAIT_FAILED = 0xFFFFFFFFL;
|
|
72
|
+
|
|
73
|
+
class TSnapEvent {
|
|
74
|
+
private:
|
|
75
|
+
cond_t CVariable;
|
|
76
|
+
mutex_t Mutex;
|
|
77
|
+
bool AutoReset;
|
|
78
|
+
bool State;
|
|
79
|
+
public:
|
|
80
|
+
|
|
81
|
+
TSnapEvent(bool ManualReset)
|
|
82
|
+
{
|
|
83
|
+
AutoReset = !ManualReset;
|
|
84
|
+
cond_init(&CVariable, USYNC_THREAD, 0) == 0;
|
|
85
|
+
mutex_init(&Mutex, USYNC_THREAD, 0);
|
|
86
|
+
State = false;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
~TSnapEvent()
|
|
90
|
+
{
|
|
91
|
+
cond_destroy(&CVariable);
|
|
92
|
+
mutex_destroy(&Mutex);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
void Set()
|
|
96
|
+
{
|
|
97
|
+
mutex_lock(&Mutex);
|
|
98
|
+
State = true;
|
|
99
|
+
if (AutoReset)
|
|
100
|
+
cond_signal(&CVariable);
|
|
101
|
+
else
|
|
102
|
+
cond_broadcast(&CVariable);
|
|
103
|
+
mutex_unlock(&Mutex);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
void Reset()
|
|
107
|
+
{
|
|
108
|
+
mutex_lock(&Mutex);
|
|
109
|
+
State = false;
|
|
110
|
+
mutex_unlock(&Mutex);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
longword WaitForever()
|
|
114
|
+
{
|
|
115
|
+
mutex_lock(&Mutex);
|
|
116
|
+
while (!State) // <-- to avoid spurious wakeups
|
|
117
|
+
cond_wait(&CVariable, &Mutex);
|
|
118
|
+
if (AutoReset)
|
|
119
|
+
State = false;
|
|
120
|
+
mutex_unlock(&Mutex);
|
|
121
|
+
return WAIT_OBJECT_0;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
longword WaitFor(int64_t Timeout)
|
|
125
|
+
{
|
|
126
|
+
longword Result = WAIT_OBJECT_0;
|
|
127
|
+
if (Timeout == 0)
|
|
128
|
+
Timeout = 1; // 0 is not allowed
|
|
129
|
+
|
|
130
|
+
if (Timeout > 0) {
|
|
131
|
+
mutex_lock(&Mutex);
|
|
132
|
+
if (!State) {
|
|
133
|
+
timespec ts;
|
|
134
|
+
timeval tv;
|
|
135
|
+
gettimeofday(&tv, NULL);
|
|
136
|
+
uint64_t nsecs = ((uint64_t) tv.tv_sec) * 1000000000 +
|
|
137
|
+
Timeout * 1000000 +
|
|
138
|
+
((uint64_t) tv.tv_usec) * 1000;
|
|
139
|
+
ts.tv_sec = nsecs / 1000000000;
|
|
140
|
+
ts.tv_nsec = (nsecs - ((uint64_t) ts.tv_sec) * 1000000000);
|
|
141
|
+
do
|
|
142
|
+
{
|
|
143
|
+
Result = cond_timedwait(&CVariable, &Mutex, &ts);
|
|
144
|
+
if (Result == ETIMEDOUT)
|
|
145
|
+
Result = WAIT_TIMEOUT;
|
|
146
|
+
}
|
|
147
|
+
while (Result == 0 && !State);
|
|
148
|
+
}
|
|
149
|
+
else
|
|
150
|
+
if (AutoReset) // take the ownership
|
|
151
|
+
State = false;
|
|
152
|
+
mutex_unlock(&Mutex);
|
|
153
|
+
return Result;
|
|
154
|
+
}
|
|
155
|
+
else // Timeout<0
|
|
156
|
+
return WaitForever();
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
typedef TSnapEvent *PSnapEvent;
|
|
160
|
+
//---------------------------------------------------------------------------
|
|
161
|
+
|
|
162
|
+
class TSnapThread {
|
|
163
|
+
private:
|
|
164
|
+
thread_t th;
|
|
165
|
+
bool FCreateSuspended;
|
|
166
|
+
void ThreadCreate();
|
|
167
|
+
|
|
168
|
+
void ThreadJoin()
|
|
169
|
+
{
|
|
170
|
+
thr_join(th, 0, 0);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
void ThreadKill()
|
|
174
|
+
{
|
|
175
|
+
thr_kill(th, 0);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
longword ThreadWait(uint64_t Timeout)
|
|
179
|
+
{
|
|
180
|
+
longword Elapsed = SysGetTick();
|
|
181
|
+
while (!Closed && !(DeltaTime(Elapsed) > Timeout))
|
|
182
|
+
SysSleep(100);
|
|
183
|
+
if (Closed)
|
|
184
|
+
return WAIT_OBJECT_0;
|
|
185
|
+
else
|
|
186
|
+
return WAIT_TIMEOUT;
|
|
187
|
+
};
|
|
188
|
+
protected:
|
|
189
|
+
bool Started;
|
|
190
|
+
public:
|
|
191
|
+
bool Terminated;
|
|
192
|
+
bool Closed;
|
|
193
|
+
bool FreeOnTerminate;
|
|
194
|
+
TSnapThread();
|
|
195
|
+
virtual ~TSnapThread();
|
|
196
|
+
|
|
197
|
+
virtual void Execute() {
|
|
198
|
+
};
|
|
199
|
+
void Start();
|
|
200
|
+
void Terminate();
|
|
201
|
+
void Kill();
|
|
202
|
+
void Join();
|
|
203
|
+
longword WaitFor(uint64_t Timeout);
|
|
204
|
+
};
|
|
205
|
+
typedef TSnapThread *PSnapThread;
|
|
206
|
+
|
|
207
|
+
//---------------------------------------------------------------------------
|
|
208
|
+
#endif // sol_threads_h
|