trafficSDKHelper.h
2.54 KB
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
/*
*对TrafficSDK.h的再封装,实现简单的单例模式
*/
#ifndef _TRAFFIC_SDK_HELPER_H
#define _TRAFFIC_SDK_HELPER_H
#include "include/include/TrafficSDK.h"
#include "include/app/trafficQueue.h"
static HTrafficSDK hTrafficSDK = NULL;
static HSCConfig hConfig = NULL;
static CirQueue trafficQueue;
static int callbackCount = 0; //用于判断是否需要注册回调
static pthread_mutex_t trafficMut = PTHREAD_MUTEX_INITIALIZER;
//简单的单例模式(加锁没有考虑)
HTrafficSDK getTrafficSDK()
{
pthread_mutex_lock(&trafficMut);
if(hTrafficSDK == NULL)
{
hTrafficSDK = TrafficSDK_Init("127.0.0.1", 41065, "IVEClientLog.txt", 7, 1024);
if(SC_ErrSuccess != TrafficSDK_Start(hTrafficSDK))
{
TrafficSDK_UnInit(hTrafficSDK);
hTrafficSDK = NULL;
pthread_mutex_unlock(&trafficMut);
return NULL;
}
}
pthread_mutex_unlock(&trafficMut);
return hTrafficSDK;
}
HSCConfig getHSCConfig()
{
if(hConfig)
{
TrafficSDK_ReleaseHSCConfig(hTrafficSDK, hConfig);
hConfig = NULL;
}
if(hConfig == NULL)
{
if(getTrafficSDK() == NULL)
{
return NULL;
}
void *pParamXml = NULL;
int nParamXmlLen = 0;
ScErr err = TrafficSDK_GetHSCConfig(hTrafficSDK, &hConfig, pParamXml, nParamXmlLen);
if(err != SC_ErrSuccess)
{
// printf("----------FAILED: TrafficSDK_GetHSCConfig--------\n");
return NULL;
}
}
return hConfig;
}
int getCallbackCount()
{
return callbackCount;
}
void addCallbackCount()
{
++callbackCount;
}
void initCallbackCount()
{
callbackCount = 0;
}
//封装后的注册回调函数
void tcRegisterCallback()
{
printf("---------------------registerCallback-----------------------\n");
HTrafficSDK pTrafficSDK = getTrafficSDK();
if(pTrafficSDK == NULL)
{
printf("---------------------getTrafficSDK error-----------------------\n");
return;
}
//initialTrafficQueue();
//TrafficSDK_SetResultCallBack(pTrafficSDK, tcTrafficResult, 0);
}
ScErr releaseTrafficResources()
{
ScErr err = SC_ErrSuccess;
/*
pthread_mutex_lock(&trafficMut);
if(hTrafficSDK != NULL)
{
if(hConfig != NULL)
{
err = TrafficSDK_ReleaseHSCConfig(hTrafficSDK, hConfig);
if(err == SC_ErrSuccess)
{
hConfig = NULL;
}
else
{
pthread_mutex_unlock(&trafficMut);
return err;
}
}
err = TrafficSDK_UnInit(hTrafficSDK);
if(err == SC_ErrSuccess)
{
hTrafficSDK = NULL;
}
else
{
pthread_mutex_unlock(&trafficMut);
return err;
}
initCallbackCount();
}
pthread_mutex_unlock(&trafficMut);
*/
return err;
}
void initialTrafficQueue()
{
Initial(&trafficQueue);
}
#endif