1
zhanghua
2024-09-26 c775c6953d9759e70f08acbfa8f6d7490aaae3d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
package com.netsdk.module;
 
import com.netsdk.lib.NetSDKLib;
import com.netsdk.lib.ToolKits;
import com.netsdk.lib.enumeration.*;
import com.netsdk.lib.structure.NET_CFG_BGY_CUSTOMERCFG;
import com.netsdk.lib.structure.NET_CFG_FORBIDDEN_ADVERT_PLAY;
import com.netsdk.lib.structure.NET_CFG_HEALTH_CODE_INFO;
import com.netsdk.module.entity.ForbiddenAdvertPlayInfoConfig;
import com.sun.jna.Memory;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import java.util.List;
 
/**
 * @author 47081
 * @version 1.0
 * @description 设备配置的获取与设置二次封装
 * @date 2020/9/14
 */
public class ConfigModule extends BaseModule {
  private final NetSDKLib configApi;
 
  public ConfigModule(NetSDKLib netSdkApi) {
    super(netSdkApi);
    this.configApi = NetSDKLib.CONFIG_INSTANCE;
  }
 
  public ConfigModule(NetSDKLib netSDKApi, NetSDKLib configApi) {
    super(netSDKApi);
    this.configApi = configApi;
  }
 
  public ConfigModule() {
    this(NetSDKLib.NETSDK_INSTANCE, NetSDKLib.CONFIG_INSTANCE);
  }
 
  public NetSDKLib getConfigApi() {
    return configApi;
  }
 
  /**
   * 全屏广告模式配置
   *
   * @return
   */
  public boolean bgyCustomerCfg(long loginHandler, NET_CFG_BGY_CUSTOMERCFG config) {
    Pointer pointer = new Memory(config.size());
    ToolKits.SetStructDataToPointer(config, pointer, 0);
    return getNetsdkApi()
        .CLIENT_SetConfig(
            new NetSDKLib.LLong(loginHandler),
            NET_EM_CFG_OPERATE_TYPE.NET_EM_CFG_BGY_CUSTOMERCFG,
            -1,
            pointer,
            config.size(),
            5000,
            new IntByReference(0),
            null);
  }
 
  /**
   * 获取全屏广告配置
   *
   * @param loginHandler
   * @return
   */
  public NET_CFG_BGY_CUSTOMERCFG getBgyCustomerCfg(long loginHandler) {
    NET_CFG_BGY_CUSTOMERCFG config = new NET_CFG_BGY_CUSTOMERCFG();
    Pointer pointer = new Memory(config.size());
    ToolKits.SetStructDataToPointer(config, pointer, 0);
    boolean result =
        getNetsdkApi()
            .CLIENT_GetConfig(
                new NetSDKLib.LLong(loginHandler),
                NET_EM_CFG_OPERATE_TYPE.NET_EM_CFG_BGY_CUSTOMERCFG,
                -1,
                pointer,
                config.size(),
                5000,
                null);
    if (!result) {
      System.out.println("获取全屏广告配置失败." + ENUMERROR.getErrorMessage());
      return null;
    }
    ToolKits.GetPointerData(pointer, config);
    return config;
  }
 
  /**
   * 配置广告禁播时间段
   *
   * @return
   */
  public boolean forbiddenAdvertPlayConfig(
      long loginHandler, List<ForbiddenAdvertPlayInfoConfig> configs) {
    NET_CFG_FORBIDDEN_ADVERT_PLAY config = new NET_CFG_FORBIDDEN_ADVERT_PLAY();
    if (configs.size() > config.stuAdvertInfo.length) {
      System.out.println("超出最大时间段设置");
      return false;
    }
    config.nAdvertNum = configs.size();
    ForbiddenAdvertPlayInfoConfig fb;
    for (int i = 0; i < configs.size(); i++) {
      fb = configs.get(i);
      config.stuAdvertInfo[i].bEnable = fb.isbEnable();
      config.stuAdvertInfo[i].stuBeginTime = fb.stuBeginTime;
      config.stuAdvertInfo[i].stuEndTime = fb.stuEndTime;
    }
    Pointer pointer = new Memory(config.size());
    ToolKits.SetStructDataToPointer(config, pointer, 0);
    return getNetsdkApi()
        .CLIENT_SetConfig(
            new NetSDKLib.LLong(loginHandler),
            NET_EM_CFG_OPERATE_TYPE.NET_EM_CFG_FORBIDDEN_ADVERT_PLAY,
            -1,
            pointer,
            config.size(),
            5000,
            new IntByReference(0),
            null);
  }
 
  /**
   * 配置健康码
   *
   * @return
   */
  public boolean healthCodeConfig(long loginHandler, NET_CFG_HEALTH_CODE_INFO config) {
    Pointer pointer = new Memory(config.size());
    ToolKits.SetStructDataToPointer(config, pointer, 0);
    return getNetsdkApi()
        .CLIENT_SetConfig(
            new NetSDKLib.LLong(loginHandler),
            NET_EM_CFG_OPERATE_TYPE.NET_EM_CFG_HEALTH_CODE,
            -1,
            pointer,
            config.size(),
            5000,
            new IntByReference(0),
            null);
  }
 
  /**
   * 下发配置
   *
   * @param loginHandler 登录句柄
   * @param emType 配置类型 枚举值参考{@link NET_EM_CFG_OPERATE_TYPE}
   * @param config 配置信息
   * @param channel 通道号
   * @param waitTime 超时时间
   * @return
   */
  public boolean setConfig(
      long loginHandler, int emType, NetSDKLib.SdkStructure config, int channel, int waitTime) {
    Pointer pointer = new Memory(config.size());
    ToolKits.SetStructDataToPointer(config, pointer, 0);
    boolean result =
        getNetsdkApi()
            .CLIENT_SetConfig(
                new NetSDKLib.LLong(loginHandler),
                emType,
                channel,
                pointer,
                config.size(),
                waitTime,
                new IntByReference(0),
                null);
    if (!result) {
      System.out.println("set config emType failed.error is " + ENUMERROR.getErrorMessage());
    }
    return result;
  }
 
  /**
   * @param loginHandler 登录句柄
   * @param emType 配置类型 枚举值参考{@link NET_EM_CFG_OPERATE_TYPE}
   * @param config 配置信息
   * @param channel 通道号
   * @return 下发配置是否成功
   */
  public boolean setConfig(
      long loginHandler, int emType, NetSDKLib.SdkStructure config, int channel) {
    return setConfig(loginHandler, emType, config, channel, 5000);
  }
 
  /**
   * 获取配置
   *
   * @param loginHandler 登录句柄
   * @param emType 配置类型 枚举值参考{@link NET_EM_CFG_OPERATE_TYPE}
   * @param config 配置信息
   * @param channel 通道号
   */
  public NetSDKLib.SdkStructure getConfig(
      long loginHandler, int emType, NetSDKLib.SdkStructure config, int channel, int waitTime) {
    config.write(); // 数据写入 native 内存
    if (!getNetsdkApi().CLIENT_GetConfig(
            new NetSDKLib.LLong(loginHandler),  // 登录句柄
            emType,                             // 配置枚举类型
            channel,                            // 通道号
            config.getPointer(),                // config 的指针
            config.size(),                      // Pointer 大小
            waitTime,
            null
    )) {
      System.out.println("get config failed emType:" + emType + "," + ENUMERROR.getErrorMessage());
      return null;
    }
    config.read(); // 从 native 内存读回数据
    return config;
  }
 
  /**
   * 获取配置
   *
   * @param loginHandler 登录句柄
   * @param emType 配置类型,枚举值参考{@link NET_EM_CFG_OPERATE_TYPE}
   * @param config 配置信息
   * @param channel 通道号
   * @return
   */
  public NetSDKLib.SdkStructure getConfig(
      long loginHandler, int emType, NetSDKLib.SdkStructure config, int channel) {
    return getConfig(loginHandler, emType, config, channel, 5000);
  }
 
  public NetSDKLib.SdkStructure[] getConfigs(
      long loginHandler, int emType, NetSDKLib.SdkStructure[] configs) {
    Pointer pointer = new Memory(configs[0].size() * configs.length);
    ToolKits.SetStructArrToPointerData(configs, pointer);
    if (!getNetsdkApi()
        .CLIENT_GetConfig(
            new NetSDKLib.LLong(loginHandler),
            emType,
            -1,
            pointer,
            configs[0].size() * configs.length,
            5000,
            null)) {
      System.out.println("get config failed emType:" + emType + "," + ENUMERROR.getErrorMessage());
      return null;
    }
    ToolKits.GetPointerDataToStructArr(pointer, configs);
    return configs;
  }
 
  /**
   * 查询系统能力信息,对应接口 {@link NetSDKLib#CLIENT_QueryNewSystemInfo(NetSDKLib.LLong, String, int, byte[],
   * int, IntByReference, int)}
   *
   * @param loginHandler
   * @return
   */
  public NetSDKLib.SdkStructure queryConfig(
      long loginHandler,
      EM_NEW_QUERY_SYSTEM_INFO query,
      NetSDKLib.SdkStructure structure,
      int channelId,
      int waitTime) {
    byte[] data = new byte[structure.size()];
    IntByReference error = new IntByReference(0);
    boolean result =
        getNetsdkApi()
            .CLIENT_QueryNewSystemInfo(
                new NetSDKLib.LLong(loginHandler),
                query.getValue(),
                channelId,
                data,
                data.length,
                error,
                waitTime);
    if (!result) {
      System.out.println("query system info failed.error is" + ENUMERROR.getErrorMessage());
      return null;
    }
    // 解析能力信息
    structure.write();
    result =
        configApi.CLIENT_ParseData(
            query.getValue(), data, structure.getPointer(), structure.size(), null);
    if (!result) {
      System.out.println("parse system info failed.error is " + ENUMERROR.getErrorMessage());
      return null;
    }
    structure.read();
    return structure;
  }
 
  /**
   * 获取设备配置
   *
   * @param loginHandler 登录句柄
   * @param get 配置命令
   * @param structure 配置信息
   * @param channelId 通道号
   * @param waitTime 超时时间
   * @return
   */
  public NetSDKLib.SdkStructure getNewConfig(
      long loginHandler,
      EM_NEW_CONFIG get,
      NetSDKLib.SdkStructure structure,
      int channelId,
      int waitTime) {
    byte[] data = new byte[structure.size() * 8];
    IntByReference error = new IntByReference(0);
    boolean result =
        getNetsdkApi()
            .CLIENT_GetNewDevConfig(
                new NetSDKLib.LLong(loginHandler),
                get.getValue(),
                channelId,
                data,
                data.length,
                error,
                waitTime,null);
    if (!result) {
      System.out.println("query system info failed.error is" + ENUMERROR.getErrorMessage());
      return null;
    }
    // 解析能力信息
    result =
        configApi.CLIENT_ParseData(
            get.getValue(), data, structure.getPointer(), structure.size(), null);
    if (!result) {
      System.out.println("parse system info failed.error is " + ENUMERROR.getErrorMessage());
      return null;
    }
    structure.read();
    return structure;
  }
 
  public NetSDKLib.SdkStructure getDevCaps(
      long loginHandler,
      GetDevCaps_Type cap,
      NetSDKLib.SdkStructure inParam,
      NetSDKLib.SdkStructure outParam,
      int waitTime) {
    inParam.write();
    outParam.write();
    if (getNetsdkApi()
        .CLIENT_GetDevCaps(
            new NetSDKLib.LLong(loginHandler),
            cap.getType(),
            inParam.getPointer(),
            outParam.getPointer(),
            waitTime)) {
      outParam.read();
      return outParam;
    } else {
      System.out.println("GetDevCaps failed." + ENUMERROR.getErrorMessage());
      return null;
    }
  }
  /**
   * 下发设备配置
   *
   * @param loginHandler 登录句柄
   * @param set 配置命令
   * @param structure 下发的配置
   * @param channelId 通道号
   * @param waitTime 超时时间
   * @return
   */
  public boolean setNewConfig(
      long loginHandler,
      EM_NEW_CONFIG set,
      NetSDKLib.SdkStructure structure,
      int channelId,
      int waitTime) {
    byte[] data = new byte[structure.size() * 8];
    structure.write();
    boolean result =
        configApi.CLIENT_PacketData(
            set.getValue(), structure.getPointer(), structure.size(), data, data.length);
    if (!result) {
      System.out.println("packet data failed.error is " + ENUMERROR.getErrorMessage());
      return false;
    }
    IntByReference error = new IntByReference(0);
    IntByReference restart = new IntByReference(0);
    result =
        getNetsdkApi()
            .CLIENT_SetNewDevConfig(
                new NetSDKLib.LLong(loginHandler),
                set.getValue(),
                channelId,
                data,
                data.length,
                error,
                restart,
                waitTime);
    if (!result) {
      System.out.println("set NewDevConfig failed. error is " + ENUMERROR.getErrorMessage());
      return false;
    }
    return true;
  }
}