|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.iotdb.db.pipe.connector.protocol.opcda; |
| 21 | + |
| 22 | +import com.sun.jna.Pointer; |
| 23 | +import com.sun.jna.Structure; |
| 24 | +import com.sun.jna.WString; |
| 25 | +import com.sun.jna.platform.win32.COM.Unknown; |
| 26 | +import com.sun.jna.platform.win32.Guid; |
| 27 | +import com.sun.jna.platform.win32.Variant; |
| 28 | +import com.sun.jna.ptr.IntByReference; |
| 29 | +import com.sun.jna.ptr.PointerByReference; |
| 30 | + |
| 31 | +import java.util.Arrays; |
| 32 | +import java.util.List; |
| 33 | + |
| 34 | +/** We define the OPC DA Classes and interfaces here like C's .h file. */ |
| 35 | +public class OpcDaHeader { |
| 36 | + // IOPCServer |
| 37 | + static final Guid.IID IID_IOPCServer = new Guid.IID("39C13A4D-011E-11D0-9675-0020AFD8ADB3"); |
| 38 | + |
| 39 | + // IOPCItemMgt |
| 40 | + static final Guid.IID IID_IOPCItemMgt = new Guid.IID("39C13A54-011E-11D0-9675-0020AFD8ADB3"); |
| 41 | + |
| 42 | + // IOPCSyncIO |
| 43 | + static final Guid.IID IID_IOPCSyncIO = new Guid.IID("39C13A52-011E-11D0-9675-0020AFD8ADB3"); |
| 44 | + |
| 45 | + // IUnknown |
| 46 | + static final Guid.IID IID_IUNKNOWN = new Guid.IID("00000000-0000-0000-C000-000000000046"); |
| 47 | + |
| 48 | + public static class IOPCServer extends Unknown { |
| 49 | + public IOPCServer(final Pointer p) { |
| 50 | + super(p); |
| 51 | + } |
| 52 | + |
| 53 | + // /* [string][in] */ LPCWSTR szName, |
| 54 | + // /* [in] */ BOOL bActive, |
| 55 | + // /* [in] */ DWORD dwRequestedUpdateRate, |
| 56 | + // /* [in] */ OPCHANDLE hClientGroup, |
| 57 | + // /* [in][unique] */ LONG *pTimeBias, |
| 58 | + // /* [in][unique] */ FLOAT *pPercentDeadband, |
| 59 | + // /* [in] */ DWORD dwLCID, |
| 60 | + // /* [out] */ OPCHANDLE *phServerGroup, |
| 61 | + // /* [out] */ DWORD *pRevisedUpdateRate, |
| 62 | + // /* [in] */ REFIID riid, |
| 63 | + // /* [iid_is][out] */ LPUNKNOWN *ppUnk) = 0; |
| 64 | + public int addGroup( |
| 65 | + final String szName, // Group name ("" means auto) |
| 66 | + final boolean bActive, // Whether to activate the group |
| 67 | + final int dwRequestedUpdateRate, // The update rate of request (ms) |
| 68 | + final int hClientGroup, // The handle of client group |
| 69 | + final Pointer pTimeBias, // Time zone bias |
| 70 | + final Pointer pPercentDeadband, // Dead band |
| 71 | + final int dwLCID, // Region ID |
| 72 | + final PointerByReference phServerGroup, // Server group handler |
| 73 | + final IntByReference pRevisedUpdateRate, // Real update rate |
| 74 | + final Guid.GUID.ByReference riid, // Interface IID |
| 75 | + final PointerByReference ppUnk // The OPC Group pointer returned |
| 76 | + ) { |
| 77 | + // Convert Java string into COM "bstr" |
| 78 | + final WString wName = new WString(szName); |
| 79 | + |
| 80 | + return this._invokeNativeInt( |
| 81 | + 3, |
| 82 | + new Object[] { |
| 83 | + this.getPointer(), |
| 84 | + wName, |
| 85 | + bActive ? 1 : 0, |
| 86 | + dwRequestedUpdateRate, |
| 87 | + hClientGroup, |
| 88 | + pTimeBias, |
| 89 | + pPercentDeadband, |
| 90 | + dwLCID, |
| 91 | + phServerGroup, |
| 92 | + pRevisedUpdateRate, |
| 93 | + riid != null ? riid.getPointer() : null, |
| 94 | + ppUnk |
| 95 | + }); |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + // IOPCItemMgt( |
| 100 | + // /* [in] */ DWORD dwCount, |
| 101 | + // /* [in] */ OPCITEMDEF *pItemArray, |
| 102 | + // /* [out] */ OPCITEMRESULT **ppAddResults, |
| 103 | + // /* [out] */ HRESULT **ppErrors) = 0; |
| 104 | + public static class IOPCItemMgt extends Unknown { |
| 105 | + public IOPCItemMgt(final Pointer p) { |
| 106 | + super(p); |
| 107 | + } |
| 108 | + |
| 109 | + public int addItems( |
| 110 | + final int dwCount, // Data count |
| 111 | + final OPCITEMDEF[] pItemArray, // Items array to create |
| 112 | + final PointerByReference pResults, // Results' handles |
| 113 | + final PointerByReference pErrors // Error's pointers |
| 114 | + ) { |
| 115 | + return this._invokeNativeInt( |
| 116 | + 3, new Object[] {this.getPointer(), dwCount, pItemArray, pResults, pErrors}); |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + public static class IOPCSyncIO extends Unknown { |
| 121 | + public IOPCSyncIO(final Pointer p) { |
| 122 | + super(p); |
| 123 | + } |
| 124 | + |
| 125 | + // /* [in] */ DWORD dwCount, |
| 126 | + // /* [size_is][in] */ OPCHANDLE *phServer, |
| 127 | + // /* [size_is][in] */ VARIANT *pItemValues, |
| 128 | + // /* [size_is][size_is][out] */ HRESULT **ppErrors) = 0; |
| 129 | + public int write( |
| 130 | + final int dwCount, // Data count |
| 131 | + final Pointer phServer, // Server handles of items |
| 132 | + final Pointer pItemValues, // Values of items |
| 133 | + final PointerByReference pErrors // Error codes |
| 134 | + ) { |
| 135 | + return this._invokeNativeInt( |
| 136 | + 4, |
| 137 | + new Object[] { // Write is the 4th method in vtable |
| 138 | + this.getPointer(), dwCount, phServer, pItemValues, pErrors |
| 139 | + }); |
| 140 | + } |
| 141 | + } |
| 142 | + |
| 143 | + // /* [string] */ LPWSTR szAccessPath; |
| 144 | + // /* [string] */ LPWSTR szItemID; |
| 145 | + // BOOL bActive; |
| 146 | + // OPCHANDLE hClient; |
| 147 | + // DWORD dwBlobSize; |
| 148 | + // /* [size_is] */ BYTE *pBlob; |
| 149 | + // VARTYPE vtRequestedDataType; |
| 150 | + // WORD wReserved; |
| 151 | + public static class OPCITEMDEF extends Structure { |
| 152 | + public WString szAccessPath = new WString(""); // Access path (Usually empty) |
| 153 | + public WString szItemID; // Item ID(Like "Channel1.Device1.Tag1") |
| 154 | + public int bActive; // Whether to activate this item(TRUE=1, FALSE=0) |
| 155 | + public int hClient; // Client handle, Used in async callback and remove item |
| 156 | + public int dwBlobSize; // BLOB size |
| 157 | + public Pointer pBlob; // BLOB's pointer |
| 158 | + public short vtRequestedDataType = Variant.VT_UNKNOWN; // Requested datatype |
| 159 | + public short wReserved; // Reserved |
| 160 | + |
| 161 | + // As C structure |
| 162 | + @Override |
| 163 | + protected List<String> getFieldOrder() { |
| 164 | + return Arrays.asList( |
| 165 | + "szAccessPath", |
| 166 | + "szItemID", |
| 167 | + "bActive", |
| 168 | + "hClient", |
| 169 | + "dwBlobSize", |
| 170 | + "pBlob", |
| 171 | + "vtRequestedDataType", |
| 172 | + "wReserved"); |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + // OPCHANDLE hServer; |
| 177 | + // VARTYPE vtCanonicalDataType; |
| 178 | + // WORD wReserved; |
| 179 | + // DWORD dwAccessRights; |
| 180 | + // DWORD dwBlobSize; |
| 181 | + // /* [size_is] */ BYTE *pBlob; |
| 182 | + public static class OPCITEMRESULT extends Structure { |
| 183 | + public int hServer; // Server handle, Used to write |
| 184 | + public short vtCanonicalDataType; // Data type (like Variant.VT_R8) |
| 185 | + public short wReserved; // Reserved word |
| 186 | + public int dwAccessRights; // Access right |
| 187 | + public int dwBlobSize; // BLOB size |
| 188 | + public Pointer pBlob; // BLOB pointer |
| 189 | + |
| 190 | + public OPCITEMRESULT(final Pointer pointer) { |
| 191 | + super(pointer); |
| 192 | + } |
| 193 | + |
| 194 | + @Override |
| 195 | + protected List<String> getFieldOrder() { |
| 196 | + return Arrays.asList( |
| 197 | + "hServer", "vtCanonicalDataType", "wReserved", "dwAccessRights", "dwBlobSize", "pBlob"); |
| 198 | + } |
| 199 | + } |
| 200 | +} |
0 commit comments