qi-qin пре 1 година
комит
1c828f778c
74 измењених фајлова са 10474 додато и 0 уклоњено
  1. 152
    0
      .cproject
  2. 28
    0
      .project
  3. 25
    0
      .settings/language.settings.xml
  4. 31
    0
      Debug/common/subdir.mk
  5. 83
    0
      Debug/makefile
  6. 31
    0
      Debug/service/impl/subdir.mk
  7. 39
    0
      Debug/sources.mk
  8. 31
    0
      Debug/test/subdir.mk
  9. 34
    0
      Debug/util/easylogger/plugins/file/subdir.mk
  10. 31
    0
      Debug/util/easylogger/port/subdir.mk
  11. 40
    0
      Debug/util/easylogger/src/subdir.mk
  12. 9
    0
      Release/common/GUID.d
  13. BIN
      Release/common/GUID.o
  14. 31
    0
      Release/common/subdir.mk
  15. BIN
      Release/libcan_BMSer.so
  16. 82
    0
      Release/makefile
  17. 8
    0
      Release/objects.mk
  18. 82
    0
      Release/service/impl/ProtocolImpl.d
  19. BIN
      Release/service/impl/ProtocolImpl.o
  20. 31
    0
      Release/service/impl/subdir.mk
  21. 38
    0
      Release/sources.mk
  22. 14
    0
      Release/util/easylogger/plugins/file/elog_file.d
  23. BIN
      Release/util/easylogger/plugins/file/elog_file.o
  24. 14
    0
      Release/util/easylogger/plugins/file/elog_file_port.d
  25. BIN
      Release/util/easylogger/plugins/file/elog_file_port.o
  26. 34
    0
      Release/util/easylogger/plugins/file/subdir.mk
  27. 13
    0
      Release/util/easylogger/port/elog_port.d
  28. BIN
      Release/util/easylogger/port/elog_port.o
  29. 31
    0
      Release/util/easylogger/port/subdir.mk
  30. 7
    0
      Release/util/easylogger/src/elog.d
  31. BIN
      Release/util/easylogger/src/elog.o
  32. 7
    0
      Release/util/easylogger/src/elog_async.d
  33. BIN
      Release/util/easylogger/src/elog_async.o
  34. 7
    0
      Release/util/easylogger/src/elog_buf.d
  35. BIN
      Release/util/easylogger/src/elog_buf.o
  36. 7
    0
      Release/util/easylogger/src/elog_utils.d
  37. BIN
      Release/util/easylogger/src/elog_utils.o
  38. 40
    0
      Release/util/easylogger/src/subdir.mk
  39. 24
    0
      Release/util/iLOG/subdir.mk
  40. 27
    0
      common/GUID.cpp
  41. 26
    0
      common/IFace.h
  42. 24
    0
      common/IUnknown.h
  43. 412
    0
      common/Type.h
  44. 33
    0
      externservice/CoCreateI.h
  45. 123
    0
      externservice/HardwareI.h
  46. 51
    0
      externservice/ParaAnalysisI.h
  47. 73
    0
      externservice/ProtocolI.h
  48. 82
    0
      externservice/Sqlite3I.h
  49. 34
    0
      externservice/SubContractI.h
  50. 37
    0
      service/CallBackHandleI.h
  51. 73
    0
      service/ProtocolI.h
  52. 58
    0
      service/impl/JobExecuterImpl.h
  53. 114
    0
      service/impl/MThreadedJobQImpl.h
  54. 857
    0
      service/impl/ProtocolImpl.cpp
  55. 353
    0
      service/impl/ProtocolImpl.h
  56. 247
    0
      servicemodel/Base.h
  57. 336
    0
      servicemodel/Channel.h
  58. 355
    0
      servicemodel/Device.h
  59. 604
    0
      servicemodel/Item.h
  60. 153
    0
      servicemodel/Packet.h
  61. 34
    0
      test/main.cpp
  62. 273
    0
      util/easylogger/inc/elog.h
  63. 67
    0
      util/easylogger/inc/elog_cfg.h
  64. 165
    0
      util/easylogger/plugins/file/elog_file.c
  65. 72
    0
      util/easylogger/plugins/file/elog_file.h
  66. 41
    0
      util/easylogger/plugins/file/elog_file_cfg.h
  67. 160
    0
      util/easylogger/plugins/file/elog_file_port.c
  68. 146
    0
      util/easylogger/port/elog_port.c
  69. 872
    0
      util/easylogger/src/elog.c
  70. 352
    0
      util/easylogger/src/elog_async.c
  71. 104
    0
      util/easylogger/src/elog_buf.c
  72. 103
    0
      util/easylogger/src/elog_utils.c
  73. 2356
    0
      util/iLOG/LOG.c
  74. 653
    0
      util/iLOG/LOG.h

+ 152
- 0
.cproject Прегледај датотеку

@@ -0,0 +1,152 @@
1
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
3
+	<storageModule moduleId="org.eclipse.cdt.core.settings">
4
+		<cconfiguration id="cdt.managedbuild.config.gnu.cross.exe.debug.1584908887">
5
+			<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.cross.exe.debug.1584908887" moduleId="org.eclipse.cdt.core.settings" name="Debug">
6
+				<externalSettings>
7
+					<externalSetting>
8
+						<entry flags="VALUE_WORKSPACE_PATH" kind="includePath" name="/ModBusRTU"/>
9
+						<entry flags="VALUE_WORKSPACE_PATH" kind="libraryPath" name="/ModBusRTU/Debug"/>
10
+						<entry flags="RESOLVED" kind="libraryFile" name="ModBusRTU" srcPrefixMapping="" srcRootPath=""/>
11
+					</externalSetting>
12
+				</externalSettings>
13
+				<extensions>
14
+					<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
15
+					<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
16
+					<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
17
+					<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
18
+					<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
19
+					<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
20
+				</extensions>
21
+			</storageModule>
22
+			<storageModule moduleId="cdtBuildSystem" version="4.0.0">
23
+				<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.cross.exe.debug.1584908887" name="Debug" parent="cdt.managedbuild.config.gnu.cross.exe.debug">
24
+					<folderInfo id="cdt.managedbuild.config.gnu.cross.exe.debug.1584908887." name="/" resourcePath="">
25
+						<toolChain id="cdt.managedbuild.toolchain.gnu.cross.base.2071457276" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.base">
26
+							<option id="cdt.managedbuild.option.gnu.cross.prefix.480423893" name="Prefix" superClass="cdt.managedbuild.option.gnu.cross.prefix" value="arm-linux-gnueabihf-" valueType="string"/>
27
+							<option id="cdt.managedbuild.option.gnu.cross.path.619067777" name="Path" superClass="cdt.managedbuild.option.gnu.cross.path" value="C:\Program Files (x86)\Linaro\gcc-linaro-arm-linux-gnueabihf-4.7-2013.04\bin" valueType="string"/>
28
+							<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.214665671" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
29
+							<builder buildPath="${workspace_loc:/ModBusRTU}/Debug" id="cdt.managedbuild.builder.gnu.cross.1489259146" keepEnvironmentInBuildfile="false" name="Gnu Make Builder" superClass="cdt.managedbuild.builder.gnu.cross"/>
30
+							<tool id="cdt.managedbuild.tool.gnu.cross.c.compiler.347683857" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler">
31
+								<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.option.optimization.level.2109235616" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
32
+								<option id="gnu.c.compiler.option.debugging.level.1155094864" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.max" valueType="enumerated"/>
33
+								<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.976005224" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
34
+							</tool>
35
+							<tool id="cdt.managedbuild.tool.gnu.cross.cpp.compiler.1913246873" name="Cross G++ Compiler" superClass="cdt.managedbuild.tool.gnu.cross.cpp.compiler">
36
+								<option id="gnu.cpp.compiler.option.optimization.level.563184349" name="Optimization Level" superClass="gnu.cpp.compiler.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
37
+								<option id="gnu.cpp.compiler.option.debugging.level.623273529" name="Debug Level" superClass="gnu.cpp.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.default" valueType="enumerated"/>
38
+								<option id="gnu.cpp.compiler.option.dialect.std.729547743" name="Language standard" superClass="gnu.cpp.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.cpp.compiler.dialect.c++11" valueType="enumerated"/>
39
+								<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1521173018" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
40
+							</tool>
41
+							<tool id="cdt.managedbuild.tool.gnu.cross.c.linker.113998562" name="Cross GCC Linker" superClass="cdt.managedbuild.tool.gnu.cross.c.linker">
42
+								<option defaultValue="true" id="gnu.c.link.option.shared.417021627" name="Shared (-shared)" superClass="gnu.c.link.option.shared" valueType="boolean"/>
43
+							</tool>
44
+							<tool id="cdt.managedbuild.tool.gnu.cross.cpp.linker.1446380673" name="Cross G++ Linker" superClass="cdt.managedbuild.tool.gnu.cross.cpp.linker">
45
+								<option defaultValue="true" id="gnu.cpp.link.option.shared.1121658289" name="Shared (-shared)" superClass="gnu.cpp.link.option.shared" value="false" valueType="boolean"/>
46
+								<option id="gnu.cpp.link.option.flags.504201333" name="Linker flags" superClass="gnu.cpp.link.option.flags" value="-fPIC" valueType="string"/>
47
+								<option id="gnu.cpp.link.option.libs.759565065" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" valueType="libs">
48
+									<listOptionValue builtIn="false" value="dl"/>
49
+								</option>
50
+								<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1437245927" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
51
+									<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
52
+									<additionalInput kind="additionalinput" paths="$(LIBS)"/>
53
+								</inputType>
54
+							</tool>
55
+							<tool id="cdt.managedbuild.tool.gnu.cross.archiver.1865069350" name="Cross GCC Archiver" superClass="cdt.managedbuild.tool.gnu.cross.archiver"/>
56
+							<tool id="cdt.managedbuild.tool.gnu.cross.assembler.804578898" name="Cross GCC Assembler" superClass="cdt.managedbuild.tool.gnu.cross.assembler">
57
+								<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1440928162" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
58
+							</tool>
59
+						</toolChain>
60
+					</folderInfo>
61
+					<sourceEntries>
62
+						<entry excluding="util/iLOG" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
63
+					</sourceEntries>
64
+				</configuration>
65
+			</storageModule>
66
+			<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
67
+		</cconfiguration>
68
+		<cconfiguration id="cdt.managedbuild.config.gnu.cross.exe.release.1421790062">
69
+			<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.cross.exe.release.1421790062" moduleId="org.eclipse.cdt.core.settings" name="Release">
70
+				<externalSettings>
71
+					<externalSetting>
72
+						<entry flags="VALUE_WORKSPACE_PATH" kind="includePath" name="/ModBusRTU"/>
73
+						<entry flags="VALUE_WORKSPACE_PATH" kind="includePath" name="/can_dexn"/>
74
+						<entry flags="VALUE_WORKSPACE_PATH" kind="libraryPath" name="/ModBusRTU/Release"/>
75
+						<entry flags="VALUE_WORKSPACE_PATH" kind="libraryPath" name="/can_dexn/Release"/>
76
+						<entry flags="RESOLVED" kind="libraryFile" name="libModBusRTU" srcPrefixMapping="" srcRootPath=""/>
77
+						<entry flags="RESOLVED" kind="libraryFile" name="libcan_dexn" srcPrefixMapping="" srcRootPath=""/>
78
+					</externalSetting>
79
+				</externalSettings>
80
+				<extensions>
81
+					<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
82
+					<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
83
+					<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
84
+					<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
85
+					<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
86
+					<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
87
+				</extensions>
88
+			</storageModule>
89
+			<storageModule moduleId="cdtBuildSystem" version="4.0.0">
90
+				<configuration artifactExtension="so" artifactName="lib${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.sharedLib" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.sharedLib,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.cross.exe.release.1421790062" name="Release" parent="cdt.managedbuild.config.gnu.cross.exe.release">
91
+					<folderInfo id="cdt.managedbuild.config.gnu.cross.exe.release.1421790062." name="/" resourcePath="">
92
+						<toolChain id="cdt.managedbuild.toolchain.gnu.cross.exe.release.1531614038" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.exe.release">
93
+							<option id="cdt.managedbuild.option.gnu.cross.prefix.187193156" name="Prefix" superClass="cdt.managedbuild.option.gnu.cross.prefix" value="arm-linux-gnueabihf-" valueType="string"/>
94
+							<option id="cdt.managedbuild.option.gnu.cross.path.63077068" name="Path" superClass="cdt.managedbuild.option.gnu.cross.path" value="C:\Program Files (x86)\Linaro\gcc-linaro-arm-linux-gnueabihf-4.7-2013.04\bin" valueType="string"/>
95
+							<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.1958385737" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
96
+							<builder buildPath="${workspace_loc:/ModBusRTU}/Release" id="cdt.managedbuild.builder.gnu.cross.186384360" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.builder.gnu.cross"/>
97
+							<tool id="cdt.managedbuild.tool.gnu.cross.c.compiler.1926426749" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler">
98
+								<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.option.optimization.level.1332335031" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
99
+								<option id="gnu.c.compiler.option.debugging.level.608551846" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.none" valueType="enumerated"/>
100
+								<option id="gnu.c.compiler.option.misc.pic.247383801" name="Position Independent Code (-fPIC)" superClass="gnu.c.compiler.option.misc.pic" useByScannerDiscovery="false" value="true" valueType="boolean"/>
101
+								<option id="gnu.c.compiler.option.include.paths.121242850" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
102
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/util/easylogger/plugins/file}&quot;"/>
103
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/util/easylogger/inc}&quot;"/>
104
+								</option>
105
+								<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1179617019" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
106
+							</tool>
107
+							<tool id="cdt.managedbuild.tool.gnu.cross.cpp.compiler.1557130217" name="Cross G++ Compiler" superClass="cdt.managedbuild.tool.gnu.cross.cpp.compiler">
108
+								<option id="gnu.cpp.compiler.option.optimization.level.2034279973" name="Optimization Level" superClass="gnu.cpp.compiler.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
109
+								<option id="gnu.cpp.compiler.option.debugging.level.849197417" name="Debug Level" superClass="gnu.cpp.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
110
+								<option id="gnu.cpp.compiler.option.other.other.1949555287" name="Other flags" superClass="gnu.cpp.compiler.option.other.other" useByScannerDiscovery="false" value="-c -fmessage-length=0 -fPIC" valueType="string"/>
111
+								<option id="gnu.cpp.compiler.option.dialect.std.2122234811" name="Language standard" superClass="gnu.cpp.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.cpp.compiler.dialect.c++11" valueType="enumerated"/>
112
+								<option id="gnu.cpp.compiler.option.include.paths.652733609" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
113
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/util/easylogger/inc}&quot;"/>
114
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/util/easylogger/plugins/file}&quot;"/>
115
+								</option>
116
+								<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1766412265" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
117
+							</tool>
118
+							<tool id="cdt.managedbuild.tool.gnu.cross.c.linker.402551931" name="Cross GCC Linker" superClass="cdt.managedbuild.tool.gnu.cross.c.linker">
119
+								<option defaultValue="true" id="gnu.c.link.option.shared.756925904" name="Shared (-shared)" superClass="gnu.c.link.option.shared" valueType="boolean"/>
120
+							</tool>
121
+							<tool id="cdt.managedbuild.tool.gnu.cross.cpp.linker.1789745970" name="Cross G++ Linker" superClass="cdt.managedbuild.tool.gnu.cross.cpp.linker">
122
+								<option defaultValue="true" id="gnu.cpp.link.option.shared.1627043286" name="Shared (-shared)" superClass="gnu.cpp.link.option.shared" valueType="boolean"/>
123
+								<option id="gnu.cpp.link.option.flags.1093968783" name="Linker flags" superClass="gnu.cpp.link.option.flags" value="-pthread" valueType="string"/>
124
+								<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1758523284" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
125
+									<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
126
+									<additionalInput kind="additionalinput" paths="$(LIBS)"/>
127
+								</inputType>
128
+								<outputType id="cdt.managedbuild.tool.gnu.cpp.linker.output.so.1464380722" outputPrefix="" superClass="cdt.managedbuild.tool.gnu.cpp.linker.output.so"/>
129
+							</tool>
130
+							<tool id="cdt.managedbuild.tool.gnu.cross.archiver.666708137" name="Cross GCC Archiver" superClass="cdt.managedbuild.tool.gnu.cross.archiver"/>
131
+							<tool id="cdt.managedbuild.tool.gnu.cross.assembler.1585589444" name="Cross GCC Assembler" superClass="cdt.managedbuild.tool.gnu.cross.assembler">
132
+								<inputType id="cdt.managedbuild.tool.gnu.assembler.input.499669344" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
133
+							</tool>
134
+						</toolChain>
135
+					</folderInfo>
136
+					<sourceEntries>
137
+						<entry excluding="util/iLOG|test" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
138
+					</sourceEntries>
139
+				</configuration>
140
+			</storageModule>
141
+			<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
142
+		</cconfiguration>
143
+	</storageModule>
144
+	<storageModule moduleId="cdtBuildSystem" version="4.0.0">
145
+		<project id="ModBusRTU.cdt.managedbuild.target.gnu.cross.exe.802181475" name="Executable" projectType="cdt.managedbuild.target.gnu.cross.exe"/>
146
+	</storageModule>
147
+	<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
148
+	<storageModule moduleId="refreshScope"/>
149
+	<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
150
+	<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
151
+	<storageModule moduleId="scannerConfiguration"/>
152
+</cproject>

+ 28
- 0
.project Прегледај датотеку

@@ -0,0 +1,28 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<projectDescription>
3
+	<name>can_dexn</name>
4
+	<comment></comment>
5
+	<projects>
6
+	</projects>
7
+	<buildSpec>
8
+		<buildCommand>
9
+			<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
10
+			<triggers>clean,full,incremental,</triggers>
11
+			<arguments>
12
+			</arguments>
13
+		</buildCommand>
14
+		<buildCommand>
15
+			<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
16
+			<triggers>full,incremental,</triggers>
17
+			<arguments>
18
+			</arguments>
19
+		</buildCommand>
20
+	</buildSpec>
21
+	<natures>
22
+		<nature>org.eclipse.cdt.core.cnature</nature>
23
+		<nature>org.eclipse.cdt.core.ccnature</nature>
24
+		<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
25
+		<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
26
+		<nature>org.eclipse.linuxtools.tmf.project.nature</nature>
27
+	</natures>
28
+</projectDescription>

+ 25
- 0
.settings/language.settings.xml Прегледај датотеку

@@ -0,0 +1,25 @@
1
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+<project>
3
+	<configuration id="cdt.managedbuild.config.gnu.cross.exe.debug.1584908887" name="Debug">
4
+		<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
5
+			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
6
+			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
7
+			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
8
+			<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-1196467537535742160" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
9
+				<language-scope id="org.eclipse.cdt.core.gcc"/>
10
+				<language-scope id="org.eclipse.cdt.core.g++"/>
11
+			</provider>
12
+		</extension>
13
+	</configuration>
14
+	<configuration id="cdt.managedbuild.config.gnu.cross.exe.release.1421790062" name="Release">
15
+		<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
16
+			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
17
+			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
18
+			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
19
+			<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-1196467537535742160" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
20
+				<language-scope id="org.eclipse.cdt.core.gcc"/>
21
+				<language-scope id="org.eclipse.cdt.core.g++"/>
22
+			</provider>
23
+		</extension>
24
+	</configuration>
25
+</project>

+ 31
- 0
Debug/common/subdir.mk Прегледај датотеку

@@ -0,0 +1,31 @@
1
+################################################################################
2
+# Automatically-generated file. Do not edit!
3
+################################################################################
4
+
5
+# Add inputs and outputs from these tool invocations to the build variables 
6
+CPP_SRCS += \
7
+../common/GUID.cpp 
8
+
9
+CPP_DEPS += \
10
+./common/GUID.d 
11
+
12
+OBJS += \
13
+./common/GUID.o 
14
+
15
+
16
+# Each subdirectory must supply rules for building sources it contributes
17
+common/%.o: ../common/%.cpp common/subdir.mk
18
+	@echo 'Building file: $<'
19
+	@echo 'Invoking: Cross G++ Compiler'
20
+	arm-linux-gnueabihf-g++ -std=c++0x -O0 -g -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
21
+	@echo 'Finished building: $<'
22
+	@echo ' '
23
+
24
+
25
+clean: clean-common
26
+
27
+clean-common:
28
+	-$(RM) ./common/GUID.d ./common/GUID.o
29
+
30
+.PHONY: clean-common
31
+

+ 83
- 0
Debug/makefile Прегледај датотеку

@@ -0,0 +1,83 @@
1
+################################################################################
2
+# Automatically-generated file. Do not edit!
3
+################################################################################
4
+
5
+-include ../makefile.init
6
+
7
+RM := rm -rf
8
+
9
+# All of the sources participating in the build are defined here
10
+-include sources.mk
11
+-include util/easylogger/src/subdir.mk
12
+-include util/easylogger/port/subdir.mk
13
+-include util/easylogger/plugins/file/subdir.mk
14
+-include test/subdir.mk
15
+-include service/impl/subdir.mk
16
+-include common/subdir.mk
17
+ifneq ($(MAKECMDGOALS),clean)
18
+ifneq ($(strip $(C++M_DEPS)),)
19
+-include $(C++M_DEPS)
20
+endif
21
+ifneq ($(strip $(C++_DEPS)),)
22
+-include $(C++_DEPS)
23
+endif
24
+ifneq ($(strip $(CCM_DEPS)),)
25
+-include $(CCM_DEPS)
26
+endif
27
+ifneq ($(strip $(CC_DEPS)),)
28
+-include $(CC_DEPS)
29
+endif
30
+ifneq ($(strip $(CPP_DEPS)),)
31
+-include $(CPP_DEPS)
32
+endif
33
+ifneq ($(strip $(CXXM_DEPS)),)
34
+-include $(CXXM_DEPS)
35
+endif
36
+ifneq ($(strip $(CXX_DEPS)),)
37
+-include $(CXX_DEPS)
38
+endif
39
+ifneq ($(strip $(C_DEPS)),)
40
+-include $(C_DEPS)
41
+endif
42
+ifneq ($(strip $(C_UPPER_DEPS)),)
43
+-include $(C_UPPER_DEPS)
44
+endif
45
+endif
46
+
47
+-include ../makefile.defs
48
+
49
+OPTIONAL_TOOL_DEPS := \
50
+$(wildcard ../makefile.defs) \
51
+$(wildcard ../makefile.init) \
52
+$(wildcard ../makefile.targets) \
53
+
54
+
55
+BUILD_ARTIFACT_NAME := can_dexn
56
+BUILD_ARTIFACT_EXTENSION :=
57
+BUILD_ARTIFACT_PREFIX :=
58
+BUILD_ARTIFACT := $(BUILD_ARTIFACT_PREFIX)$(BUILD_ARTIFACT_NAME)$(if $(BUILD_ARTIFACT_EXTENSION),.$(BUILD_ARTIFACT_EXTENSION),)
59
+
60
+# Add inputs and outputs from these tool invocations to the build variables 
61
+
62
+# All Target
63
+all: main-build
64
+
65
+# Main-build Target
66
+main-build: can_dexn
67
+
68
+# Tool invocations
69
+can_dexn: $(OBJS) $(USER_OBJS) makefile $(OPTIONAL_TOOL_DEPS)
70
+	@echo 'Building target: $@'
71
+	@echo 'Invoking: Cross G++ Linker'
72
+	arm-linux-gnueabihf-g++ -fPIC -o "can_dexn" $(OBJS) $(USER_OBJS) $(LIBS) -ldl
73
+	@echo 'Finished building target: $@'
74
+	@echo ' '
75
+
76
+# Other Targets
77
+clean:
78
+	-$(RM) can_dexn
79
+	-@echo ' '
80
+
81
+.PHONY: all clean dependents main-build
82
+
83
+-include ../makefile.targets

+ 31
- 0
Debug/service/impl/subdir.mk Прегледај датотеку

@@ -0,0 +1,31 @@
1
+################################################################################
2
+# Automatically-generated file. Do not edit!
3
+################################################################################
4
+
5
+# Add inputs and outputs from these tool invocations to the build variables 
6
+CPP_SRCS += \
7
+../service/impl/ProtocolImpl.cpp 
8
+
9
+CPP_DEPS += \
10
+./service/impl/ProtocolImpl.d 
11
+
12
+OBJS += \
13
+./service/impl/ProtocolImpl.o 
14
+
15
+
16
+# Each subdirectory must supply rules for building sources it contributes
17
+service/impl/%.o: ../service/impl/%.cpp service/impl/subdir.mk
18
+	@echo 'Building file: $<'
19
+	@echo 'Invoking: Cross G++ Compiler'
20
+	arm-linux-gnueabihf-g++ -std=c++0x -O0 -g -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
21
+	@echo 'Finished building: $<'
22
+	@echo ' '
23
+
24
+
25
+clean: clean-service-2f-impl
26
+
27
+clean-service-2f-impl:
28
+	-$(RM) ./service/impl/ProtocolImpl.d ./service/impl/ProtocolImpl.o
29
+
30
+.PHONY: clean-service-2f-impl
31
+

+ 39
- 0
Debug/sources.mk Прегледај датотеку

@@ -0,0 +1,39 @@
1
+################################################################################
2
+# Automatically-generated file. Do not edit!
3
+################################################################################
4
+
5
+ASM_SRCS := 
6
+C++M_SRCS := 
7
+C++_SRCS := 
8
+CCM_SRCS := 
9
+CC_SRCS := 
10
+CPP_SRCS := 
11
+CXXM_SRCS := 
12
+CXX_SRCS := 
13
+C_SRCS := 
14
+C_UPPER_SRCS := 
15
+OBJ_SRCS := 
16
+O_SRCS := 
17
+SX_SRCS := 
18
+S_UPPER_SRCS := 
19
+C++M_DEPS := 
20
+C++_DEPS := 
21
+CCM_DEPS := 
22
+CC_DEPS := 
23
+CPP_DEPS := 
24
+CXXM_DEPS := 
25
+CXX_DEPS := 
26
+C_DEPS := 
27
+C_UPPER_DEPS := 
28
+EXECUTABLES := 
29
+OBJS := 
30
+
31
+# Every subdirectory with source files must be described here
32
+SUBDIRS := \
33
+common \
34
+service/impl \
35
+test \
36
+util/easylogger/plugins/file \
37
+util/easylogger/port \
38
+util/easylogger/src \
39
+

+ 31
- 0
Debug/test/subdir.mk Прегледај датотеку

@@ -0,0 +1,31 @@
1
+################################################################################
2
+# Automatically-generated file. Do not edit!
3
+################################################################################
4
+
5
+# Add inputs and outputs from these tool invocations to the build variables 
6
+CPP_SRCS += \
7
+../test/main.cpp 
8
+
9
+CPP_DEPS += \
10
+./test/main.d 
11
+
12
+OBJS += \
13
+./test/main.o 
14
+
15
+
16
+# Each subdirectory must supply rules for building sources it contributes
17
+test/%.o: ../test/%.cpp test/subdir.mk
18
+	@echo 'Building file: $<'
19
+	@echo 'Invoking: Cross G++ Compiler'
20
+	arm-linux-gnueabihf-g++ -std=c++0x -O0 -g -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
21
+	@echo 'Finished building: $<'
22
+	@echo ' '
23
+
24
+
25
+clean: clean-test
26
+
27
+clean-test:
28
+	-$(RM) ./test/main.d ./test/main.o
29
+
30
+.PHONY: clean-test
31
+

+ 34
- 0
Debug/util/easylogger/plugins/file/subdir.mk Прегледај датотеку

@@ -0,0 +1,34 @@
1
+################################################################################
2
+# Automatically-generated file. Do not edit!
3
+################################################################################
4
+
5
+# Add inputs and outputs from these tool invocations to the build variables 
6
+C_SRCS += \
7
+../util/easylogger/plugins/file/elog_file.c \
8
+../util/easylogger/plugins/file/elog_file_port.c 
9
+
10
+C_DEPS += \
11
+./util/easylogger/plugins/file/elog_file.d \
12
+./util/easylogger/plugins/file/elog_file_port.d 
13
+
14
+OBJS += \
15
+./util/easylogger/plugins/file/elog_file.o \
16
+./util/easylogger/plugins/file/elog_file_port.o 
17
+
18
+
19
+# Each subdirectory must supply rules for building sources it contributes
20
+util/easylogger/plugins/file/%.o: ../util/easylogger/plugins/file/%.c util/easylogger/plugins/file/subdir.mk
21
+	@echo 'Building file: $<'
22
+	@echo 'Invoking: Cross GCC Compiler'
23
+	arm-linux-gnueabihf-gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
24
+	@echo 'Finished building: $<'
25
+	@echo ' '
26
+
27
+
28
+clean: clean-util-2f-easylogger-2f-plugins-2f-file
29
+
30
+clean-util-2f-easylogger-2f-plugins-2f-file:
31
+	-$(RM) ./util/easylogger/plugins/file/elog_file.d ./util/easylogger/plugins/file/elog_file.o ./util/easylogger/plugins/file/elog_file_port.d ./util/easylogger/plugins/file/elog_file_port.o
32
+
33
+.PHONY: clean-util-2f-easylogger-2f-plugins-2f-file
34
+

+ 31
- 0
Debug/util/easylogger/port/subdir.mk Прегледај датотеку

@@ -0,0 +1,31 @@
1
+################################################################################
2
+# Automatically-generated file. Do not edit!
3
+################################################################################
4
+
5
+# Add inputs and outputs from these tool invocations to the build variables 
6
+C_SRCS += \
7
+../util/easylogger/port/elog_port.c 
8
+
9
+C_DEPS += \
10
+./util/easylogger/port/elog_port.d 
11
+
12
+OBJS += \
13
+./util/easylogger/port/elog_port.o 
14
+
15
+
16
+# Each subdirectory must supply rules for building sources it contributes
17
+util/easylogger/port/%.o: ../util/easylogger/port/%.c util/easylogger/port/subdir.mk
18
+	@echo 'Building file: $<'
19
+	@echo 'Invoking: Cross GCC Compiler'
20
+	arm-linux-gnueabihf-gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
21
+	@echo 'Finished building: $<'
22
+	@echo ' '
23
+
24
+
25
+clean: clean-util-2f-easylogger-2f-port
26
+
27
+clean-util-2f-easylogger-2f-port:
28
+	-$(RM) ./util/easylogger/port/elog_port.d ./util/easylogger/port/elog_port.o
29
+
30
+.PHONY: clean-util-2f-easylogger-2f-port
31
+

+ 40
- 0
Debug/util/easylogger/src/subdir.mk Прегледај датотеку

@@ -0,0 +1,40 @@
1
+################################################################################
2
+# Automatically-generated file. Do not edit!
3
+################################################################################
4
+
5
+# Add inputs and outputs from these tool invocations to the build variables 
6
+C_SRCS += \
7
+../util/easylogger/src/elog.c \
8
+../util/easylogger/src/elog_async.c \
9
+../util/easylogger/src/elog_buf.c \
10
+../util/easylogger/src/elog_utils.c 
11
+
12
+C_DEPS += \
13
+./util/easylogger/src/elog.d \
14
+./util/easylogger/src/elog_async.d \
15
+./util/easylogger/src/elog_buf.d \
16
+./util/easylogger/src/elog_utils.d 
17
+
18
+OBJS += \
19
+./util/easylogger/src/elog.o \
20
+./util/easylogger/src/elog_async.o \
21
+./util/easylogger/src/elog_buf.o \
22
+./util/easylogger/src/elog_utils.o 
23
+
24
+
25
+# Each subdirectory must supply rules for building sources it contributes
26
+util/easylogger/src/%.o: ../util/easylogger/src/%.c util/easylogger/src/subdir.mk
27
+	@echo 'Building file: $<'
28
+	@echo 'Invoking: Cross GCC Compiler'
29
+	arm-linux-gnueabihf-gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
30
+	@echo 'Finished building: $<'
31
+	@echo ' '
32
+
33
+
34
+clean: clean-util-2f-easylogger-2f-src
35
+
36
+clean-util-2f-easylogger-2f-src:
37
+	-$(RM) ./util/easylogger/src/elog.d ./util/easylogger/src/elog.o ./util/easylogger/src/elog_async.d ./util/easylogger/src/elog_async.o ./util/easylogger/src/elog_buf.d ./util/easylogger/src/elog_buf.o ./util/easylogger/src/elog_utils.d ./util/easylogger/src/elog_utils.o
38
+
39
+.PHONY: clean-util-2f-easylogger-2f-src
40
+

+ 9
- 0
Release/common/GUID.d Прегледај датотеку

@@ -0,0 +1,9 @@
1
+common/GUID.o: ../common/GUID.cpp ../common/Type.h \
2
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog.h \
3
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog_cfg.h
4
+
5
+../common/Type.h:
6
+
7
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog.h:
8
+
9
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog_cfg.h:

BIN
Release/common/GUID.o Прегледај датотеку


+ 31
- 0
Release/common/subdir.mk Прегледај датотеку

@@ -0,0 +1,31 @@
1
+################################################################################
2
+# Automatically-generated file. Do not edit!
3
+################################################################################
4
+
5
+# Add inputs and outputs from these tool invocations to the build variables 
6
+CPP_SRCS += \
7
+../common/GUID.cpp 
8
+
9
+CPP_DEPS += \
10
+./common/GUID.d 
11
+
12
+OBJS += \
13
+./common/GUID.o 
14
+
15
+
16
+# Each subdirectory must supply rules for building sources it contributes
17
+common/%.o: ../common/%.cpp common/subdir.mk
18
+	@echo 'Building file: $<'
19
+	@echo 'Invoking: Cross G++ Compiler'
20
+	arm-linux-gnueabihf-g++ -std=c++0x -I"E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc" -I"E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\plugins\file" -O3 -Wall -c -fmessage-length=0 -fPIC -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
21
+	@echo 'Finished building: $<'
22
+	@echo ' '
23
+
24
+
25
+clean: clean-common
26
+
27
+clean-common:
28
+	-$(RM) ./common/GUID.d ./common/GUID.o
29
+
30
+.PHONY: clean-common
31
+

BIN
Release/libcan_BMSer.so Прегледај датотеку


+ 82
- 0
Release/makefile Прегледај датотеку

@@ -0,0 +1,82 @@
1
+################################################################################
2
+# Automatically-generated file. Do not edit!
3
+################################################################################
4
+
5
+-include ../makefile.init
6
+
7
+RM := rm -rf
8
+
9
+# All of the sources participating in the build are defined here
10
+-include sources.mk
11
+-include util/easylogger/src/subdir.mk
12
+-include util/easylogger/port/subdir.mk
13
+-include util/easylogger/plugins/file/subdir.mk
14
+-include service/impl/subdir.mk
15
+-include common/subdir.mk
16
+ifneq ($(MAKECMDGOALS),clean)
17
+ifneq ($(strip $(C++M_DEPS)),)
18
+-include $(C++M_DEPS)
19
+endif
20
+ifneq ($(strip $(C++_DEPS)),)
21
+-include $(C++_DEPS)
22
+endif
23
+ifneq ($(strip $(CCM_DEPS)),)
24
+-include $(CCM_DEPS)
25
+endif
26
+ifneq ($(strip $(CC_DEPS)),)
27
+-include $(CC_DEPS)
28
+endif
29
+ifneq ($(strip $(CPP_DEPS)),)
30
+-include $(CPP_DEPS)
31
+endif
32
+ifneq ($(strip $(CXXM_DEPS)),)
33
+-include $(CXXM_DEPS)
34
+endif
35
+ifneq ($(strip $(CXX_DEPS)),)
36
+-include $(CXX_DEPS)
37
+endif
38
+ifneq ($(strip $(C_DEPS)),)
39
+-include $(C_DEPS)
40
+endif
41
+ifneq ($(strip $(C_UPPER_DEPS)),)
42
+-include $(C_UPPER_DEPS)
43
+endif
44
+endif
45
+
46
+-include ../makefile.defs
47
+
48
+OPTIONAL_TOOL_DEPS := \
49
+$(wildcard ../makefile.defs) \
50
+$(wildcard ../makefile.init) \
51
+$(wildcard ../makefile.targets) \
52
+
53
+
54
+BUILD_ARTIFACT_NAME := libcan_BMSer
55
+BUILD_ARTIFACT_EXTENSION := so
56
+BUILD_ARTIFACT_PREFIX :=
57
+BUILD_ARTIFACT := $(BUILD_ARTIFACT_PREFIX)$(BUILD_ARTIFACT_NAME)$(if $(BUILD_ARTIFACT_EXTENSION),.$(BUILD_ARTIFACT_EXTENSION),)
58
+
59
+# Add inputs and outputs from these tool invocations to the build variables 
60
+
61
+# All Target
62
+all: main-build
63
+
64
+# Main-build Target
65
+main-build: libcan_BMSer.so
66
+
67
+# Tool invocations
68
+libcan_BMSer.so: $(OBJS) $(USER_OBJS) makefile $(OPTIONAL_TOOL_DEPS)
69
+	@echo 'Building target: $@'
70
+	@echo 'Invoking: Cross G++ Linker'
71
+	arm-linux-gnueabihf-g++ -pthread -shared -o "libcan_BMSer.so" $(OBJS) $(USER_OBJS) $(LIBS)
72
+	@echo 'Finished building target: $@'
73
+	@echo ' '
74
+
75
+# Other Targets
76
+clean:
77
+	-$(RM) libcan_BMSer.so
78
+	-@echo ' '
79
+
80
+.PHONY: all clean dependents main-build
81
+
82
+-include ../makefile.targets

+ 8
- 0
Release/objects.mk Прегледај датотеку

@@ -0,0 +1,8 @@
1
+################################################################################
2
+# Automatically-generated file. Do not edit!
3
+################################################################################
4
+
5
+USER_OBJS :=
6
+
7
+LIBS :=
8
+

+ 82
- 0
Release/service/impl/ProtocolImpl.d Прегледај датотеку

@@ -0,0 +1,82 @@
1
+service/impl/ProtocolImpl.o: ../service/impl/ProtocolImpl.cpp \
2
+ ../service/impl/ProtocolImpl.h ../service/impl/../../common/Type.h \
3
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog.h \
4
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog_cfg.h \
5
+ ../service/impl/../ProtocolI.h ../service/impl/../../common/IUnknown.h \
6
+ ../service/impl/../../common/Type.h ../service/impl/../../common/Type.h \
7
+ ../service/impl/../../common/GUID.cpp \
8
+ ../service/impl/../../servicemodel/Base.h \
9
+ ../service/impl/../../servicemodel/../common/Type.h \
10
+ ../service/impl/../../servicemodel/Channel.h \
11
+ ../service/impl/../../servicemodel/../externservice/HardwareI.h \
12
+ ../service/impl/../../servicemodel/../externservice/../common/IUnknown.h \
13
+ ../service/impl/../../servicemodel/../externservice/../common/Type.h \
14
+ ../service/impl/../../servicemodel/../service/CallBackHandleI.h \
15
+ ../service/impl/../../servicemodel/../service/../common/Type.h \
16
+ ../service/impl/../../servicemodel/../service/impl/MThreadedJobQImpl.h \
17
+ ../service/impl/../../servicemodel/Base.h \
18
+ ../service/impl/../../servicemodel/Device.h \
19
+ ../service/impl/../../servicemodel/../externservice/ParaAnalysisI.h \
20
+ ../service/impl/../../servicemodel/../externservice/ProtocolI.h \
21
+ ../service/impl/../../servicemodel/../externservice/SubContractI.h \
22
+ ../service/impl/../../servicemodel/Item.h \
23
+ ../service/impl/../../servicemodel/Packet.h \
24
+ ../service/impl/../../servicemodel/Device.h \
25
+ ../service/impl/../../servicemodel/Item.h \
26
+ ../service/impl/../../servicemodel/Packet.h
27
+
28
+../service/impl/ProtocolImpl.h:
29
+
30
+../service/impl/../../common/Type.h:
31
+
32
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog.h:
33
+
34
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog_cfg.h:
35
+
36
+../service/impl/../ProtocolI.h:
37
+
38
+../service/impl/../../common/IUnknown.h:
39
+
40
+../service/impl/../../common/Type.h:
41
+
42
+../service/impl/../../common/Type.h:
43
+
44
+../service/impl/../../common/GUID.cpp:
45
+
46
+../service/impl/../../servicemodel/Base.h:
47
+
48
+../service/impl/../../servicemodel/../common/Type.h:
49
+
50
+../service/impl/../../servicemodel/Channel.h:
51
+
52
+../service/impl/../../servicemodel/../externservice/HardwareI.h:
53
+
54
+../service/impl/../../servicemodel/../externservice/../common/IUnknown.h:
55
+
56
+../service/impl/../../servicemodel/../externservice/../common/Type.h:
57
+
58
+../service/impl/../../servicemodel/../service/CallBackHandleI.h:
59
+
60
+../service/impl/../../servicemodel/../service/../common/Type.h:
61
+
62
+../service/impl/../../servicemodel/../service/impl/MThreadedJobQImpl.h:
63
+
64
+../service/impl/../../servicemodel/Base.h:
65
+
66
+../service/impl/../../servicemodel/Device.h:
67
+
68
+../service/impl/../../servicemodel/../externservice/ParaAnalysisI.h:
69
+
70
+../service/impl/../../servicemodel/../externservice/ProtocolI.h:
71
+
72
+../service/impl/../../servicemodel/../externservice/SubContractI.h:
73
+
74
+../service/impl/../../servicemodel/Item.h:
75
+
76
+../service/impl/../../servicemodel/Packet.h:
77
+
78
+../service/impl/../../servicemodel/Device.h:
79
+
80
+../service/impl/../../servicemodel/Item.h:
81
+
82
+../service/impl/../../servicemodel/Packet.h:

BIN
Release/service/impl/ProtocolImpl.o Прегледај датотеку


+ 31
- 0
Release/service/impl/subdir.mk Прегледај датотеку

@@ -0,0 +1,31 @@
1
+################################################################################
2
+# Automatically-generated file. Do not edit!
3
+################################################################################
4
+
5
+# Add inputs and outputs from these tool invocations to the build variables 
6
+CPP_SRCS += \
7
+../service/impl/ProtocolImpl.cpp 
8
+
9
+CPP_DEPS += \
10
+./service/impl/ProtocolImpl.d 
11
+
12
+OBJS += \
13
+./service/impl/ProtocolImpl.o 
14
+
15
+
16
+# Each subdirectory must supply rules for building sources it contributes
17
+service/impl/%.o: ../service/impl/%.cpp service/impl/subdir.mk
18
+	@echo 'Building file: $<'
19
+	@echo 'Invoking: Cross G++ Compiler'
20
+	arm-linux-gnueabihf-g++ -std=c++0x -I"E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc" -I"E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\plugins\file" -O3 -Wall -c -fmessage-length=0 -fPIC -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
21
+	@echo 'Finished building: $<'
22
+	@echo ' '
23
+
24
+
25
+clean: clean-service-2f-impl
26
+
27
+clean-service-2f-impl:
28
+	-$(RM) ./service/impl/ProtocolImpl.d ./service/impl/ProtocolImpl.o
29
+
30
+.PHONY: clean-service-2f-impl
31
+

+ 38
- 0
Release/sources.mk Прегледај датотеку

@@ -0,0 +1,38 @@
1
+################################################################################
2
+# Automatically-generated file. Do not edit!
3
+################################################################################
4
+
5
+ASM_SRCS := 
6
+C++M_SRCS := 
7
+C++_SRCS := 
8
+CCM_SRCS := 
9
+CC_SRCS := 
10
+CPP_SRCS := 
11
+CXXM_SRCS := 
12
+CXX_SRCS := 
13
+C_SRCS := 
14
+C_UPPER_SRCS := 
15
+OBJ_SRCS := 
16
+O_SRCS := 
17
+SX_SRCS := 
18
+S_UPPER_SRCS := 
19
+C++M_DEPS := 
20
+C++_DEPS := 
21
+CCM_DEPS := 
22
+CC_DEPS := 
23
+CPP_DEPS := 
24
+CXXM_DEPS := 
25
+CXX_DEPS := 
26
+C_DEPS := 
27
+C_UPPER_DEPS := 
28
+LIBRARIES := 
29
+OBJS := 
30
+
31
+# Every subdirectory with source files must be described here
32
+SUBDIRS := \
33
+common \
34
+service/impl \
35
+util/easylogger/plugins/file \
36
+util/easylogger/port \
37
+util/easylogger/src \
38
+

+ 14
- 0
Release/util/easylogger/plugins/file/elog_file.d Прегледај датотеку

@@ -0,0 +1,14 @@
1
+util/easylogger/plugins/file/elog_file.o: \
2
+ ../util/easylogger/plugins/file/elog_file.c \
3
+ ../util/easylogger/plugins/file/elog_file.h \
4
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog.h \
5
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog_cfg.h \
6
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\plugins\file/elog_file_cfg.h
7
+
8
+../util/easylogger/plugins/file/elog_file.h:
9
+
10
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog.h:
11
+
12
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog_cfg.h:
13
+
14
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\plugins\file/elog_file_cfg.h:

BIN
Release/util/easylogger/plugins/file/elog_file.o Прегледај датотеку


+ 14
- 0
Release/util/easylogger/plugins/file/elog_file_port.d Прегледај датотеку

@@ -0,0 +1,14 @@
1
+util/easylogger/plugins/file/elog_file_port.o: \
2
+ ../util/easylogger/plugins/file/elog_file_port.c \
3
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\plugins\file/elog_file.h \
4
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog.h \
5
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog_cfg.h \
6
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\plugins\file/elog_file_cfg.h
7
+
8
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\plugins\file/elog_file.h:
9
+
10
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog.h:
11
+
12
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog_cfg.h:
13
+
14
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\plugins\file/elog_file_cfg.h:

BIN
Release/util/easylogger/plugins/file/elog_file_port.o Прегледај датотеку


+ 34
- 0
Release/util/easylogger/plugins/file/subdir.mk Прегледај датотеку

@@ -0,0 +1,34 @@
1
+################################################################################
2
+# Automatically-generated file. Do not edit!
3
+################################################################################
4
+
5
+# Add inputs and outputs from these tool invocations to the build variables 
6
+C_SRCS += \
7
+../util/easylogger/plugins/file/elog_file.c \
8
+../util/easylogger/plugins/file/elog_file_port.c 
9
+
10
+C_DEPS += \
11
+./util/easylogger/plugins/file/elog_file.d \
12
+./util/easylogger/plugins/file/elog_file_port.d 
13
+
14
+OBJS += \
15
+./util/easylogger/plugins/file/elog_file.o \
16
+./util/easylogger/plugins/file/elog_file_port.o 
17
+
18
+
19
+# Each subdirectory must supply rules for building sources it contributes
20
+util/easylogger/plugins/file/%.o: ../util/easylogger/plugins/file/%.c util/easylogger/plugins/file/subdir.mk
21
+	@echo 'Building file: $<'
22
+	@echo 'Invoking: Cross GCC Compiler'
23
+	arm-linux-gnueabihf-gcc -I"E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\plugins\file" -I"E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc" -O3 -Wall -c -fmessage-length=0 -fPIC -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
24
+	@echo 'Finished building: $<'
25
+	@echo ' '
26
+
27
+
28
+clean: clean-util-2f-easylogger-2f-plugins-2f-file
29
+
30
+clean-util-2f-easylogger-2f-plugins-2f-file:
31
+	-$(RM) ./util/easylogger/plugins/file/elog_file.d ./util/easylogger/plugins/file/elog_file.o ./util/easylogger/plugins/file/elog_file_port.d ./util/easylogger/plugins/file/elog_file_port.o
32
+
33
+.PHONY: clean-util-2f-easylogger-2f-plugins-2f-file
34
+

+ 13
- 0
Release/util/easylogger/port/elog_port.d Прегледај датотеку

@@ -0,0 +1,13 @@
1
+util/easylogger/port/elog_port.o: ../util/easylogger/port/elog_port.c \
2
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog.h \
3
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog_cfg.h \
4
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\plugins\file/elog_file.h \
5
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\plugins\file/elog_file_cfg.h
6
+
7
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog.h:
8
+
9
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog_cfg.h:
10
+
11
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\plugins\file/elog_file.h:
12
+
13
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\plugins\file/elog_file_cfg.h:

BIN
Release/util/easylogger/port/elog_port.o Прегледај датотеку


+ 31
- 0
Release/util/easylogger/port/subdir.mk Прегледај датотеку

@@ -0,0 +1,31 @@
1
+################################################################################
2
+# Automatically-generated file. Do not edit!
3
+################################################################################
4
+
5
+# Add inputs and outputs from these tool invocations to the build variables 
6
+C_SRCS += \
7
+../util/easylogger/port/elog_port.c 
8
+
9
+C_DEPS += \
10
+./util/easylogger/port/elog_port.d 
11
+
12
+OBJS += \
13
+./util/easylogger/port/elog_port.o 
14
+
15
+
16
+# Each subdirectory must supply rules for building sources it contributes
17
+util/easylogger/port/%.o: ../util/easylogger/port/%.c util/easylogger/port/subdir.mk
18
+	@echo 'Building file: $<'
19
+	@echo 'Invoking: Cross GCC Compiler'
20
+	arm-linux-gnueabihf-gcc -I"E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\plugins\file" -I"E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc" -O3 -Wall -c -fmessage-length=0 -fPIC -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
21
+	@echo 'Finished building: $<'
22
+	@echo ' '
23
+
24
+
25
+clean: clean-util-2f-easylogger-2f-port
26
+
27
+clean-util-2f-easylogger-2f-port:
28
+	-$(RM) ./util/easylogger/port/elog_port.d ./util/easylogger/port/elog_port.o
29
+
30
+.PHONY: clean-util-2f-easylogger-2f-port
31
+

+ 7
- 0
Release/util/easylogger/src/elog.d Прегледај датотеку

@@ -0,0 +1,7 @@
1
+util/easylogger/src/elog.o: ../util/easylogger/src/elog.c \
2
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog.h \
3
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog_cfg.h
4
+
5
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog.h:
6
+
7
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog_cfg.h:

BIN
Release/util/easylogger/src/elog.o Прегледај датотеку


+ 7
- 0
Release/util/easylogger/src/elog_async.d Прегледај датотеку

@@ -0,0 +1,7 @@
1
+util/easylogger/src/elog_async.o: ../util/easylogger/src/elog_async.c \
2
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog.h \
3
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog_cfg.h
4
+
5
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog.h:
6
+
7
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog_cfg.h:

BIN
Release/util/easylogger/src/elog_async.o Прегледај датотеку


+ 7
- 0
Release/util/easylogger/src/elog_buf.d Прегледај датотеку

@@ -0,0 +1,7 @@
1
+util/easylogger/src/elog_buf.o: ../util/easylogger/src/elog_buf.c \
2
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog.h \
3
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog_cfg.h
4
+
5
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog.h:
6
+
7
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog_cfg.h:

BIN
Release/util/easylogger/src/elog_buf.o Прегледај датотеку


+ 7
- 0
Release/util/easylogger/src/elog_utils.d Прегледај датотеку

@@ -0,0 +1,7 @@
1
+util/easylogger/src/elog_utils.o: ../util/easylogger/src/elog_utils.c \
2
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog.h \
3
+ E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog_cfg.h
4
+
5
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog.h:
6
+
7
+E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc/elog_cfg.h:

BIN
Release/util/easylogger/src/elog_utils.o Прегледај датотеку


+ 40
- 0
Release/util/easylogger/src/subdir.mk Прегледај датотеку

@@ -0,0 +1,40 @@
1
+################################################################################
2
+# Automatically-generated file. Do not edit!
3
+################################################################################
4
+
5
+# Add inputs and outputs from these tool invocations to the build variables 
6
+C_SRCS += \
7
+../util/easylogger/src/elog.c \
8
+../util/easylogger/src/elog_async.c \
9
+../util/easylogger/src/elog_buf.c \
10
+../util/easylogger/src/elog_utils.c 
11
+
12
+C_DEPS += \
13
+./util/easylogger/src/elog.d \
14
+./util/easylogger/src/elog_async.d \
15
+./util/easylogger/src/elog_buf.d \
16
+./util/easylogger/src/elog_utils.d 
17
+
18
+OBJS += \
19
+./util/easylogger/src/elog.o \
20
+./util/easylogger/src/elog_async.o \
21
+./util/easylogger/src/elog_buf.o \
22
+./util/easylogger/src/elog_utils.o 
23
+
24
+
25
+# Each subdirectory must supply rules for building sources it contributes
26
+util/easylogger/src/%.o: ../util/easylogger/src/%.c util/easylogger/src/subdir.mk
27
+	@echo 'Building file: $<'
28
+	@echo 'Invoking: Cross GCC Compiler'
29
+	arm-linux-gnueabihf-gcc -I"E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\plugins\file" -I"E:\25-0.5p\2-src\can-BMSer\can-BMSer\util\easylogger\inc" -O3 -Wall -c -fmessage-length=0 -fPIC -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
30
+	@echo 'Finished building: $<'
31
+	@echo ' '
32
+
33
+
34
+clean: clean-util-2f-easylogger-2f-src
35
+
36
+clean-util-2f-easylogger-2f-src:
37
+	-$(RM) ./util/easylogger/src/elog.d ./util/easylogger/src/elog.o ./util/easylogger/src/elog_async.d ./util/easylogger/src/elog_async.o ./util/easylogger/src/elog_buf.d ./util/easylogger/src/elog_buf.o ./util/easylogger/src/elog_utils.d ./util/easylogger/src/elog_utils.o
38
+
39
+.PHONY: clean-util-2f-easylogger-2f-src
40
+

+ 24
- 0
Release/util/iLOG/subdir.mk Прегледај датотеку

@@ -0,0 +1,24 @@
1
+################################################################################
2
+# Automatically-generated file. Do not edit!
3
+################################################################################
4
+
5
+# Add inputs and outputs from these tool invocations to the build variables 
6
+C_SRCS += \
7
+../util/iLOG/LOG.c 
8
+
9
+OBJS += \
10
+./util/iLOG/LOG.o 
11
+
12
+C_DEPS += \
13
+./util/iLOG/LOG.d 
14
+
15
+
16
+# Each subdirectory must supply rules for building sources it contributes
17
+util/iLOG/%.o: ../util/iLOG/%.c
18
+	@echo 'Building file: $<'
19
+	@echo 'Invoking: Cross GCC Compiler'
20
+	arm-linux-gnueabihf-gcc -O3 -Wall -c -fmessage-length=0 -fPIC -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
21
+	@echo 'Finished building: $<'
22
+	@echo ' '
23
+
24
+

+ 27
- 0
common/GUID.cpp Прегледај датотеку

@@ -0,0 +1,27 @@
1
+/**
2
+ * @content:组件标识符定义头文件
3
+ * @time:2016-8-23
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-8-23#V1.0#首次生成
8
+ */
9
+
10
+#include "Type.h"
11
+
12
+#ifdef __cplusplus
13
+extern "C" {
14
+#endif
15
+	const IID IID_IUnknown =
16
+		{0x6e4eb430,0x8ba5,0x4142,
17
+		{0x84,0xb1,0xd1,0xbe,0xf9,0x79,0x5b,0xec
18
+	}};
19
+	const IID IID_IProtocol =
20
+		{0x6e4eb431,0x8ba5,0x4142,
21
+		{0x84,0xb1,0xd1,0xbe,0xf9,0x79,0x5b,0xec
22
+	}};
23
+
24
+	const ProgID ProgID_IProtocol = "linux.deecs.data-service.micro-service.data-entry.components.protocol.can-dexn";
25
+#ifdef __cplusplus
26
+}
27
+#endif

+ 26
- 0
common/IFace.h Прегледај датотеку

@@ -0,0 +1,26 @@
1
+/**
2
+ * @content:组件标识符定义头文件
3
+ * @time:2016-10-6
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-10-6#V1.0#首次生成
8
+ */
9
+
10
+#ifndef INCLUDE_IFACE_H_
11
+#define INCLUDE_IFACE_H_
12
+
13
+#include "Type.h"
14
+
15
+#ifdef __cplusplus
16
+extern "C" {
17
+#endif
18
+	extern const IID IID_IUnknown;
19
+	extern const IID IID_IProtocol;
20
+
21
+	extern const ProgID ProgID_IProtocol;
22
+#ifdef __cplusplus
23
+}
24
+#endif
25
+
26
+#endif /* INCLUDE_IFACE_H_ */

+ 24
- 0
common/IUnknown.h Прегледај датотеку

@@ -0,0 +1,24 @@
1
+/**
2
+ * @content:IUnknown接口定义头文件
3
+ * @time:2016-8-23
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-8-23#V1.0#首次生成
8
+ */
9
+
10
+#ifndef INCLUDE_IUNKNOWN_H_
11
+#define INCLUDE_IUNKNOWN_H_
12
+
13
+#include "Type.h"
14
+
15
+interface IUnknown{
16
+	virtual HRESULT queryInterface(const IID& iid, void** ppv) = 0;	//----查询接口
17
+	virtual ULONG addRef() = 0;	//----增加引用计数
18
+	virtual ULONG release() = 0;	//----释放接口
19
+	virtual ULONG getVersion() = 0;	//----获取组件版本
20
+
21
+	virtual ~IUnknown(){};
22
+};
23
+
24
+#endif /* INCLUDE_IUNKNOWN_H_ */

+ 412
- 0
common/Type.h Прегледај датотеку

@@ -0,0 +1,412 @@
1
+/**
2
+ * @content:基本类型定义
3
+ * @time:2016-8-23
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-8-23#V1.0#首次生成
8
+ */
9
+
10
+#ifndef TYPE_H
11
+#define TYPE_H
12
+
13
+#define LOG_TAG    "can_dexn"
14
+
15
+#include <elog.h>
16
+
17
+#include <errno.h>
18
+#include <math.h>
19
+#include <sys/select.h>
20
+#include <sys/time.h>
21
+#include <cstdio>
22
+#include <ctime>
23
+#include <iostream>
24
+#include <iterator>
25
+#include <string>
26
+#include <vector>
27
+
28
+typedef long HRESULT;
29
+typedef unsigned long ULONG;
30
+
31
+typedef char BYTE;
32
+typedef char* PBYTE;
33
+
34
+class IUnknown;
35
+
36
+#ifndef NULL
37
+#define NULL 0
38
+#endif
39
+
40
+typedef struct _GUID
41
+{
42
+	unsigned int Data1;
43
+	unsigned short Data2;
44
+	unsigned short Data3;
45
+	unsigned char Data4[8];
46
+
47
+	std::string toString()
48
+	{
49
+		char t[256];
50
+		snprintf(t, 256, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", Data1, Data2, Data3, Data4[0], Data4[1], Data4[2], Data4[3], Data4[4], Data4[5],
51
+				Data4[6], Data4[7]);
52
+		return t;
53
+	}
54
+
55
+} GUID;
56
+
57
+typedef GUID IID;
58
+
59
+typedef std::string ProgID;
60
+
61
+#define interface struct
62
+#define CLSID IID	//----组件标识符
63
+#define OBJID IID	//----对象标识符
64
+
65
+#define E_NOINTERFACE 0x80004002L
66
+#define S_OK 0
67
+#define S_FALSE 1
68
+
69
+#define SUCCEEDED(x) ((x)==S_OK)
70
+
71
+#define READ_O 0x00000001
72
+#define READ_WAIT 0x00000002
73
+#define READ_TIMEOUT 0x00000004
74
+#define WRITE_O 0x00000008
75
+#define WRITE_WAIT 0x00000010
76
+#define WRITE_TIMEOUT 0x00000020
77
+#define WRITE_FAIL 0x00000040
78
+
79
+#define HEX 16
80
+
81
+typedef IUnknown* (*CreateFuncPTR)();
82
+
83
+inline BYTE HByte(unsigned int x)
84
+{
85
+	return (((x) >> 8) & 0x00ff);
86
+}
87
+inline BYTE LByte(unsigned int x)
88
+{
89
+	return (((x)) & 0x00ff);
90
+}
91
+
92
+inline BYTE HHByte(unsigned int x)
93
+{
94
+	return (((x) >> 24) & 0x000000ff);
95
+}
96
+inline BYTE HLByte(unsigned int x)
97
+{
98
+	return (((x) >> 16) & 0x000000ff);
99
+}
100
+inline BYTE LHByte(unsigned int x)
101
+{
102
+	return (((x) >> 8) & 0x000000ff);
103
+}
104
+inline BYTE LLByte(unsigned int x)
105
+{
106
+	return (((x)) & 0x000000ff);
107
+}
108
+
109
+inline BYTE HHByte(long int x)
110
+{
111
+	return (((x) >> 24) & 0x000000ff);
112
+}
113
+inline BYTE HLByte(long int x)
114
+{
115
+	return (((x) >> 16) & 0x000000ff);
116
+}
117
+inline BYTE LHByte(long int x)
118
+{
119
+	return (((x) >> 8) & 0x000000ff);
120
+}
121
+inline BYTE LLByte(long int x)
122
+{
123
+	return (((x)) & 0x000000ff);
124
+}
125
+
126
+inline BYTE HHByte(int x)
127
+{
128
+	return (((x) >> 24) & 0x000000ff);
129
+}
130
+inline BYTE HLByte(int x)
131
+{
132
+	return (((x) >> 16) & 0x000000ff);
133
+}
134
+inline BYTE LHByte(int x)
135
+{
136
+	return (((x) >> 8) & 0x000000ff);
137
+}
138
+inline BYTE LLByte(int x)
139
+{
140
+	return (((x)) & 0x000000ff);
141
+}
142
+
143
+/**
144
+ * @content:输出调试信息至stdout
145
+ * @time:2016-8-26
146
+ * @author:Mr_zhu
147
+ * @param: const ProgID(组件中文标识符),const char*(待输出信息)
148
+ * @return: void
149
+ * @decribe
150
+ * 1#2016-8-26#V1.0#首次生成
151
+ */
152
+inline void trace(const ProgID pid, const char* msg)
153
+{
154
+	struct timeval tv;
155
+	struct timezone tz;
156
+
157
+	struct tm *p;
158
+
159
+	gettimeofday(&tv, &tz);
160
+//	printf("tv_sec:%ld\n", tv.tv_sec);
161
+//	printf("tv_usec:%ld\n", tv.tv_usec);
162
+//	printf("tz_minuteswest:%d\n", tz.tz_minuteswest);
163
+//	printf("tz_dsttime:%d\n", tz.tz_dsttime);
164
+
165
+	p = localtime(&tv.tv_sec);
166
+	char t[255];
167
+	snprintf(t, 255, "time_now:%04d-%02d-%02d %02d-%02d-%02d,%ld", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, tv.tv_usec);
168
+//	std::cout << __FILE__ << "," << __LINE__ << "[" << t << "], "<< pid << ":" << msg
169
+//			<< std::endl;
170
+	std::cout << "[" << t << "], " << pid << ":" << msg << std::endl;
171
+}
172
+
173
+/**
174
+ * @content:将String转为Hex
175
+ * @time:2016-10-1
176
+ * @author:Mr_zhu
177
+ * @param: std::string(待转字符串)
178
+ * @return: unsigned int(返回值)
179
+ * @decribe
180
+ * 1#2016-10-1#V1.0#首次生成
181
+ */
182
+inline unsigned int hexstringtoInt(std::string str)
183
+{
184
+	unsigned int result = 0;
185
+	for (unsigned int i = 0; i < str.length(); i++)
186
+	{
187
+		if ((str.at(i) >= '0') && (str.at(i) <= '9'))
188
+		{
189
+			result += ((str.at(i) - 48) * pow(16, str.length() - 1 - i));
190
+		}
191
+		else if ((str.at(i) >= 'a') && (str.at(i) <= 'f'))
192
+		{
193
+			result += ((str.at(i) - 97 + 10) * pow(16, str.length() - 1 - i));
194
+		}
195
+	}
196
+	return result;
197
+}
198
+
199
+/**
200
+ * @content:将String转为Hex
201
+ * @time:2016-10-1
202
+ * @author:Mr_zhu
203
+ * @param: std::string(待转字符串)
204
+ * @return: unsigned short(返回值)
205
+ * @decribe
206
+ * 1#2016-10-1#V1.0#首次生成
207
+ */
208
+inline unsigned short hexstringtoShort(std::string str)
209
+{
210
+	unsigned short result = 0;
211
+	for (unsigned int i = 0; i < str.length(); i++)
212
+	{
213
+		if ((str.at(i) >= '0') && (str.at(i) <= '9'))
214
+		{
215
+			result += (str.at(i) - 48) * pow(16, str.length() - 1 - i);
216
+		}
217
+		if ((str.at(i) >= 'a') && (str.at(i) <= 'f'))
218
+		{
219
+			result += (str.at(i) - 97 + 10) * pow(16, str.length() - 1 - i);
220
+		}
221
+	}
222
+	return result;
223
+}
224
+
225
+/**
226
+ * @content:将String转为Hex
227
+ * @time:2016-10-1
228
+ * @author:Mr_zhu
229
+ * @param: std::string(待转字符串)
230
+ * @return: unsigned char(返回值)
231
+ * @decribe
232
+ * 1#2016-10-1#V1.0#首次生成
233
+ */
234
+inline unsigned char hexstringtoChar(std::string str)
235
+{
236
+	unsigned char result = 0;
237
+	for (unsigned int i = 0; i < str.length(); i++)
238
+	{
239
+		if ((str.at(i) >= '0') && (str.at(i) <= '9'))
240
+		{
241
+			result += (str.at(i) - 48) * pow(16, str.length() - 1 - i);
242
+		}
243
+		if ((str.at(i) >= 'a') && (str.at(i) <= 'f'))
244
+		{
245
+			result += (str.at(i) - 97 + 10) * pow(16, str.length() - 1 - i);
246
+		}
247
+	}
248
+	return result;
249
+}
250
+
251
+/**
252
+ * @content:将String转为GUID
253
+ * @time:2016-10-1
254
+ * @author:Mr_zhu
255
+ * @param: std::string(待转字符串)
256
+ * @return: GUID(返回的GUID)
257
+ * @decribe
258
+ * 1#2016-10-1#V1.0#首次生成
259
+ */
260
+inline GUID stringtoGUID(std::string str)
261
+{
262
+	GUID t_guid =
263
+	{ 0, 0, 0,
264
+	{ 0, 0, 0, 0, 0, 0, 0, 0 } };
265
+
266
+	if (!str.empty())
267
+	{
268
+		std::string t_str = str;
269
+		std::vector<std::string> t_vstr;
270
+//	int index = t_str.find('{');
271
+//	int index1 = t_str.find('}');
272
+		int index = 0;
273
+		int index1 = 0;
274
+		if ((index != -1) && (index1 != -1))
275
+		{
276
+			t_str = t_str.substr(0);
277
+			int index = t_str.find('-');
278
+
279
+			while (index != -1)
280
+			{
281
+				t_vstr.push_back(t_str.substr(0, index));
282
+				t_str = t_str.substr(index + 1);
283
+				index = t_str.find('-');
284
+				if (index == -1)
285
+				{
286
+					break;
287
+				}
288
+			}
289
+			t_vstr.push_back(t_str);
290
+		}
291
+		if (t_vstr.size() == 5)
292
+		{
293
+			t_guid.Data1 = hexstringtoInt(t_vstr.at(0));
294
+			t_guid.Data2 = hexstringtoShort(t_vstr.at(1));
295
+			t_guid.Data3 = hexstringtoShort(t_vstr.at(2));
296
+			t_guid.Data4[0] = hexstringtoChar(t_vstr.at(3).substr(0, 2));
297
+			t_guid.Data4[1] = hexstringtoChar(t_vstr.at(3).substr(2));
298
+			std::string sstr = t_vstr.at(4);
299
+			t_guid.Data4[2] = hexstringtoChar(sstr.substr(0, 2));
300
+			t_guid.Data4[3] = hexstringtoChar(sstr.substr(2, 2));
301
+			t_guid.Data4[4] = hexstringtoChar(sstr.substr(4, 2));
302
+			t_guid.Data4[5] = hexstringtoChar(sstr.substr(6, 2));
303
+			t_guid.Data4[6] = hexstringtoChar(sstr.substr(8, 2));
304
+			t_guid.Data4[7] = hexstringtoChar(sstr.substr(10, 2));
305
+		}
306
+	}
307
+	return t_guid;
308
+}
309
+
310
+/**
311
+ * @content: 比较两个标识符是否相等
312
+ * @time:2016-8-26
313
+ * @author:Mr_zhu
314
+ * @param: const IID&(待比较标识符1),const IID2&(待比较标识符2)
315
+ * @return: void
316
+ * @decribe
317
+ * 1#2016-8-26#V1.0#首次生成
318
+ */
319
+inline bool operator==(const IID& guid1, const IID& guid2)
320
+{
321
+	if (guid1.Data1 != guid2.Data1)
322
+		return false;
323
+	if (guid1.Data2 != guid2.Data2)
324
+		return false;
325
+	if (guid1.Data3 != guid2.Data3)
326
+		return false;
327
+	for (int i = 0; i < 8; i++)
328
+	{
329
+		if (guid1.Data4[i] != guid2.Data4[i])
330
+			return false;
331
+	}
332
+	return true;
333
+}
334
+
335
+/**
336
+ * @content: 比较标识符1是否小于标识符2
337
+ * @time:2016-8-26
338
+ * @author:Mr_zhu
339
+ * @param: const IID&(待比较标识符1),const IID2&(待比较标识符2)
340
+ * @return: void
341
+ * @decribe
342
+ * 1#2016-8-26#V1.0#首次生成
343
+ */
344
+inline bool operator<(const IID& guid1, const IID& guid2)
345
+{
346
+	if (guid1.Data1 >= guid2.Data1)
347
+		return false;
348
+	if (guid1.Data2 >= guid2.Data2)
349
+		return false;
350
+	if (guid1.Data3 >= guid2.Data3)
351
+		return false;
352
+	for (int i = 0; i < 8; i++)
353
+	{
354
+		if (guid1.Data4[i] >= guid2.Data4[i])
355
+			return false;
356
+	}
357
+	return true;
358
+}
359
+
360
+inline bool isGUIDEqual(const IID& guid1, const IID& guid2)
361
+{
362
+	return ((guid1.Data1 == guid2.Data1) && (guid1.Data2 == guid2.Data2) && (guid1.Data3 == guid2.Data3) && (guid1.Data4[0] == guid2.Data4[0])
363
+			&& (guid1.Data4[1] == guid2.Data4[1]) && (guid1.Data4[2] == guid2.Data4[2]) && (guid1.Data4[3] == guid2.Data4[3])
364
+			&& (guid1.Data4[4] == guid2.Data4[4]) && (guid1.Data4[5] == guid2.Data4[5]) && (guid1.Data4[6] == guid2.Data4[6])
365
+			&& (guid1.Data4[7] == guid2.Data4[7]));
366
+}
367
+
368
+inline void secondsSleep(unsigned int seconds)
369
+{
370
+	struct timeval tv;
371
+	tv.tv_sec = seconds;
372
+	tv.tv_usec = 0;
373
+	int err;
374
+	do
375
+	{
376
+		err = select(0, NULL, NULL, NULL, &tv);
377
+	} while (err < 0 && errno == EINTR);
378
+}
379
+
380
+inline void milisecondsSleep(unsigned int mSeconds)
381
+{
382
+	struct timeval tv;
383
+	tv.tv_sec = mSeconds / 1000;
384
+	tv.tv_usec = (mSeconds % 1000) * 1000;
385
+	int err;
386
+	do
387
+	{
388
+		err = select(0, NULL, NULL, NULL, &tv);
389
+	} while (err < 0 && errno == EINTR);
390
+}
391
+
392
+inline void microssecondsSleep(unsigned int uSeconds)
393
+{
394
+	struct timeval tv;
395
+	tv.tv_sec = uSeconds / 1000000;
396
+	tv.tv_usec = uSeconds % 1000000;
397
+	int err;
398
+	do
399
+	{
400
+		err = select(0, NULL, NULL, NULL, &tv);
401
+	} while (err < 0 && errno == EINTR);
402
+}
403
+
404
+/**
405
+ * DEBUG等级
406
+ */
407
+typedef enum
408
+{
409
+	DEBUG = 0, INFO, WARN, ERROR, FATAL
410
+} LEVEL;
411
+
412
+#endif

+ 33
- 0
externservice/CoCreateI.h Прегледај датотеку

@@ -0,0 +1,33 @@
1
+/**
2
+ * @content:CreateI接口定义头文件
3
+ * @time:2016-9-24
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-9-24#V1.0#首次生成
8
+ */
9
+
10
+#ifndef INCLUDE_ICREATE_H_
11
+#define INCLUDE_ICREATE_H_
12
+
13
+#include "../common/IUnknown.h"
14
+#include "../common/Type.h"
15
+
16
+interface CreateI:IUnknown{
17
+	/**
18
+	 * 根据so文件名创建接口
19
+	 */
20
+	virtual IUnknown* coCreateInstance(const char* nameofso) = 0;
21
+
22
+	/**
23
+	 * 根据CLSID创建接口
24
+	 */
25
+	virtual IUnknown* callCreateInstance(CLSID& clsid) = 0;
26
+
27
+	/**
28
+	 * 关闭接口句柄
29
+	 */
30
+	virtual void closeHandle() = 0;
31
+};
32
+
33
+#endif /* INCLUDE_ICREATE_H_ */

+ 123
- 0
externservice/HardwareI.h Прегледај датотеку

@@ -0,0 +1,123 @@
1
+/**
2
+ * @content:HardwareI接口定义文件
3
+ * @time:2016-9-7
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-9-7#V1.0#首次生成
8
+ */
9
+
10
+#ifndef INCLUDE_IHARDWARE_H_
11
+#define INCLUDE_IHARDWARE_H_
12
+
13
+#include <map>
14
+#include <string>
15
+
16
+#include "../common/IUnknown.h"
17
+#include "../common/Type.h"
18
+
19
+struct CallBackHandleI;
20
+
21
+interface HardwareI:IUnknown{
22
+	/**
23
+	 * 设置硬件参数
24
+	 */
25
+	virtual HRESULT setParam(
26
+		std::map<std::string,std::string>::iterator param,
27
+		const int length
28
+	) = 0;
29
+
30
+	/**
31
+	 * 打开硬件
32
+	 */
33
+	virtual HRESULT openHW() = 0;
34
+
35
+	/**
36
+	 * 初始化硬件
37
+	 */
38
+	virtual HRESULT init() = 0;
39
+
40
+	/**
41
+	 * 启动硬件
42
+	 */
43
+	virtual HRESULT start() = 0;
44
+
45
+	/**
46
+	 * 停止硬件
47
+	 */
48
+	virtual HRESULT stop() = 0;
49
+
50
+	/**
51
+	 * 挂起硬件
52
+	 */
53
+	virtual HRESULT hang() = 0;
54
+
55
+	/**
56
+	 * 恢复硬件
57
+	 */
58
+	virtual HRESULT resume() = 0;
59
+
60
+	/**
61
+	 * 硬件是否处于运行
62
+	 */
63
+	virtual HRESULT isRun() = 0;
64
+
65
+	/**
66
+	 * 硬件是否挂起
67
+	 */
68
+	virtual HRESULT isHang() = 0;
69
+
70
+	/**
71
+	 * 注册硬件回调接口
72
+	 */
73
+	virtual HRESULT registerHandler(
74
+		CallBackHandleI *pfunc
75
+	) = 0;
76
+
77
+	/**
78
+	 * 同步写操作
79
+	 */
80
+	virtual HRESULT syncRead(
81
+		PBYTE preadbuf,
82
+		const unsigned int length,
83
+		int& len,
84
+		const unsigned int timeout
85
+	) = 0;
86
+
87
+	/**
88
+	 * 异步读操作
89
+	 */
90
+	virtual HRESULT asyncRead(
91
+		PBYTE preadbuf,
92
+		const unsigned int length,
93
+		int& len
94
+	) = 0;
95
+
96
+	/**
97
+	 * 同步写操作
98
+	 */
99
+	virtual HRESULT syncWrite(
100
+		PBYTE pwritebuf,
101
+		const unsigned int length,
102
+		int& len,
103
+		const unsigned int timeout
104
+	) = 0;
105
+
106
+	/**
107
+	 * 异步写操作
108
+	 */
109
+	virtual HRESULT asyncWrite(
110
+		PBYTE pwritebuf,
111
+		const unsigned int length,
112
+		int& len
113
+	) = 0;
114
+
115
+	/**
116
+	 * 释放硬件
117
+	 */
118
+	virtual HRESULT realeseHW() = 0;
119
+
120
+	virtual ~HardwareI(){}
121
+};
122
+
123
+#endif /* INCLUDE_IHARDWARE_H_ */

+ 51
- 0
externservice/ParaAnalysisI.h Прегледај датотеку

@@ -0,0 +1,51 @@
1
+/**
2
+ * @content:ParaAnalysisI接口定义头文件
3
+ * @time:2016-8-25
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-8-23#V1.0#首次生成
8
+ */
9
+
10
+#ifndef INCLUDE_IPARAANALYSIS_H_
11
+#define INCLUDE_IPARAANALYSIS_H_
12
+
13
+#include <string>
14
+
15
+#include "../common/IUnknown.h"
16
+#include "../common/Type.h"
17
+
18
+interface ParaAnalysisI: IUnknown
19
+{
20
+
21
+	enum DATATYPE
22
+	{
23
+		STRING = 0,
24
+		INT,
25
+		FLOAT,
26
+		HEXINT,
27
+		HEXFLOAT
28
+	};
29
+
30
+	/**
31
+	 * 获取参数个数
32
+	 */
33
+	virtual ULONG getParaCount() = 0;
34
+
35
+	/**
36
+	 * 根据索引获取参数对
37
+	 */
38
+	virtual HRESULT getParam(const unsigned int index, std::string& key,
39
+			std::string& value, DATATYPE& datatype) = 0;
40
+
41
+	/**
42
+	 * 设置参数字符串
43
+	 */
44
+	virtual HRESULT setParaString(const std::string para) = 0;
45
+
46
+	virtual ~ParaAnalysisI()
47
+	{
48
+	}
49
+};
50
+
51
+#endif /* INCLUDE_IPARAANALYSIS_H_ */

+ 73
- 0
externservice/ProtocolI.h Прегледај датотеку

@@ -0,0 +1,73 @@
1
+/**
2
+ * @content:ProtocolI接口定义文件
3
+ * @time:2016-9-7
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-9-7#V1.0#首次生成
8
+ */
9
+
10
+#ifndef INCLUDE_IPROTOCOL_H_
11
+#define INCLUDE_IPROTOCOL_H_
12
+
13
+#include <string>
14
+
15
+#include "../common/IUnknown.h"
16
+#include "../common/type.h"
17
+
18
+class Device;
19
+class Item;
20
+class Packet;
21
+
22
+interface ProtocolI:IUnknown{
23
+	/**
24
+	 * 读数据
25
+	 */
26
+	virtual HRESULT onRead(
27
+		Device* pdevice,	//----设备句柄
28
+		Packet* ppacket,	//----包句柄
29
+		Item* pitem,	//----点句柄
30
+		PBYTE pbuf,	//----数据缓冲区
31
+		int& len	//----数据长度
32
+	) = 0;
33
+
34
+	/**
35
+	 * 写数据
36
+	 */
37
+	virtual HRESULT onWrite(
38
+		Device* pdevice,	//----设备句柄
39
+		Packet* ppacket,	//----包句柄
40
+		Item* pitem,	//----点句柄
41
+		PBYTE pbuf,	//----数据缓冲区
42
+		int& len,	//----数据长度
43
+		std::string swritebuf,	//----待写数据字符串
44
+		const unsigned int writelen	//----待写数据长度
45
+	) = 0;
46
+
47
+	/**
48
+	 * 判断回复数据是否完全
49
+	 */
50
+	virtual HRESULT isResponseOK(
51
+		Device* pdevice,	//----设备句柄
52
+		Packet* ppacket,	//----包句柄
53
+		Item* pitem,	//----点句柄
54
+		PBYTE pbuf,	//----数据缓冲区
55
+		const int len	//----数据长度
56
+	) = 0;
57
+
58
+	/**
59
+	 * 解析数据
60
+	 */
61
+	virtual HRESULT onResponse(
62
+		Device* pdevice,	//----设备句柄
63
+		Packet* ppacket,	//----包句柄
64
+		Item* pitem,	//----点句柄
65
+		PBYTE pbuf,	//----数据缓冲区
66
+		const int len,	//----数据长度
67
+		int& deletelen	//----删除数据长度
68
+	) = 0;
69
+
70
+	virtual ~ProtocolI(){}
71
+};
72
+
73
+#endif /* INCLUDE_IMANAGER_H_ */

+ 82
- 0
externservice/Sqlite3I.h Прегледај датотеку

@@ -0,0 +1,82 @@
1
+/**
2
+ * @content:Sqlite3I接口定义文件
3
+ * @time:2016-8-25
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-8-23#V1.0#首次生成
8
+ */
9
+
10
+#ifndef INCLUDE_SQLITE3I_H_
11
+#define INCLUDE_SQLITE3I_H_
12
+
13
+#include <string>
14
+
15
+#include "../common/IUnknown.h"
16
+#include "../common/Type.h"
17
+
18
+interface Sqlite3I:IUnknown{
19
+	/**
20
+	 * 打开Sqlite3数据库文件
21
+	 */
22
+	virtual bool Open(std::string const& db_file) = 0;
23
+
24
+	/**
25
+	 * 直接执行SQL语句
26
+	 */
27
+	virtual bool DirectStatement(std::string const& stmt) = 0;
28
+
29
+	/**
30
+	 * 执行SQL语句
31
+	 */
32
+	virtual bool Statement(std::string const& stmt) = 0;
33
+
34
+	/**
35
+	 * SQL事务处理接口
36
+	 */
37
+	virtual bool Begin() = 0;
38
+	virtual bool Commit() = 0;
39
+	virtual bool Rollback() = 0;
40
+
41
+	/**
42
+	 * 获取上次Sqlite3操作错误代码
43
+	 */
44
+	virtual std::string LastError() = 0;
45
+
46
+	/**
47
+	 * 参数绑定
48
+	 */
49
+	virtual bool Bind(int pos_zero_indexed, std::string const& value) = 0;
50
+	virtual bool Bind(int pos_zero_indexed, double value) = 0;
51
+	virtual bool Bind(int pos_zero_indexed, int value) = 0;
52
+	virtual bool BindNull(int pos_zero_indexed) = 0;
53
+
54
+	/**
55
+	 * 执行SQL
56
+	 */
57
+	virtual bool Execute() = 0;
58
+
59
+	/**
60
+	 * 获取查询结果的下一行
61
+	 */
62
+	virtual bool NextRow() = 0;
63
+
64
+	virtual bool Reset() = 0;
65
+	virtual bool RestartSelect() = 0;
66
+
67
+	/**
68
+	 * 获取String结果值
69
+	 */
70
+	virtual std::string ValueString(int pos_zero_indexed) = 0;
71
+
72
+	/**
73
+	 * 获取Int结果值
74
+	 */
75
+	virtual int ValueInt(int pos_zero_indexed) = 0;
76
+
77
+	virtual double ValueFloat(int pos_zero_indexed) = 0;
78
+
79
+	virtual ~Sqlite3I(){}
80
+};
81
+
82
+#endif /* INCLUDE_SQLITE3I_H_ */

+ 34
- 0
externservice/SubContractI.h Прегледај датотеку

@@ -0,0 +1,34 @@
1
+/**
2
+ * @content:分包组件接口头文件
3
+ * @time:2016-10-6
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-10-6#V1.0#首次生成
8
+ */
9
+
10
+#ifndef INCLUDE_SUBCONTRACTI_H_
11
+#define INCLUDE_SUBCONTRACTI_H_
12
+
13
+#include "../common/IUnknown.h"
14
+#include "../common/Type.h"
15
+
16
+class Device;
17
+class Item;
18
+class Packet;
19
+
20
+interface SubContractI:IUnknown{
21
+	/**
22
+	 * 分包算法
23
+	 */
24
+	virtual bool isSubContract(
25
+		Device* device,
26
+		Packet* packet,
27
+		Item* item,
28
+		Packet** rpacket
29
+	) = 0;
30
+
31
+	virtual ~SubContractI(){}
32
+};
33
+
34
+#endif /* INCLUDE_SUBCONTRACTI_H_ */

+ 37
- 0
service/CallBackHandleI.h Прегледај датотеку

@@ -0,0 +1,37 @@
1
+/**
2
+ * @content:CallBackHandleI回调接口定义
3
+ * @time:2016-9-7
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-9-7#V1.0#首次生成
8
+ */
9
+
10
+#ifndef INCLUDE_ICALLBACKHANDLE_H_
11
+#define INCLUDE_ICALLBACKHANDLE_H_
12
+
13
+#include "../common/Type.h"
14
+
15
+interface CallBackHandleI{
16
+	/**
17
+	 * 数据接收回调接口
18
+	 */
19
+	virtual HRESULT onRecieveData(
20
+		PBYTE pbuf,
21
+		const unsigned int len
22
+	) = 0;
23
+
24
+	/**
25
+	 * 获取接收数据
26
+	 */
27
+	virtual HRESULT getRecieveData(PBYTE pbuf, int& len) = 0;
28
+
29
+	/**
30
+	 * 清空数据缓冲区
31
+	 */
32
+	virtual HRESULT resetBuf() = 0;
33
+
34
+	virtual ~CallBackHandleI(){}
35
+};
36
+
37
+#endif /* INCLUDE_ICALLBACKHANDLE_H_ */

+ 73
- 0
service/ProtocolI.h Прегледај датотеку

@@ -0,0 +1,73 @@
1
+/**
2
+ * @content:ProtocolI接口定义文件
3
+ * @time:2016-9-7
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-9-7#V1.0#首次生成
8
+ */
9
+
10
+#ifndef INCLUDE_IPROTOCOL_H_
11
+#define INCLUDE_IPROTOCOL_H_
12
+
13
+#include <string>
14
+
15
+#include "../common/IUnknown.h"
16
+#include "../common/Type.h"
17
+
18
+class Device;
19
+class Item;
20
+class Packet;
21
+
22
+interface ProtocolI:IUnknown{
23
+	/**
24
+	 * 读数据
25
+	 */
26
+	virtual HRESULT onRead(
27
+		Device* pdevice,	//----设备句柄
28
+		Packet* ppacket,	//----包句柄
29
+		Item* pitem,	//----点句柄
30
+		PBYTE pbuf,	//----数据缓冲区
31
+		int& len	//----数据长度
32
+	) = 0;
33
+
34
+	/**
35
+	 * 写数据
36
+	 */
37
+	virtual HRESULT onWrite(
38
+		Device* pdevice,	//----设备句柄
39
+		Packet* ppacket,	//----包句柄
40
+		Item* pitem,	//----点句柄
41
+		PBYTE pbuf,	//----数据缓冲区
42
+		int& len,	//----数据长度
43
+		std::string swritebuf,	//----待写数据字符串
44
+		const unsigned int writelen	//----待写数据长度
45
+	) = 0;
46
+
47
+	/**
48
+	 * 判断回复数据是否完全
49
+	 */
50
+	virtual HRESULT isResponseOK(
51
+		Device* pdevice,	//----设备句柄
52
+		Packet* ppacket,	//----包句柄
53
+		Item* pitem,	//----点句柄
54
+		PBYTE pbuf,	//----数据缓冲区
55
+		const int len	//----数据长度
56
+	) = 0;
57
+
58
+	/**
59
+	 * 解析数据
60
+	 */
61
+	virtual HRESULT onResponse(
62
+		Device* pdevice,	//----设备句柄
63
+		Packet* ppacket,	//----包句柄
64
+		Item* pitem,	//----点句柄
65
+		PBYTE pbuf,	//----数据缓冲区
66
+		const int len,	//----数据长度
67
+		int& deletelen	//----删除数据长度
68
+	) = 0;
69
+
70
+	virtual ~ProtocolI(){}
71
+};
72
+
73
+#endif /* INCLUDE_IMANAGER_H_ */

+ 58
- 0
service/impl/JobExecuterImpl.h Прегледај датотеку

@@ -0,0 +1,58 @@
1
+/*
2
+ * JobExecuterImpl.h
3
+ *
4
+ *  Created on: 2016年11月18日
5
+ *      Author: nego
6
+ */
7
+
8
+#ifndef SERVICE_IMPL_JOBEXECUTERIMPL_H_
9
+#define SERVICE_IMPL_JOBEXECUTERIMPL_H_
10
+
11
+#include <pthread.h>
12
+#include "MThreadedJobQImpl.h"
13
+
14
+class JobI;
15
+class MThreadedJobQImpl;
16
+
17
+class JobExecuterImpl {
18
+public:
19
+	//This function stops the Executer. Your code should not call this method.?
20
+	void stop();
21
+
22
+	//This points to the CMThreadedJobQ to which this instace belongs.?
23
+	MThreadedJobQImpl* m_pJobQ;
24
+
25
+	//This contain the refarence to a instance of CJob or it's child class.
26
+	//The executer remains idle if this is NULL. That is when no job to do.
27
+	JobI* m_pJob2Do;
28
+
29
+	//This is used as a Flag. Two defind constats are
30
+	//defined for this variable, they are  STOP_WORKING (Value is  -1),
31
+	//KEEP_WORKING (value is  0 ). If the m_flaag value is set to STOP_WORKING then
32
+	//the thread associated with the instance exists, else that thread is keep working.
33
+	int m_flag;
34
+
35
+	//This pointer keep a reference to the thread that
36
+	//is associated with the class.
37
+	pthread_t pid;
38
+
39
+	//This operation is responsible for executing a job. The CMThreadedJobQ
40
+	//class will call this function to get a job done. User should not call
41
+	//this method, this is only for the use of the implementation of the
42
+	//multithreaded job queue.
43
+	void execute(JobI* pJob);
44
+
45
+	//This is the static thread function. This function is used while
46
+	//creating the thread in the constructor.
47
+	static void* ThreadFunction(void* pParam);
48
+
49
+	//Constructor
50
+	JobExecuterImpl(MThreadedJobQImpl *pJobQ);
51
+
52
+	virtual ~JobExecuterImpl();
53
+
54
+private:
55
+	static pthread_mutex_t xLock;
56
+};
57
+
58
+#endif /* SERVICE_IMPL_JOBEXECUTERIMPL_H_ */

+ 114
- 0
service/impl/MThreadedJobQImpl.h Прегледај датотеку

@@ -0,0 +1,114 @@
1
+/*
2
+ * MThreadedJobQImpl.h
3
+ *
4
+ *  Created on: 2016年11月18日
5
+ *      Author: nego
6
+ */
7
+
8
+#ifndef SERVICE_IMPL_MTHREADEDJOBQIMPL_H_
9
+#define SERVICE_IMPL_MTHREADEDJOBQIMPL_H_
10
+
11
+#include <pthread.h>
12
+#include <vector>
13
+
14
+class JobExecuterImpl;
15
+class JobI;
16
+
17
+class MThreadedJobQImpl {
18
+public:
19
+	typedef struct THNODE {
20
+		//Pointer to the Job Executer
21
+		JobExecuterImpl* pExecuter;
22
+
23
+		//Pointer to next THNODE
24
+		THNODE * pNext;
25
+	} THNODE;
26
+
27
+	//This is the pointer to the the thread (instance of CWinThread) which is
28
+	//responsible for observing and assigning the jobs to the free executer threads.
29
+	pthread_t pid;
30
+
31
+	//CriticalSection object, used for synchronized access of shared resources
32
+	//between the thread.
33
+	//CCriticalSection m_cs;
34
+
35
+	//This is the link list to maintain the priority queue of jobs.
36
+	std::vector<JobI* > m_jobQList;
37
+
38
+	//This method deletes a job executer. This method is not required to be used by the user. This is only for the use of the implementation of the multithreaded job queue.
39
+	void deleteJobExecuter(JobExecuterImpl *pEx);
40
+
41
+	//The setMaxNoOfExecuter method sets the maximum number of executer. If the user increases
42
+	//the maximum number of executer then the multithreaded job queue will create more
43
+	//threads to execute more jobs parallely. If the user decreases the max number of
44
+	//executers then the job queue brings down the number of executer. The bringing
45
+	//down process may not be immediate if all the executers are busy in processing.
46
+	//In such a case the number will come down as soon as some jobs gets finished.
47
+	void setMaxNoOfExecuter(int value);
48
+
49
+	//This method adds a CJobExecuter to the Job executer link list. This method
50
+	//is not required to be called by the user, this is only for the use of the
51
+	//implementation of the multithreaded job queue
52
+	void addJobExecuter(JobExecuterImpl *pEx);
53
+
54
+	//This method returns a free Job Executer. This method is not required to be
55
+	//called or used by the user. This is only for the implementation of the
56
+	//multithreaded job queue.
57
+	JobExecuterImpl* getJobExecuter();
58
+
59
+	//This method adds a Job Executer to the free job executer list. This method
60
+	//is not required to be used by the user, this is only for the use of the
61
+	//implementation of the multithreaded job queue.
62
+	void addFreeJobExecuter(JobExecuterImpl *pEx);
63
+
64
+	//This method adds a job to the job queue. The job is passed as the parameter.
65
+	void addJob(JobI *pJob);
66
+
67
+	//This method returns the maximum number allowed executer threads.
68
+	int getMaxNoOfExecuter();
69
+
70
+	//This method returns the number of executer present at any instance of time.
71
+	int getNoOfExecuter();
72
+
73
+	//This is the static thread function. This function is not to be used by the user.
74
+	//This function is used to create the observer thread.
75
+	static void* JobObserverThreadFunction(void*);
76
+
77
+	//This pauses the Multithreaded job queue, so that no new job gets processed.
78
+	//But the user can add new jobs to the job queue. The jobs will be processed
79
+	//when the user again resumes. But this does not pauses currently running jobs.
80
+	void pause();
81
+
82
+	//This resumes the Multithreaded job queue, after resume all the pending
83
+	//jobs will be processed.
84
+	void resume();
85
+
86
+	void start();
87
+
88
+	MThreadedJobQImpl();virtual ~MThreadedJobQImpl();
89
+
90
+private:
91
+	//The BOOL attribute to state whether the observer thread should process or
92
+	//not the new jobs.
93
+	bool m_pause;
94
+
95
+	//This int attribute represent the maximum limit of the executers. At any
96
+	//instance of time the total number of free , and busy executer threads all
97
+	//together should not exceed this number.
98
+	int m_MaxNoOfExecuter;
99
+
100
+	//This int attribute is to maintain the number of executer that are present
101
+	//at a particular instance of time to execute the Jobs.
102
+	int m_NoOfExecuter;
103
+
104
+	//This is the pointer to the head of the link list which maintains the free executer
105
+	//thread list.
106
+	THNODE* m_pFreeEList;
107
+
108
+	//This is the head of the link list that maintains all the executer thread list.
109
+	THNODE* m_pAllEList;
110
+
111
+	static pthread_mutex_t xLock;
112
+};
113
+
114
+#endif /* SERVICE_IMPL_MTHREADEDJOBQIMPL_H_ */

+ 857
- 0
service/impl/ProtocolImpl.cpp Прегледај датотеку

@@ -0,0 +1,857 @@
1
+/**
2
+ * @content:ModbusRTU组件实现文件
3
+ * @time:2016-8-23
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-8-23#V1.0#首次生成
8
+ */
9
+
10
+#include "ProtocolImpl.h"
11
+
12
+#include <cmath>
13
+#include <cstdlib>
14
+#include <vector>
15
+#include <sstream>
16
+#include <stdexcept>
17
+#include <iostream>
18
+
19
+
20
+#include "../../common/GUID.cpp"
21
+#include "../../servicemodel/Base.h"
22
+#include "../../servicemodel/Channel.h"
23
+#include "../../servicemodel/Device.h"
24
+#include "../../servicemodel/Item.h"
25
+#include "../../servicemodel/Packet.h"
26
+
27
+using namespace std;
28
+bool ProtocolImpl::hasInit = false;
29
+
30
+uint8_t ProtocolImpl::retBigEndian(uint32_t value, int offset)
31
+{
32
+	uint8_t ret = 0;
33
+	ret = (value >> offset) & 0xFF;
34
+	return ret;
35
+}
36
+int ProtocolImpl::getRegAddrMax(Packet *ppacket, Item *pitem)
37
+{
38
+	std::string sParaRegAddr;
39
+	int iParaRegAddr;
40
+	int maxRegAddr = -1;
41
+	//Base& base = pitem->getBase();
42
+	std::vector<Item*> items = ppacket->getVitem();
43
+	for (size_t i = 0; i < items.size(); ++i)    //遍历容器中的所有元素
44
+	{
45
+		sParaRegAddr = items[i]->getBase().getParam("起始地址");
46
+		iParaRegAddr = strtol(sParaRegAddr.c_str(), NULL, HEX);
47
+		if (iParaRegAddr > maxRegAddr)  //更新寄存器数量最大值
48
+		{
49
+			maxRegAddr = iParaRegAddr;
50
+		}
51
+		else
52
+		{
53
+
54
+		}
55
+	}
56
+	log_i("最大的起始地址:0x%x", maxRegAddr);
57
+	return maxRegAddr;
58
+}
59
+
60
+int ProtocolImpl::getRegAddrMin(Packet *ppacket, Item *pitem)
61
+{
62
+	std::string sMinRegAddr;
63
+	int iMinRegAddr = 0;
64
+	std::string sParaRegAddr;
65
+	int iParaRegAddr;
66
+	std::vector<Item*> items = ppacket->getVitem();
67
+	log_i("Items size: %zu", items.size());
68
+	sMinRegAddr = items[0]->getBase().getParam("起始地址");
69
+	iMinRegAddr = strtol(sMinRegAddr.c_str(), NULL, HEX);
70
+	log_i("Initial minimum register address value: 0x%x", iMinRegAddr);
71
+	for (size_t i = 0; i < items.size(); ++i)
72
+	{
73
+		log_i("Processing item %zu", i);
74
+		sParaRegAddr = items[i]->getBase().getParam("起始地址");
75
+		iParaRegAddr = strtol(sParaRegAddr.c_str(), NULL, HEX);
76
+		if (iParaRegAddr < iMinRegAddr)
77
+		{
78
+			iMinRegAddr = iParaRegAddr;
79
+		}
80
+	}
81
+	log_i("最小的寄存器起始地址:0x%x", iMinRegAddr);
82
+
83
+	return iMinRegAddr;
84
+}
85
+int ProtocolImpl::retStateResponse(Packet *ppacket, Item *pitem, const int len)
86
+{
87
+	int maxRegAddr = -1;
88
+	int minRegAddr = 0;
89
+	int regNum = 0;
90
+	int datasLen = 0;
91
+	maxRegAddr = getRegAddrMax(ppacket, pitem);
92
+	minRegAddr = getRegAddrMin(ppacket, pitem);
93
+	regNum = maxRegAddr - minRegAddr + 1;
94
+	log_i("reg:%d", regNum);
95
+	datasLen = getRealValidLen(regNum);
96
+	log_i("最大寄存器地址:0x%x,最小寄存器数量:0x%x,寄存器个数:0x%x,数据长度:%d,合法的数据长度=%d", maxRegAddr,
97
+			minRegAddr, regNum, datasLen, len);
98
+	if (len >= datasLen)
99
+	{
100
+		return S_OK;
101
+	}
102
+	else
103
+	{
104
+		return S_FALSE;
105
+	}
106
+
107
+	return S_FALSE;
108
+}
109
+
110
+int ProtocolImpl::getRealValidLen(int maxRegNum)
111
+{
112
+	int len = 0;
113
+	if (maxRegNum <= 4 && maxRegNum > 0)
114
+	{
115
+		len = 4 + 2 * maxRegNum;
116
+		log_i("寄存器数量小于等于4个,计算得出合法数据长度:%d", len);
117
+	}
118
+	else
119
+	{
120
+		if (maxRegNum % 4 == 0)
121
+		{
122
+			len = 12 * (maxRegNum / 4);
123
+			log_i("寄存器请求数量:%d,回复帧长度:%d",maxRegNum,len);
124
+		}
125
+		else
126
+		{
127
+			len = 4*((maxRegNum / 4) +1) + (maxRegNum *2);   //帧数据长度+寄存器长度
128
+			log_i("寄存器请求数量:%d,回复帧长度:%d",maxRegNum,len);
129
+		}
130
+	}
131
+	return len;
132
+}
133
+int ProtocolImpl::getRealFrame(PBYTE pbuf, int count)
134
+{
135
+	PBYTE ptemp = pbuf;
136
+
137
+	int id = (((ptemp[0 + count] << 24) & 0xff000000)
138
+			| ((ptemp[1 + count] << 16) & 0x00ff0000)
139
+			| ((ptemp[2 + count] << 8) & 0x0000ff00)
140
+			| ((ptemp[3 + count]) & 0x000000ff));
141
+	log_i("帧id:0x%x", id);
142
+
143
+	return id;
144
+
145
+}
146
+
147
+std::map<int, int> ProtocolImpl::handleDataLess(PBYTE pbuf,int len,int regNum,int datasLen)
148
+{
149
+	int iPbufId;
150
+	std::map<int, int> dataSet;
151
+	iPbufId = getRealFrame(pbuf, 0);
152
+
153
+
154
+	for (int i = 0; i < regNum; i++)
155
+	{
156
+		uint16_t regValue = 0;
157
+
158
+		if (i * 2 + 4 <= datasLen)
159
+		{
160
+			regValue = (pbuf[i * 2 + 4] << 8) | pbuf[i * 2 + 5]; // 提取寄存器值
161
+			dataSet[iPbufId + i] = regValue; // 绑定到map
162
+		}
163
+		else
164
+		{
165
+			log_i(
166
+					"Data insufficient for regNum %d, setting default value 0xFFFF",
167
+					i);
168
+			// 数据不足,处理错误或默认值
169
+			regValue = 0xFFFF; // 默认值为;0xFFFF
170
+
171
+			dataSet[iPbufId + i] = regValue; // 绑定到map
172
+			log_i("Added to dataSet: addrFrame=0x%x, value=0x%x", iPbufId + i,
173
+					regValue);
174
+		}
175
+	}
176
+	for (const auto &entry : dataSet)
177
+	{
178
+		log_i("addrFrame = 0x%x, value = 0x%x", entry.first, entry.second);
179
+	}
180
+
181
+	return dataSet;
182
+}
183
+
184
+std::map<int,int> ProtocolImpl::handleDataGreater(PBYTE pbuf,int len,int regNum,int datasLen)
185
+{
186
+	int validlen = len;
187
+	int iPbufId;
188
+	std::map<int, int> dataSet;
189
+
190
+	for (int count = 0;
191
+			((count < validlen) && ((validlen - count) >= 12));
192
+			count += 12)
193
+	{
194
+		iPbufId = getRealFrame(pbuf, count);
195
+
196
+
197
+		for (int i = 0; i < 4 && regNum > 0; i++,regNum --)   // i代表第i个寄存器
198
+		{
199
+
200
+			uint16_t regValue = 0;
201
+			if (i * 2 + 4 + count <= datasLen)  //当前寄存器数量的总帧数
202
+			{
203
+				regValue = (pbuf[i * 2 + 4 + count] << 8)
204
+						| pbuf[i * 2 + 5 + count]; // 提取寄存器值
205
+				dataSet[iPbufId + i % 4] = regValue; // 绑定到map
206
+			}
207
+			else
208
+			{
209
+				// 数据不足,处理错误或默认值
210
+				regValue = 0xFFFF; // 默认值为0xFFFF
211
+				dataSet[iPbufId + i % 4] = regValue; // 绑定到map
212
+			}
213
+		}
214
+		for (const auto &entry : dataSet)
215
+		{
216
+			log_i("addrFrame = 0x%x, value = 0x%x", entry.first,
217
+					entry.second);
218
+		}
219
+
220
+	}
221
+	return dataSet;
222
+
223
+}
224
+
225
+std::map<int,int>ProtocolImpl::retDataSet(Packet *ppacket, Item *pitem,PBYTE pbuf,int len)
226
+{
227
+	std::map<int, int> dataSet; // 存储寄存器地址和值
228
+	int maxRegAddr, minRegAddr, regNum;
229
+	int datasLen = 0;
230
+	maxRegAddr = getRegAddrMax(ppacket, pitem);
231
+	minRegAddr = getRegAddrMin(ppacket, pitem);
232
+	regNum = maxRegAddr - minRegAddr + 1;
233
+	datasLen = getRealValidLen(regNum);
234
+	if (datasLen <= 12)
235
+	{
236
+		dataSet = handleDataLess(pbuf,len,regNum,datasLen);
237
+	}
238
+	else
239
+	{
240
+		dataSet = handleDataGreater(pbuf,len,regNum,datasLen);
241
+	}
242
+	return dataSet;
243
+
244
+
245
+}
246
+int ProtocolImpl::iGetItemParaConfig(Item *pitem,std::string attribute)
247
+{
248
+
249
+	Item *t_item = pitem;
250
+	Base &t_base = t_item->getBase();
251
+	string sAttribute = "";
252
+	int iAttribute = 0;
253
+
254
+	sAttribute = t_base.getParam(attribute);
255
+	log_i("%s: %s",attribute.c_str(), sAttribute.c_str());
256
+
257
+	iAttribute = strtol(sAttribute.c_str(), NULL, HEX);
258
+	log_i("retV:0x%x",iAttribute);
259
+
260
+
261
+	return iAttribute;
262
+
263
+}
264
+
265
+std::string  ProtocolImpl::sGetItemParaConfig(Item *pitem, std::string attribute)
266
+{
267
+	Item *t_item = pitem;
268
+	Base &t_base = t_item->getBase();
269
+	string sAttribute = "";
270
+	sAttribute = t_base.getParam(attribute);
271
+	log_i("%s: %s",attribute.c_str(), sAttribute.c_str());
272
+
273
+	return sAttribute;
274
+
275
+}
276
+
277
+void ProtocolImpl::setData(Item *pitem,int16_t pbuf,int receiveData,int paraData,std::string t_sDataType,std::string t_sByteOrder,string t_sBits)
278
+{
279
+	Item* t_item = pitem;
280
+	int16_t buf = pbuf;
281
+	string t_str;
282
+	char t[256];
283
+	log_i("receiveData:0x%x,paraData:0x%x",receiveData,paraData);
284
+	if(receiveData == paraData)
285
+	{
286
+		log_i("ID匹配,处理数据");
287
+		if (t_sDataType == "I")
288
+		{
289
+			log_i("数据类型为I,调用merge16函数,buf=0x%x",buf);
290
+			t_item->setValue(merge16(buf, t_sByteOrder));
291
+
292
+
293
+		}
294
+		else if (t_sDataType == "UI")
295
+		{
296
+			log_i("数据类型为UI,调用merge16函数");
297
+			t_item->setValue(merge16(buf, t_sByteOrder));
298
+		}
299
+		else if (t_sDataType == "B")
300
+		{
301
+			int index = t_sBits.find(".");
302
+			if (index != -1)
303
+			{
304
+				string t_sBitnum = t_sBits.substr(0,index);
305
+				int t_iBitnum =(int) (strtol(t_sBitnum.c_str(),NULL, 10));	//----位起始地址
306
+				int t_Bits =(int) (strtol(t_sBits.substr(index + 1).c_str(),NULL, 10));
307
+				unsigned short t_usdata =(unsigned short) (strtol(merge16_u(buf,t_sByteOrder).c_str(),NULL, 10));
308
+				unsigned short bits = 0;
309
+				for (int i = 0; i < t_Bits; i++)
310
+				{
311
+					unsigned short bit = (t_usdata >> (t_iBitnum + i))& 0x0001;
312
+					bits += bit * pow(2, i);
313
+				}
314
+				snprintf(t, 256, "%d", bits);
315
+				t_str = t;
316
+				t_item->setValue(t_str);
317
+
318
+			}
319
+
320
+		}
321
+	}
322
+
323
+
324
+}
325
+
326
+HRESULT ProtocolImpl::queryInterface(const IID &iid, void **ppv)
327
+{
328
+	if (iid == IID_IProtocol)
329
+	{
330
+		log_d( "成功返回Protocol-CANDEXN协议句柄");
331
+		*ppv = static_cast<ProtocolI*>(this);
332
+	}
333
+	else if (iid == IID_IUnknown)
334
+	{
335
+		log_d( "成功返回Protocol-CANDEXN协议IUnknown句柄");
336
+		*ppv = static_cast<IUnknown*>(this);
337
+	}
338
+	else
339
+	{
340
+		log_d( "未查询到接口");
341
+		*ppv = NULL;
342
+		return E_NOINTERFACE;
343
+	}
344
+	reinterpret_cast<IUnknown*>(*ppv)->addRef();
345
+	return S_OK;
346
+}
347
+
348
+ULONG ProtocolImpl::addRef(void)
349
+{
350
+	return ++m_cRef;
351
+}
352
+
353
+ULONG ProtocolImpl::release(void)
354
+{
355
+	if (--m_cRef == 0)
356
+	{
357
+		delete this;
358
+		return 0;
359
+	}
360
+	return m_cRef;
361
+}
362
+
363
+ULONG ProtocolImpl::getVersion()
364
+{
365
+	return VERSION;
366
+}
367
+
368
+/**
369
+ * @content:组织读数据报文
370
+ * @time:2016-9-9
371
+ * @author:Mr_zhu
372
+ * @param: pdevice(设备句柄),ppacket(包句柄),pitem(点句柄),pbuf(数据缓冲区),len(返回报文长度)
373
+ * @return: HRESULT(S_OK,S_FALSE)
374
+ * @decribe
375
+ * 1#2016-9-9#V1.0#首次生成
376
+ */
377
+HRESULT ProtocolImpl::onRead(Device *pdevice, Packet *ppacket, Item *pitem,
378
+		PBYTE pbuf, int &len)
379
+{
380
+	log_i("onRead");
381
+
382
+
383
+
384
+
385
+	if (ppacket->getVitem().size() == 0)
386
+	{
387
+		return S_FALSE;
388
+	}
389
+
390
+	pdevice->getBase().setRwstate(READ_WAIT);	//----设置设备状态
391
+
392
+	std::string sParaId;
393
+	int iParaId;
394
+	Base &t_base = ppacket->getVitem().at(0)->getBase();
395
+	sParaId = t_base.getParam("功能码");
396
+	log_i("Parameter ID: %s", sParaId.c_str());
397
+	iParaId = strtol(sParaId.c_str(), NULL, HEX);
398
+	log_i("Parameter ID: %s", sParaId.c_str());
399
+	log_i("Converted Parameter ID: 0x%x", iParaId);
400
+	int frameFuncCode  = (iParaId & 0x070000);
401
+	log_i("frameFuncCode = 0x%x",frameFuncCode);
402
+	if (ppacket == nullptr || pitem == nullptr)
403
+	{
404
+		log_i("Invalid packet or item");
405
+		return S_FALSE;
406
+	}
407
+	string t_saddr;
408
+	t_saddr = pdevice->getBase().getParam("站地址");
409
+	int t_iaddr = 0;
410
+	t_iaddr = strtol(t_saddr.c_str(), NULL, HEX);
411
+	log_i("stationAddr = %d",t_iaddr);
412
+	iParaId |=  (t_iaddr << 19);
413
+	log_i("onread -addStation-id = 0x%x",iParaId);
414
+
415
+    //判断寄存器是读寄存器
416
+	if(frameFuncCode == 0x030000)
417
+	{
418
+		int maxRegAddr = getRegAddrMax(ppacket, pitem);
419
+		int minRegAddr = getRegAddrMin(ppacket, pitem);
420
+		log_i("MaxRegAddr: 0x%x, MinRegAddr: 0x%x", maxRegAddr, minRegAddr);
421
+
422
+		if (maxRegAddr < minRegAddr)
423
+		{
424
+			log_i("Invalid register address range");
425
+			return S_FALSE;
426
+		}
427
+		int regNum = maxRegAddr - minRegAddr + 1;
428
+
429
+		pbuf[0] = retBigEndian(iParaId + minRegAddr, 24);
430
+		pbuf[1] = retBigEndian(iParaId + minRegAddr, 16);
431
+		pbuf[2] = retBigEndian(iParaId + minRegAddr, 8);
432
+		pbuf[3] = retBigEndian(iParaId + minRegAddr, 0);
433
+		pbuf[4] = retBigEndian(regNum, 8);
434
+		pbuf[5] = retBigEndian(regNum, 0);
435
+		len = 6;
436
+
437
+		if (pbuf == nullptr)
438
+		{
439
+			log_i("pbuf is null");
440
+			return S_FALSE;
441
+		}
442
+		for (int i = 0; i < 6; i++)
443
+		{
444
+			log_i("onRead-读数据:pbuf[%d]:0x%x", i, pbuf[i]);
445
+		}
446
+	}
447
+
448
+	Channel *pC = pdevice->getParent();
449
+	log_i("Channel pointer: %p", pC);
450
+	if (pC == nullptr)
451
+	{
452
+		log_i("Channel pointer is null");
453
+		return S_FALSE;
454
+	}
455
+	if (pC != NULL)
456
+	{
457
+		if (m_tmpItems.count(pC->getBase().getObjid().toString()) == 0)
458
+		{
459
+			log_i("Temporary items not found for Channel ID: %s",
460
+					pC->getBase().getObjid().toString().c_str());
461
+			int ccount = pC->getDeviceCount();
462
+			log_i("Channel device count: %d", ccount);
463
+			std::multimap<int, Item*> tmpItems;
464
+			for (int i = 0; i < ccount; i++)
465
+			{
466
+
467
+				for (size_t j = 0;
468
+						j < pC->getVDevice().at(i)->getVitem().size(); j++)
469
+				{
470
+					string t_sId;
471
+					Base &t_base =
472
+							pC->getVDevice().at(i)->getVitem().at(j)->getBase();
473
+					t_sId = t_base.getParam("写功能码");
474
+					log_i("写功能码: %s", t_sId.c_str());
475
+					int t_iId = 0;
476
+					t_iId = strtol(t_sId.c_str(), NULL, HEX);	//----获取帧ID
477
+					log_i("功能码转换为整数: 0x%x", t_iId);
478
+					string t_stype;
479
+					t_stype = t_base.getParam("帧类型");
480
+					log_i("帧类型: %s", t_stype.c_str());
481
+
482
+					if (t_stype == "1")
483
+					{
484
+						t_iId |= 0x80000000;
485
+						log_i("帧类型为1,功能码更新为: 0x%x", t_iId);
486
+					}
487
+
488
+					string sStartAddr;
489
+					//sStartAddr = pC->getVDevice().at(i)->getBase().getParam("起始地址");
490
+					sStartAddr = t_base.getParam("起始地址");
491
+					log_i("起始地址 =%s", sStartAddr.c_str());
492
+
493
+					int iStartAddr = 0;
494
+					iStartAddr = strtol(sStartAddr.c_str(), NULL, HEX);
495
+					log_i("起始地址转换为整数: 0x%x", iStartAddr);
496
+					t_iId += iStartAddr;
497
+					string t_saddr;
498
+					t_saddr = pC->getVDevice().at(i)->getBase().getParam("站地址");
499
+					int t_iaddr = 0;
500
+					t_iaddr = strtol(t_saddr.c_str(), NULL, HEX);
501
+					t_iId |=  (t_iaddr << 19);
502
+					tmpItems.insert(
503
+							make_pair(t_iId,
504
+									pC->getVDevice().at(i)->getVitem().at(j)));
505
+					log_i("插入临时条目: ID=0x%x", t_iId);
506
+				}
507
+			}
508
+
509
+			m_tmpItems.insert(
510
+					make_pair(pC->getBase().getObjid().toString(), tmpItems));
511
+		}
512
+		else
513
+		{
514
+			log_i("Temporary items already exist for Channel ID: %s",
515
+					pC->getBase().getObjid().toString().c_str());
516
+		}
517
+	}
518
+
519
+	return S_OK;
520
+}
521
+
522
+/**
523
+ * @content:组织写数据报文
524
+ * @time:2016-9-9
525
+ * @author:Mr_zhu
526
+ * @param: pdevice(设备句柄),ppacket(包句柄),pitem(点句柄),pbuf(数据缓冲区),len(返回报文长度)
527
+ * @param: swritebuf(待写字符串),writelen(待写数据长度)
528
+ * @return: HRESULT(S_OK,S_FALSE)
529
+ * @decribe
530
+ * 1#2016-9-9#V1.0#首次生成
531
+ */
532
+HRESULT ProtocolImpl::onWrite(Device *pdevice, Packet *ppacket, Item *pitem,
533
+		PBYTE pbuf, int &len, string swritebuf, const unsigned int writelen)
534
+{
535
+	log_i("onWrite");
536
+	int t_len = 0;
537
+
538
+	Base &base = pitem->getBase();
539
+	string t_sRWType;
540
+	t_sRWType = base.getParam("读写类型");	//----获取点读写类型
541
+	if (t_sRWType == "RO")	//----只读
542
+	{
543
+		log_w("%s, 对只读点进行非法写操作,点信息(UUID-%s,名称-%s)",
544
+				pdevice->getBase().getName().c_str(),
545
+				base.getObjid().toString().c_str(), base.getName().c_str());
546
+		return S_FALSE;
547
+	}
548
+
549
+	string t_sFuncCode;
550
+	t_sFuncCode = base.getParam("功能码");
551
+	int t_iFuncCode = 0;
552
+	t_iFuncCode = strtol(t_sFuncCode.c_str(), NULL, HEX);	//----获取帧ID
553
+
554
+	string t_sStartAddr;
555
+	int t_iStartAddr = 0;	//----起始地址
556
+	t_sStartAddr = base.getParam("起始地址");
557
+	t_iStartAddr = strtol(t_sStartAddr.c_str(), NULL, 16);
558
+	t_iFuncCode += t_iStartAddr;
559
+	string t_saddr;
560
+	t_saddr = pdevice->getBase().getParam("站地址");
561
+
562
+	int t_iaddr = 0;
563
+	t_iaddr = strtol(t_saddr.c_str(), NULL, HEX);
564
+	t_iFuncCode |=  (t_iaddr << 19);
565
+
566
+
567
+	*(pbuf + (t_len++)) = HHByte(t_iFuncCode);
568
+	*(pbuf + (t_len++)) = HLByte(t_iFuncCode);
569
+	*(pbuf + (t_len++)) = LHByte(t_iFuncCode);
570
+	*(pbuf + (t_len++)) = LLByte(t_iFuncCode);	//----发送帧ID
571
+	if (ppacket != NULL && pdevice != NULL && pitem != NULL)
572
+	{
573
+		struct candata t_data =
574
+		//{ 0, 0, 0, 0, 0, 0, 0, 0 };
575
+				{ 0, 0 };
576
+		if (m_tmpwritedata.count(t_sFuncCode) > 0)
577
+		{
578
+			t_data = m_tmpwritedata.find(t_sFuncCode)->second;
579
+		}
580
+
581
+		*(pbuf + (t_len++)) = t_data.data0 & 0x00ff;
582
+		*(pbuf + (t_len++)) = t_data.data1 & 0x00ff;
583
+//		*(pbuf + (t_len++)) = t_data.data2 & 0x00ff;
584
+//		*(pbuf + (t_len++)) = t_data.data3 & 0x00ff;
585
+//		*(pbuf + (t_len++)) = t_data.data4 & 0x00ff;
586
+//		*(pbuf + (t_len++)) = t_data.data5 & 0x00ff;
587
+//		*(pbuf + (t_len++)) = t_data.data6 & 0x00ff;
588
+//		*(pbuf + (t_len++)) = t_data.data7 & 0x00ff;
589
+
590
+		string t_sDataType;	//----数据类型
591
+		t_sDataType = base.getParam("数据类型");
592
+
593
+		string t_sByteOrder;
594
+		t_sByteOrder = base.getParam("字节序");
595
+
596
+		if (t_sDataType == "I" || t_sDataType == "UI")
597
+		{
598
+			long int value = 0;
599
+			value = strtol(swritebuf.c_str(), NULL, 10);
600
+			if (t_sByteOrder == "BA")
601
+			{
602
+				pbuf[4] = HByte(value);
603
+				pbuf[5] = LByte(value);
604
+			}
605
+			else if (t_sByteOrder == "AB")
606
+			{
607
+				pbuf[4] = LByte(value);
608
+				pbuf[5] = HByte(value);
609
+			}
610
+		}
611
+	}
612
+
613
+	len = 6;
614
+
615
+	struct candata data;
616
+	data.data0 = pbuf[4] & 0x00ff;
617
+	data.data1 = pbuf[5] & 0x00ff;
618
+//	data.data2 = pbuf[6] & 0x00ff;
619
+//	data.data3 = pbuf[7] & 0x00ff;
620
+//	data.data4 = pbuf[8] & 0x00ff;
621
+//	data.data5 = pbuf[9] & 0x00ff;
622
+//	data.data6 = pbuf[10] & 0x00ff;
623
+//	data.data7 = pbuf[11] & 0x00ff;
624
+
625
+	std::string sbuf;
626
+	for (int i = 0; i < 12; i++)
627
+	{
628
+		char str[10];
629
+		snprintf(str, 10, "%x", pbuf[i]);
630
+		sbuf = sbuf + str;
631
+		if (i != (12 - 1))
632
+		{
633
+			sbuf = sbuf + ",";
634
+		}
635
+	}
636
+	log_i( "待发送数据为: %s", sbuf.c_str());
637
+
638
+	log_i( "%%x, %x", data.data0, data.data1);
639
+	m_tmpwritedata[t_sFuncCode] = data;
640
+
641
+	pitem->setValue(swritebuf);
642
+
643
+//	pdevice->getBase().setRwstate(WRITE_O);
644
+	pdevice->getBase().setRwstate(WRITE_WAIT);
645
+	return S_OK;
646
+}
647
+
648
+/**
649
+ * @content:判断回复数据是否接收完成
650
+ * @time:2016-9-9
651
+ * @author:Mr_zhu
652
+ * @param: pdevice(设备句柄),ppacket(包句柄),pitem(点句柄),pbuf(数据缓冲区),len(返回报文长度)
653
+ * @return: HRESULT(S_OK,S_FALSE)
654
+ * @decribe
655
+ * 1#2016-9-9#V1.0#首次生成
656
+ */
657
+HRESULT ProtocolImpl::isResponseOK(Device *pdevice, Packet *ppacket,
658
+		Item *pitem, PBYTE pbuf, const int len)
659
+{
660
+	log_i("isResponseOk");
661
+	int ret;
662
+
663
+	switch (pdevice->getBase().getRwstate())
664
+	{
665
+	case READ_O:
666
+	case WRITE_WAIT:
667
+	case READ_WAIT:
668
+		ret = retStateResponse(ppacket, pitem, len);
669
+		log_i("isResponseOK返回值:%d", ret);
670
+		if (ret == S_OK)
671
+		{
672
+			return S_OK;
673
+		}
674
+		else
675
+		{
676
+			if (ret == S_FALSE)
677
+			{
678
+				return S_FALSE;
679
+			}
680
+		}
681
+		return S_FALSE;
682
+	case WRITE_O:
683
+	//case WRITE_WAIT:
684
+
685
+		return S_OK;
686
+	}
687
+
688
+	return S_FALSE;
689
+
690
+}
691
+
692
+/**
693
+ * @content:解析数据
694
+ * @time:2016-9-9
695
+ * @author:Mr_zhu
696
+ * @param: pdevice(设备句柄),ppacket(包句柄),pitem(点句柄),pbuf(数据缓冲区),len(返回报文长度),deletelen(待删除数据长度)
697
+ * @return: HRESULT(S_OK,S_FALSE)
698
+ * @decribe
699
+ * 1#2016-9-9#V1.0#首次生成
700
+ */
701
+HRESULT ProtocolImpl::onResponse(Device *pdevice, Packet *ppacket, Item *pitem,
702
+		PBYTE pbuf, const int len, int &deletelen)
703
+{
704
+
705
+	log_i("onResponse");
706
+	int validlen = len;
707
+	int t_iRWState = pdevice->getBase().getRwstate();	//----设备读写状态
708
+	Base *pbase = new Base();
709
+	Base &base = *pbase;
710
+
711
+	std::vector<Item*> items = ppacket->getVitem();
712
+	std::map<int, int> dataSet; // 存储寄存器地址和值
713
+	int id;
714
+	int16_t buf;
715
+
716
+	Channel *pC = pdevice->getParent();
717
+	if (pC == NULL)
718
+	{
719
+		log_e("%s, 父通道为空, 无法进行数据解析", pdevice->getBase().getName().c_str());
720
+		return S_FALSE;
721
+	}
722
+	switch (t_iRWState)
723
+	{
724
+	case READ_O:
725
+	case READ_WAIT:
726
+	case WRITE_WAIT:
727
+		log_i("WRITE_WAIT");
728
+		if (validlen >= 6)
729
+		{
730
+			dataSet=retDataSet(ppacket, pitem,pbuf,len);
731
+			log_i("pbuf[4]= 0x%x,pbuf[5] = 0x%x",pbuf[4],pbuf[5]);
732
+
733
+			for (const auto &entry : dataSet)
734
+			{
735
+				log_i("addrFrame = 0x%x, value = 0x%x", entry.first,
736
+						entry.second);
737
+			}
738
+			for (const auto &dataPair : dataSet)
739
+			{
740
+				log_i("addData.size=%d", dataSet.size());
741
+				id = dataPair.first;
742
+
743
+				id = (0x7fffffff) & id;
744
+				buf = dataPair.second;
745
+				log_i("dataPair.second =0x%x",buf);
746
+
747
+
748
+				//buf = (PBYTE) &dataPair.second;
749
+				//log_i("buf[0] =0x%x,buf[1] =0x%x",buf[0],buf[1]);
750
+
751
+
752
+				log_i("Processing data pair with ID: 0x%x", id);
753
+
754
+				if (m_tmpItems.count(pC->getBase().getObjid().toString()) > 0)
755
+				{
756
+
757
+					log_i("Found temporary items for Channel ID: %s",
758
+							pC->getBase().getObjid().toString().c_str());
759
+					std::multimap<int, Item*> tmpItms = m_tmpItems.find(
760
+							pC->getBase().getObjid().toString())->second; //是否有效
761
+					for (const auto &data : tmpItms)
762
+					{
763
+						log_i("缓存条目中的缓存地址:0x%x,0x%x", data.first, data.second);
764
+					}
765
+					log_i("Temporary items size: %zu", tmpItms.size());
766
+
767
+					std::multimap<int, Item*>::size_type cnt = tmpItms.count(
768
+							id);
769
+					log_i("Number of items with ID 0x%x: %zu", id, cnt);
770
+					std::multimap<int, Item*>::iterator iter = tmpItms.find(id);
771
+					if (iter != tmpItms.end())
772
+					{
773
+						for (; cnt > 0; cnt--, iter++)
774
+						{
775
+							log_i("Processing item %zu for ID 0x%x", cnt, id);
776
+							Item *t_item = iter->second;
777
+							//Device *ptdevice = (Device*) (t_item->getParent());
778
+
779
+							if (t_item != NULL && pdevice != NULL)
780
+							{
781
+								log_i("Item and Device are valid");
782
+								int iId = iGetItemParaConfig(t_item,"写功能码");
783
+								int iStartAddr = iGetItemParaConfig(t_item,"起始地址");
784
+								string t_stype = sGetItemParaConfig(t_item,"帧类型");
785
+								string t_sDataType = sGetItemParaConfig(t_item,"数据类型");
786
+								string t_sByteOrder = sGetItemParaConfig(t_item,"字节序");
787
+								string t_sBits= sGetItemParaConfig(t_item ,"位地址");
788
+								iId += iStartAddr;
789
+
790
+								string t_saddr;
791
+								t_saddr = pdevice->getBase().getParam("站地址");
792
+								int t_iaddr = 0;
793
+								t_iaddr = strtol(t_saddr.c_str(), NULL, HEX);
794
+								log_i("t_iId = 0x%x,t_iaddr =%d,",iId,t_iaddr);
795
+
796
+								iId |=  (t_iaddr << 19);
797
+
798
+								log_i("设置的数据buf=%d,paraID = 0x%x",buf,iId);
799
+								setData(t_item, buf,id,iId,t_sDataType,t_sByteOrder,t_sBits);
800
+							}
801
+
802
+							else
803
+							{
804
+								if(t_item == NULL)
805
+								{
806
+									log_i("......item== NULL......");
807
+								}
808
+								return S_FALSE;
809
+							}
810
+						}
811
+					}
812
+				}
813
+				else
814
+				{
815
+					log_i("m_tmpItems.count(pC->getBase().getObjid().toString()) <0");
816
+					return S_FALSE;
817
+				}
818
+
819
+			}
820
+
821
+		    return S_OK;
822
+
823
+
824
+		}
825
+
826
+		if (pitem != nullptr)
827
+		{
828
+			delete pitem;
829
+		}
830
+
831
+			break;
832
+
833
+			case WRITE_O:
834
+			break;
835
+
836
+			default:
837
+			break;
838
+		}
839
+		if (pbase != NULL)
840
+		{
841
+			delete pbase;
842
+			pbase = NULL;
843
+		}
844
+
845
+		return S_OK;
846
+
847
+	}
848
+#ifdef __cplusplus
849
+	extern "C" IUnknown* CreateInstance()
850
+	{
851
+		IUnknown *pI = static_cast<ProtocolI*>(new ProtocolImpl());
852
+		pI->addRef();
853
+		return pI;
854
+	}
855
+
856
+#endif
857
+

+ 353
- 0
service/impl/ProtocolImpl.h Прегледај датотеку

@@ -0,0 +1,353 @@
1
+/**
2
+ * @content:ModbusRTU组件定义头文件
3
+ * @time:2016-8-23
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-8-23#V1.0#首次生成
8
+ */
9
+
10
+#ifndef _INCLUDE_CMPNT_MODBUSRTU_H
11
+#define _INCLUDE_CMPNT_MODBUSRTU_H
12
+
13
+#include <cstdio>
14
+#include <map>
15
+#include <string>
16
+
17
+#include "../../common/Type.h"
18
+#include "../ProtocolI.h"
19
+
20
+class ProtocolImpl: public ProtocolI
21
+{
22
+private:
23
+	virtual HRESULT queryInterface(const IID& iid, void** ppv);
24
+	virtual ULONG addRef();
25
+	virtual ULONG release();
26
+	virtual ULONG getVersion();
27
+
28
+	/**
29
+	 * 读数据
30
+	 */
31
+	virtual HRESULT onRead(Device* pdevice,	//----设备句柄
32
+			Packet* ppacket,	//----包句柄
33
+			Item* pitem,	//----点句柄
34
+			PBYTE pbuf,	//----数据缓冲区
35
+			int& len	//----数据长度
36
+			);
37
+
38
+	/**
39
+	 * 写数据
40
+	 */
41
+	virtual HRESULT onWrite(Device* pdevice,	//----设备句柄
42
+			Packet* ppacket,	//----包句柄
43
+			Item* pitem,	//----点句柄
44
+			PBYTE pbuf,	//----数据缓冲区
45
+			int& len,	//----数据长度
46
+			std::string swritebuf,	//----待写数据字符串
47
+			const unsigned int writelen	//----待写数据长度
48
+			);
49
+
50
+	/**
51
+	 * 判断回复数据是否完全
52
+	 */
53
+	virtual HRESULT isResponseOK(Device* pdevice,	//----设备句柄
54
+			Packet* ppacket,	//----包句柄
55
+			Item* pitem,	//----点句柄
56
+			PBYTE pbuf,	//----数据缓冲区
57
+			const int len	//----数据长度
58
+			);
59
+
60
+	/**
61
+	 * 解析数据
62
+	 */
63
+	virtual HRESULT onResponse(Device* pdevice,	//----设备句柄
64
+			Packet* ppacket,	//----包句柄
65
+			Item* pitem,	//----点句柄
66
+			PBYTE pbuf,	//----数据缓冲区
67
+			const int len,	//----数据长度
68
+			int& deletelen	//----删除数据长度
69
+			);
70
+
71
+public:
72
+	ProtocolImpl() :
73
+			m_cRef(0), m_Level(0), VERSION(100)
74
+	{
75
+		if (!hasInit)
76
+		{
77
+			initLogger();
78
+			hasInit = true;
79
+		}
80
+	}
81
+	~ProtocolImpl()
82
+	{
83
+	}
84
+private:
85
+	struct candata
86
+	{
87
+		BYTE data0;
88
+		BYTE data1;
89
+//		BYTE data2;
90
+//		BYTE data3;
91
+//		BYTE data4;
92
+//		BYTE data5;
93
+//		BYTE data6;
94
+//		BYTE data7;
95
+	};
96
+	static bool hasInit;
97
+	struct canReqData
98
+	{
99
+		BYTE data0;
100
+		BYTE data1;
101
+	};
102
+
103
+private:
104
+	volatile long m_cRef;
105
+	int m_Level;
106
+	static BYTE auchCRCHi[];
107
+	static BYTE auchCRCLo[];
108
+	std::map<std::string, struct candata> m_tmpwritedata;
109
+
110
+//	std::map<std::string, std::multimap<int, Packet*> > m_tmppackets;
111
+	std::map<std::string, std::multimap<int, Item*> > m_tmpItems;
112
+	const ULONG VERSION;
113
+	int findAddrFlag = 0;
114
+private:
115
+	unsigned short getMinStartAddr(Packet* ppacket);
116
+	unsigned short getMaxStartAddr(Packet* ppacket, unsigned short& regnum);
117
+	unsigned short getRegNum(Packet* ppacket);
118
+	unsigned short getExpectLen(Packet* ppacket);
119
+
120
+	unsigned short GetCRC(PBYTE pchMsg, unsigned short usDataLen);
121
+
122
+	uint8_t retBigEndian(uint32_t value, int offset);
123
+	int retStateResponse(Packet* ppacket,Item* pitem,const int len);
124
+	int getRealFrame (PBYTE pbuf,int count);
125
+	int getRegAddrMax(Packet* ppacket,Item* pitem);
126
+	int getRegAddrMin(Packet* ppacket,Item* pitem);
127
+	int getRealValidLen(int maxRegNum);
128
+	std::map<int,int>handleDataLess(PBYTE pbuf,int len,int regNum,int datasLen);
129
+	std::map<int,int>handleDataGreater(PBYTE pbuf,int len,int regNum,int datasLen);
130
+	std::map<int,int>retDataSet(Packet *ppacket, Item *pitem,PBYTE pbuf,int len);
131
+	int iGetItemParaConfig(Item *pitem, std::string attribute);
132
+	std::string sGetItemParaConfig(Item *pitem, std::string attribute);
133
+	void setData(Item *pitem,int16_t pbuf,int receiveData,int paraData,std::string t_sDataType,std::string t_sByteOrder,std::string t_sBits);
134
+
135
+
136
+
137
+
138
+
139
+
140
+	std::vector<uint8_t> intToBytes(int value);
141
+	inline std::string merge8(PBYTE pbuf, std::string byteorder)
142
+	{
143
+		BYTE t_sdata = 0;
144
+		char t[256];
145
+		std::string t_str;
146
+
147
+		t_sdata = pbuf[0] & 0x00ff;
148
+		snprintf(t, 256, "%d", t_sdata);
149
+		t_str = t;
150
+		return t_str;
151
+	}
152
+
153
+	inline std::string merge8_u(PBYTE pbuf, std::string byteorder)
154
+	{
155
+		unsigned char t_sdata = 0;
156
+		char t[256];
157
+		std::string t_str;
158
+
159
+		t_sdata = (unsigned char) (pbuf[0] & 0x00ff);
160
+		snprintf(t, 256, "%d", t_sdata);
161
+		t_str = t;
162
+		return t_str;
163
+	}
164
+
165
+	//inline std::string merge16(PBYTE pbuf, std::string byteorder)
166
+	inline std::string merge16(int16_t pbuf, std::string byteorder)
167
+	{
168
+		short t_sdata = 0;
169
+		char t[256];
170
+		std::string t_str;
171
+		if (byteorder == "BA")
172
+		{
173
+//			//t_sdata = ((pbuf[0] << 8) & 0xff00) | ((pbuf[1]) & 0x00ff);
174
+//			t_sdata = ((pbuf << 8) & 0xff00) | (pbuf & 0x00ff);
175
+//			snprintf(t, 256, "%d", t_sdata);
176
+//
177
+//			t_str = t;
178
+//			log_i("BA-merge16 t_str= %s",t_str.c_str());
179
+			uint8_t high_byte = static_cast<uint8_t>((pbuf >> 8) & 0xff);
180
+			uint8_t low_byte = static_cast<uint8_t>(pbuf & 0xff);
181
+			t_sdata = low_byte | (high_byte << 8) ;
182
+			snprintf(t, 256, "%d", t_sdata);
183
+
184
+			t_str = t;
185
+			log_i("BA-merge16 t_str= %s", t_str.c_str());
186
+}
187
+		else if (byteorder == "AB")
188
+		{
189
+//			t_sdata = ((pbuf << 8) & 0xff00) | (pbuf & 0x00ff);
190
+//			snprintf(t, 256, "%d", t_sdata);
191
+//			t_str = t;
192
+//			log_i("AB-merge16 t_str= %s",t_str.c_str());
193
+			uint8_t high_byte = static_cast<uint8_t>((pbuf >> 8) & 0xff);
194
+			uint8_t low_byte = static_cast<uint8_t>(pbuf & 0xff);
195
+			t_sdata = (low_byte << 8) | high_byte;
196
+			snprintf(t, 256, "%d", t_sdata);
197
+
198
+			t_str = t;
199
+			log_i("AB-merge16 t_str= %s", t_str.c_str());
200
+		}
201
+
202
+		return t_str;
203
+	}
204
+
205
+	//inline std::string merge16_u(PBYTE pbuf, std::string byteorder)
206
+	inline std::string merge16_u(int16_t pbuf, std::string byteorder)
207
+	{
208
+		unsigned short t_sdata = 0;
209
+		char t[256];
210
+		std::string t_str;
211
+		if (byteorder == "BA")
212
+		{
213
+//			t_sdata = (unsigned short) (((pbuf[0] << 8) & 0xff00) | ((pbuf[1]) & 0x00ff));
214
+			t_sdata = (unsigned short) (((pbuf << 8) & 0xff00) | ((pbuf) & 0x00ff));
215
+			snprintf(t, 256, "%d", t_sdata);
216
+			t_str = t;
217
+		}
218
+		else if (byteorder == "AB")
219
+		{
220
+//			t_sdata = (unsigned short) (((pbuf[1] << 8) & 0xff00) | ((pbuf[0]) & 0x00ff));
221
+			t_sdata = (unsigned short) (((pbuf << 8) & 0xff00) | ((pbuf) & 0x00ff));
222
+			snprintf(t, 256, "%d", t_sdata);
223
+			t_str = t;
224
+		}
225
+		return t_str;
226
+	}
227
+
228
+	inline std::string merge32(PBYTE pbuf, std::string byteorder)
229
+	{
230
+		int t_idata = 0;
231
+		char t[256];
232
+		std::string t_str;
233
+		if (byteorder == "BADC")
234
+		{
235
+			t_idata = ((pbuf[0] << 8) & 0x0000ff00) | ((pbuf[1]) & 0x000000ff) | ((pbuf[2] << 24) & 0xff000000) | ((pbuf[3] << 16) & 0x00ff0000);
236
+			snprintf(t, 256, "%d", t_idata);
237
+			t_str = t;
238
+		}
239
+		else if (byteorder == "DCBA")
240
+		{
241
+			t_idata = ((pbuf[0] << 24) & 0xff000000) | ((pbuf[1] << 16) & 0x00ff0000) | ((pbuf[2] << 8) & 0x0000ff00) | ((pbuf[3]) & 0x000000ff);
242
+			snprintf(t, 256, "%d", t_idata);
243
+			t_str = t;
244
+		}
245
+		else if (byteorder == "ABCD")
246
+		{
247
+			t_idata = ((pbuf[0]) & 0x000000ff) | ((pbuf[1] << 8) & 0x0000ff00) | ((pbuf[2] << 16) & 0x00ff0000) | ((pbuf[3] << 24) & 0xff000000);
248
+			snprintf(t, 256, "%d", t_idata);
249
+			t_str = t;
250
+		}
251
+		else if (byteorder == "CDAB")
252
+		{
253
+			t_idata = ((pbuf[0] << 16) & 0x00ff0000) | ((pbuf[1] << 24) & 0xff000000) | ((pbuf[2]) & 0x000000ff) | ((pbuf[3] << 8) & 0x0000ff00);
254
+			snprintf(t, 256, "%d", t_idata);
255
+			t_str = t;
256
+		}
257
+		else
258
+		{
259
+
260
+		}
261
+		return t_str;
262
+	}
263
+
264
+	inline std::string merge32_u(PBYTE pbuf, std::string byteorder)
265
+	{
266
+		unsigned int t_idata = 0;
267
+		char t[256];
268
+		std::string t_str;
269
+		if (byteorder == "BADC")
270
+		{
271
+			t_idata =
272
+					(unsigned int) (((pbuf[0] << 8) & 0x0000ff00) | ((pbuf[1]) & 0x000000ff) | ((pbuf[2] << 24) & 0xff000000) | ((pbuf[3] << 16) & 0x00ff0000));
273
+			snprintf(t, 256, "%d", t_idata);
274
+			t_str = t;
275
+		}
276
+		else if (byteorder == "DCBA")
277
+		{
278
+			t_idata =
279
+					(unsigned int) (((pbuf[0] << 24) & 0xff000000) | ((pbuf[1] << 16) & 0x00ff0000) | ((pbuf[2] << 8) & 0x0000ff00) | ((pbuf[3]) & 0x000000ff));
280
+			snprintf(t, 256, "%d", t_idata);
281
+			t_str = t;
282
+		}
283
+		else if (byteorder == "ABCD")
284
+		{
285
+			t_idata =
286
+					(unsigned int) (((pbuf[0]) & 0x000000ff) | ((pbuf[1] << 8) & 0x0000ff00) | ((pbuf[2] << 16) & 0x00ff0000) | ((pbuf[3] << 24) & 0xff000000));
287
+			snprintf(t, 256, "%d", t_idata);
288
+			t_str = t;
289
+		}
290
+		else if (byteorder == "CDAB")
291
+		{
292
+			t_idata =
293
+					(unsigned int) (((pbuf[0] << 16) & 0x00ff0000) | ((pbuf[1] << 24) & 0xff000000) | ((pbuf[2]) & 0x000000ff) | ((pbuf[3] << 8) & 0x0000ff00));
294
+			snprintf(t, 256, "%d", t_idata);
295
+			t_str = t;
296
+		}
297
+		else
298
+		{
299
+
300
+		}
301
+		return t_str;
302
+	}
303
+
304
+	float intbitstofloat(int bits)
305
+	{
306
+		union
307
+		{
308
+			int i;
309
+			float f;
310
+		} u;
311
+		u.i = bits;
312
+
313
+		return u.f;
314
+	}
315
+
316
+	int floatbitstoint(float bits)
317
+	{
318
+		union
319
+		{
320
+			int i;
321
+			float f;
322
+		} u;
323
+		u.f = bits;
324
+
325
+		return u.i;
326
+	}
327
+
328
+	inline void initLogger()
329
+	{
330
+		/**
331
+		 * LOG系统初始化
332
+		 */
333
+		/* close printf buffer */
334
+		setbuf(stdout, NULL);
335
+		/* initialize EasyLogger */
336
+		elog_init();
337
+		/* set EasyLogger log format */
338
+		elog_set_fmt(ELOG_LVL_ASSERT, ELOG_FMT_ALL);
339
+		elog_set_fmt(ELOG_LVL_ERROR, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
340
+		elog_set_fmt(ELOG_LVL_WARN, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
341
+		elog_set_fmt(ELOG_LVL_INFO, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
342
+		elog_set_fmt(ELOG_LVL_DEBUG, ELOG_FMT_ALL & ~ELOG_FMT_FUNC);
343
+		elog_set_fmt(ELOG_LVL_VERBOSE, ELOG_FMT_ALL & ~ELOG_FMT_FUNC);
344
+#ifdef ELOG_COLOR_ENABLE
345
+		elog_set_text_color_enabled(true);
346
+#endif
347
+		/* start EasyLogger */
348
+		elog_start();
349
+	}
350
+};
351
+
352
+#endif
353
+

+ 247
- 0
servicemodel/Base.h Прегледај датотеку

@@ -0,0 +1,247 @@
1
+/*
2
+ * Base.h
3
+ *
4
+ *  Created on: 2016年11月15日
5
+ *      Author: nego
6
+ */
7
+
8
+#ifndef SERVICEMODEL_BASE_H_
9
+#define SERVICEMODEL_BASE_H_
10
+
11
+#include <map>
12
+#include <string>
13
+#include <utility>
14
+
15
+#include "../common/Type.h"
16
+
17
+class Base {
18
+public:
19
+
20
+	enum QUALITY {
21
+		GOOD = 0, BAD
22
+	};
23
+	enum RUNSTATE {
24
+		IDLEE = 0, TIMING, TIMEOUT, FAULT
25
+	};
26
+
27
+	Base() :
28
+		m_rwstate(-1), m_priority(-1), m_readcount(0), m_readbackcount(0), m_writecount(
29
+					0), m_writebackcount(0), m_quality(GOOD), m_runstate(TIMING),
30
+					m_rdatimeoutcount(0),m_rreadretrycount(0),m_rwriteretrycount(0),
31
+					m_rfaultcount(0){
32
+		xLock = PTHREAD_MUTEX_INITIALIZER;
33
+	}
34
+	virtual ~Base() {
35
+	}
36
+
37
+	const std::string& getName() const {
38
+		return m_name;
39
+	}
40
+
41
+	void setName(const std::string& name) {
42
+		if(!name.empty()){
43
+			this->m_name = name;
44
+		}
45
+	}
46
+
47
+	OBJID& getObjid() {
48
+		return m_objid;
49
+	}
50
+
51
+	void setObjid(const OBJID& objid) {
52
+		this->m_objid = objid;
53
+	}
54
+
55
+	std::map<std::string, std::string>& getParams() {
56
+		return m_mparams;
57
+	}
58
+
59
+	void setParams(const std::map<std::string, std::string>& params) {
60
+		this->m_mparams = params;
61
+	}
62
+
63
+	HRESULT setParam(const std::string key, const std::string value) {
64
+		getParams().insert(make_pair(key, value));
65
+		return S_OK;
66
+	}
67
+
68
+	std::string getParam(const std::string key) {
69
+		std::map<std::string, std::string>& m = getParams();
70
+		if (m.count(key) > 0) {
71
+			std::string value = m.find(key)->second;
72
+			return value;
73
+		}
74
+		return "";
75
+	}
76
+
77
+	int getPriority() const {
78
+		return m_priority;
79
+	}
80
+
81
+	void setPriority(int priority) {
82
+		this->m_priority = priority;
83
+	}
84
+
85
+	int getRwstate() const {
86
+		return m_rwstate;
87
+	}
88
+
89
+	void setRwstate(int rwstate) {
90
+		this->m_rwstate = rwstate;
91
+	}
92
+
93
+	QUALITY getQuality() const {
94
+		return m_quality;
95
+	}
96
+
97
+	void setQuality(QUALITY quality) {
98
+		this->m_quality = quality;
99
+	}
100
+
101
+	unsigned int getReadcount() const {
102
+		return m_readcount;
103
+	}
104
+
105
+	void setReadcount(unsigned int readcount) {
106
+		this->m_readcount = readcount;
107
+	}
108
+
109
+	void addReadcount() {
110
+		++this->m_readcount;
111
+	}
112
+
113
+	unsigned int getWritecount() const {
114
+		return m_writecount;
115
+	}
116
+
117
+	void setWritecount(unsigned int writecount) {
118
+		this->m_writecount = writecount;
119
+	}
120
+
121
+	void addWritecount() {
122
+		++this->m_writecount;
123
+	}
124
+
125
+	unsigned int getReadbackcount() const {
126
+		return m_readbackcount;
127
+	}
128
+
129
+	void setReadbackcount(unsigned int readbackcount) {
130
+		this->m_readbackcount = readbackcount;
131
+	}
132
+
133
+	void addReadbackcount() {
134
+		++this->m_readbackcount;
135
+	}
136
+
137
+	unsigned int getWritebackcount() const {
138
+		return m_writebackcount;
139
+	}
140
+
141
+	void setWritebackcount(unsigned int writebackcount) {
142
+		this->m_writebackcount = writebackcount;
143
+	}
144
+
145
+	void addWritebackcount() {
146
+		++this->m_writebackcount;
147
+	}
148
+
149
+	RUNSTATE getRunstate() const {
150
+		return m_runstate;
151
+	}
152
+
153
+	void setRunstate(RUNSTATE runstate) {
154
+		(void) pthread_mutex_lock(&xLock);
155
+		this->m_runstate = runstate;
156
+		(void) pthread_mutex_unlock(&xLock);
157
+	}
158
+
159
+	int getRdatimeoutcount() const {
160
+		return m_rdatimeoutcount;
161
+	}
162
+
163
+	void setRdatimeoutcount(int rdatimeoutcount) {
164
+		m_rdatimeoutcount = rdatimeoutcount;
165
+	}
166
+
167
+	void addRdatimeoutcount(int rdatimeoutcount) {
168
+		m_rdatimeoutcount += rdatimeoutcount;
169
+	}
170
+
171
+	void resetRdatimeoutcount() {
172
+		m_rdatimeoutcount = 0;
173
+	}
174
+
175
+	int getRfaultcount() const {
176
+		return m_rfaultcount;
177
+	}
178
+
179
+	void setRfaultcount(int rfaultcount) {
180
+		m_rfaultcount = rfaultcount;
181
+	}
182
+
183
+	void addRfaultcount(int rfaultcount) {
184
+		m_rfaultcount += rfaultcount;
185
+	}
186
+
187
+	void resetRfaultcount() {
188
+		m_rfaultcount = 0;
189
+	}
190
+
191
+	int getRreadretrycount() const {
192
+		return m_rreadretrycount;
193
+	}
194
+
195
+	void setRreadretrycount(int rreadretrycount) {
196
+		m_rreadretrycount = rreadretrycount;
197
+	}
198
+
199
+	void addRreadretrycount(int rreadretrycount) {
200
+		m_rreadretrycount += rreadretrycount;
201
+	}
202
+
203
+	void resetRreadretrycount() {
204
+		m_rreadretrycount = 0;
205
+	}
206
+
207
+	int getRwriteretrycount() const {
208
+		return m_rwriteretrycount;
209
+	}
210
+
211
+	void setRwriteretrycount(int rwriteretrycount) {
212
+		m_rwriteretrycount = rwriteretrycount;
213
+	}
214
+
215
+	void addRwriteretrycount(int rwriteretrycount) {
216
+		m_rwriteretrycount += rwriteretrycount;
217
+	}
218
+
219
+	void resetRwriteretrycount() {
220
+		m_rwriteretrycount = 0;
221
+	}
222
+
223
+private:
224
+	OBJID m_objid;
225
+	std::string m_name;
226
+	std::map<std::string, std::string> m_mparams;
227
+	int m_rwstate;	//----读写状态
228
+	int m_priority;	//----优先级状态
229
+
230
+	/**
231
+	 * 以下数据用于性能监视
232
+	 */
233
+	unsigned int m_readcount;	//----读计数
234
+	unsigned int m_readbackcount;	//----读回复计数
235
+	unsigned int m_writecount;	//----写计数
236
+	unsigned int m_writebackcount;	//----写回复计数
237
+	QUALITY m_quality;	//----采集质量
238
+	RUNSTATE m_runstate;	//----采集状态,处于空闲、采集、超时、故障等状态
239
+
240
+	int m_rdatimeoutcount;	//----采集超时计数
241
+	int m_rreadretrycount;	//----读重试计数
242
+	int m_rwriteretrycount;	//----写重试计数
243
+	int m_rfaultcount;	//----采集故障计数
244
+
245
+	pthread_mutex_t xLock;
246
+};
247
+#endif /* SERVICEMODEL_BASE_H_ */

+ 336
- 0
servicemodel/Channel.h Прегледај датотеку

@@ -0,0 +1,336 @@
1
+/*
2
+ * Channel.h
3
+ *
4
+ *  Created on: 2016年11月10日
5
+ *      Author: Mr_zhu
6
+ *     Content: 
7
+ */
8
+
9
+#ifndef SERVICEMODEL_CHANNEL_H_
10
+#define SERVICEMODEL_CHANNEL_H_
11
+
12
+#include <pthread.h>
13
+#include <iostream>
14
+#include <map>
15
+#include <string>
16
+#include <utility>
17
+#include <vector>
18
+
19
+#include "../common/Type.h"
20
+#include "../externservice/HardwareI.h"
21
+#include "../service/CallBackHandleI.h"
22
+#include "../service/impl/MThreadedJobQImpl.h"
23
+#include "Base.h"
24
+#include "Device.h"
25
+
26
+struct DAControlerI;
27
+
28
+struct CallBackHandleI;
29
+class MThreadedJobQImpl;
30
+class Device;
31
+
32
+class Channel
33
+{
34
+
35
+public:
36
+	enum STATE
37
+	{
38
+		R = 0, S
39
+	};
40
+
41
+public:
42
+	Channel() :
43
+			m_phw(NULL), m_DATimeout(1000), m_BaseDATime(100), m_FaultTime(10000), m_ReadRetryCount(0), m_WriteRetryCount(3), m_FaultRetryCount(3), m_pCB(NULL), isHDInitOK(
44
+					false), m_state(S), m_preadJobThread(NULL)
45
+	{
46
+		xLock = PTHREAD_MUTEX_INITIALIZER;
47
+	}
48
+	virtual ~Channel()
49
+	{
50
+		if(m_phw!=NULL)
51
+		{
52
+			delete m_phw;
53
+			m_phw = NULL;
54
+		}
55
+		if(m_pCB!=NULL)
56
+		{
57
+			delete m_pCB;
58
+			m_pCB = NULL;
59
+		}
60
+		if(m_preadJobThread!=NULL)
61
+		{
62
+			delete m_preadJobThread;
63
+			m_preadJobThread = NULL;
64
+		}
65
+	}
66
+
67
+	Base& getBase()
68
+	{
69
+		return m_base;
70
+	}
71
+
72
+	void setBase(const Base& base)
73
+	{
74
+		this->m_base = base;
75
+	}
76
+
77
+	bool isIsHdInitOk() const
78
+	{
79
+		return isHDInitOK;
80
+	}
81
+
82
+	void setIsHdInitOk(bool isHdInitOk)
83
+	{
84
+		isHDInitOK = isHdInitOk;
85
+	}
86
+
87
+	unsigned int getBaseDaTime() const
88
+	{
89
+		return m_BaseDATime;
90
+	}
91
+
92
+	void setBaseDaTime(unsigned int baseDaTime)
93
+	{
94
+		m_BaseDATime = baseDaTime;
95
+	}
96
+
97
+	const CLSID& getClsidOfHw() const
98
+	{
99
+		return m_hwguid;
100
+	}
101
+
102
+	void setClsidOfHw(const CLSID& clsidOfHw)
103
+	{
104
+		m_hwguid = clsidOfHw;
105
+	}
106
+
107
+	unsigned int getDaTimeout() const
108
+	{
109
+		return m_DATimeout;
110
+	}
111
+
112
+	void setDaTimeout(unsigned int daTimeout)
113
+	{
114
+		m_DATimeout = daTimeout;
115
+	}
116
+
117
+	CallBackHandleI* getPCb()
118
+	{
119
+		return m_pCB;
120
+	}
121
+
122
+	void setPCb(CallBackHandleI* pCb)
123
+	{
124
+		m_pCB = pCb;
125
+	}
126
+
127
+	HardwareI* getPHd()
128
+	{
129
+		return m_phw;
130
+	}
131
+
132
+	void setPHd(HardwareI* pHd)
133
+	{
134
+		m_phw = pHd;
135
+	}
136
+
137
+	const std::vector<BYTE>& getReadBuf() const
138
+	{
139
+		return m_vReadBuf;
140
+	}
141
+
142
+	void setReadBuf(const std::vector<BYTE>& readBuf)
143
+	{
144
+		m_vReadBuf = readBuf;
145
+	}
146
+
147
+	unsigned int getReadRetryCount() const
148
+	{
149
+		return m_ReadRetryCount;
150
+	}
151
+
152
+	void setReadRetryCount(unsigned int readRetryCount)
153
+	{
154
+		m_ReadRetryCount = readRetryCount;
155
+	}
156
+
157
+	std::vector<Device* >& getVDevice()
158
+	{
159
+		return m_vDevice;
160
+	}
161
+
162
+	void setVDevice(const std::vector<Device* >& vDevice)
163
+	{
164
+		m_vDevice = vDevice;
165
+	}
166
+
167
+	const std::vector<BYTE>& getWriteBuf() const
168
+	{
169
+		return m_vWriteBuf;
170
+	}
171
+
172
+	void setWriteBuf(const std::vector<BYTE>& writeBuf)
173
+	{
174
+		m_vWriteBuf = writeBuf;
175
+	}
176
+
177
+	unsigned int getWriteRetryCount() const
178
+	{
179
+		return m_WriteRetryCount;
180
+	}
181
+
182
+	void setWriteRetryCount(unsigned int writeRetryCount)
183
+	{
184
+		m_WriteRetryCount = writeRetryCount;
185
+	}
186
+
187
+	HRESULT addDevice(Device* device)
188
+	{
189
+//		bool isexist = false;
190
+//
191
+//		for (Device& d : m_vDevice) {
192
+//			if (d.isEqual(device)) {
193
+//				isexist = true;
194
+//				break;
195
+//			}
196
+//		}
197
+//		if (!isexist) {
198
+//			m_vDevice.push_back(device);
199
+//			return S_OK;
200
+//		}
201
+//		return S_FALSE;
202
+		m_vDevice.push_back(device);
203
+		return S_OK;
204
+	}
205
+
206
+	ULONG getDeviceCount()
207
+	{
208
+		return m_vDevice.size();
209
+	}
210
+
211
+	unsigned int getFaultRetryCount() const
212
+	{
213
+		return m_FaultRetryCount;
214
+	}
215
+
216
+	void setFaultRetryCount(unsigned int faultRetryCount)
217
+	{
218
+		m_FaultRetryCount = faultRetryCount;
219
+	}
220
+
221
+	unsigned int getFaultTime() const
222
+	{
223
+		return m_FaultTime;
224
+	}
225
+
226
+	void setFaultTime(unsigned int faultTime)
227
+	{
228
+		m_FaultTime = faultTime;
229
+	}
230
+
231
+	CLSID& getHwguid()
232
+	{
233
+		return m_hwguid;
234
+	}
235
+
236
+	void setHwguid(const CLSID& hwguid)
237
+	{
238
+		m_hwguid = hwguid;
239
+	}
240
+
241
+	HardwareI* getPhw()
242
+	{
243
+		return m_phw;
244
+	}
245
+
246
+	void setPhw(HardwareI* phw)
247
+	{
248
+		this->m_phw = phw;
249
+	}
250
+
251
+	STATE getState() const
252
+	{
253
+		return m_state;
254
+	}
255
+
256
+	void setState(STATE state)
257
+	{
258
+		(void) pthread_mutex_lock(&xLock);
259
+		this->m_state = state;
260
+		(void) pthread_mutex_unlock(&xLock);
261
+	}
262
+
263
+	MThreadedJobQImpl* getReadJobThread()
264
+	{
265
+		return m_preadJobThread;
266
+	}
267
+
268
+	void setReadJobThread(MThreadedJobQImpl* readJobThread)
269
+	{
270
+		m_preadJobThread = readJobThread;
271
+	}
272
+
273
+	void outInfo()
274
+	{
275
+
276
+		std::cout << "通道ID: " << m_base.getObjid().toString() << std::endl;
277
+		std::cout << "通道名称: " << m_base.getName() << std::endl;
278
+		std::cout << "通道参数: " << std::endl;
279
+		for(std::pair<const std::string,std::string>& s : m_base.getParams())
280
+		{
281
+			std::cout << s.first << " : " << s.second << std::endl;
282
+		}
283
+		std::cout << "通道读写状态: " << m_base.getRwstate() << std::endl;
284
+		std::cout << "通道优先级状态: " << m_base.getPriority() << std::endl;
285
+		std::cout << "硬件组件ID: " << m_hwguid.toString() << std::endl;
286
+		std::cout << "硬件组件句柄: " << m_phw << std::endl;
287
+		std::cout << "采集超时时间: " << m_phw << std::endl;
288
+		std::cout << "基础采集周期: " << m_phw << std::endl;
289
+		std::cout << "采集故障时间: " << m_phw << std::endl;
290
+		std::cout << "读重试次数: " << m_phw << std::endl;
291
+		std::cout << "写重试次数: " << m_phw << std::endl;
292
+		std::cout << "故障重试次数: " << m_phw << std::endl;
293
+		std::cout << "设备数: " << m_vDevice.size() << std::endl;
294
+		for(Device* & d : m_vDevice)
295
+		{
296
+			d->outInfo();
297
+		}
298
+	}
299
+
300
+	DAControlerI*& getDa()
301
+	{
302
+		return pDa;
303
+	}
304
+
305
+	void setDa(DAControlerI* da)
306
+	{
307
+		pDa = da;
308
+	}
309
+
310
+private:
311
+	CLSID m_hwguid;	//----通道组件标识符
312
+	HardwareI* m_phw;//----通道组件句柄
313
+	unsigned int m_DATimeout;
314
+	unsigned int m_BaseDATime;
315
+	unsigned int m_FaultTime;
316
+	unsigned int m_ReadRetryCount;
317
+	unsigned int m_WriteRetryCount;
318
+	unsigned int m_FaultRetryCount;
319
+	std::vector<Device* > m_vDevice;
320
+	std::vector<BYTE> m_vReadBuf;
321
+	std::vector<BYTE> m_vWriteBuf;
322
+	CallBackHandleI* m_pCB;
323
+	bool isHDInitOK;
324
+
325
+	STATE m_state;//---通道处于数据发送或者接受状态
326
+
327
+	MThreadedJobQImpl* m_preadJobThread;//----读任务线程
328
+
329
+	Base m_base;
330
+
331
+	pthread_mutex_t xLock;
332
+
333
+	DAControlerI* pDa;
334
+};
335
+
336
+#endif /* SERVICEMODEL_CHANNEL_H_ */

+ 355
- 0
servicemodel/Device.h Прегледај датотеку

@@ -0,0 +1,355 @@
1
+/*
2
+ * Device.h
3
+ *
4
+ *  Created on: 2016年11月10日
5
+ *      Author: Mr_zhu
6
+ *     Content: 
7
+ */
8
+
9
+#ifndef SERVICEMODEL_DEVICE_H_
10
+#define SERVICEMODEL_DEVICE_H_
11
+
12
+#include <string>
13
+#include <vector>
14
+
15
+#include "../common/Type.h"
16
+#include "../externservice/HardwareI.h"
17
+#include "../externservice/ParaAnalysisI.h"
18
+#include "../externservice/ProtocolI.h"
19
+#include "../externservice/SubContractI.h"
20
+#include "Base.h"
21
+#include "Item.h"
22
+#include "Packet.h"
23
+
24
+struct HardwareI;
25
+struct ParaAnalysisI;
26
+struct ProtocolI;
27
+
28
+struct SubContractI;
29
+
30
+struct IHardware;
31
+
32
+struct IParaAnalysis;
33
+struct IProtocol;
34
+
35
+class Channel;
36
+
37
+class Device {
38
+public:
39
+	Device() :
40
+			m_pptcl(NULL), m_hwtype(-1), m_hwnumber(-1), m_phw(NULL), m_ppara(
41
+			NULL), m_psubctact(
42
+			NULL), m_enable(1), m_datimer(100), m_datimeout(1000), m_dafaulttime(
43
+					3000), m_readretrycount(0), m_writeretrycount(3), m_faultcount(
44
+					3), m_parent(NULL) {
45
+
46
+	}
47
+	virtual ~Device() {
48
+//		if (m_pptcl != NULL) {
49
+//			delete m_pptcl;
50
+//			m_pptcl = NULL;
51
+//		}
52
+//		if (m_phw != NULL) {
53
+//			delete m_phw;
54
+//			m_phw = NULL;
55
+//		}
56
+//		if (m_ppara != NULL) {
57
+//			delete m_ppara;
58
+//			m_ppara = NULL;
59
+//		}
60
+//		if (m_psubctact != NULL) {
61
+//			delete m_psubctact;
62
+//			m_psubctact = NULL;
63
+//		}
64
+	}
65
+
66
+	Base& getBase() {
67
+		return m_base;
68
+	}
69
+
70
+	void setBase(const Base& base) {
71
+		this->m_base = base;
72
+	}
73
+
74
+	int getEnable() const {
75
+		return m_enable;
76
+	}
77
+
78
+	void setEnable(int enable) {
79
+		m_enable = enable;
80
+	}
81
+
82
+	CLSID& getHwguid() {
83
+		return m_hwguid;
84
+	}
85
+
86
+	void setHwguid(const CLSID& hwguid) {
87
+		m_hwguid = hwguid;
88
+	}
89
+
90
+	std::string& getHwname() {
91
+		return m_hwname;
92
+	}
93
+
94
+	void setHwname(const std::string& hwname) {
95
+		if (!hwname.empty()) {
96
+			m_hwname = hwname;
97
+		}
98
+	}
99
+
100
+	int getHwnumber() const {
101
+		return m_hwnumber;
102
+	}
103
+
104
+	void setHwnumber(int hwnumber) {
105
+		m_hwnumber = hwnumber;
106
+	}
107
+
108
+	int getHwtype() const {
109
+		return m_hwtype;
110
+	}
111
+
112
+	void setHwtype(int hwtype) {
113
+		m_hwtype = hwtype;
114
+	}
115
+
116
+	std::string& getItemtable() {
117
+		return m_itemtable;
118
+	}
119
+
120
+	void setItemtable(const std::string& itemtable) {
121
+		if (!itemtable.empty()) {
122
+			m_itemtable = itemtable;
123
+		}
124
+	}
125
+
126
+	CLSID& getParaanalysisguid() {
127
+		return m_paraanalysisguid;
128
+	}
129
+
130
+	void setParaanalysisguid(const CLSID& paraanalysisguid) {
131
+		m_paraanalysisguid = paraanalysisguid;
132
+	}
133
+
134
+	CLSID& getProtocolguid() {
135
+		return m_protocolguid;
136
+	}
137
+
138
+	void setProtocolguid(const CLSID& protocolguid) {
139
+		m_protocolguid = protocolguid;
140
+	}
141
+
142
+	const std::string& getProtocolname() const {
143
+		return m_protocolname;
144
+	}
145
+
146
+	void setProtocolname(const std::string& protocolname) {
147
+		if (!protocolname.empty()) {
148
+			m_protocolname = protocolname;
149
+		}
150
+	}
151
+
152
+	CLSID& getSubcontractguid() {
153
+		return m_subcontractguid;
154
+	}
155
+
156
+	void setSubcontractguid(const CLSID& subcontractguid) {
157
+		m_subcontractguid = subcontractguid;
158
+	}
159
+
160
+	Channel* getParent() {
161
+		return m_parent;
162
+	}
163
+
164
+	void setParent(Channel* parent) {
165
+		this->m_parent = parent;
166
+	}
167
+
168
+	HardwareI* getPhw() {
169
+		return m_phw;
170
+	}
171
+
172
+	void setPhw(HardwareI* phw) {
173
+		this->m_phw = phw;
174
+	}
175
+
176
+	ParaAnalysisI* getPpara() const {
177
+		return m_ppara;
178
+	}
179
+
180
+	void setPpara(ParaAnalysisI* ppara) {
181
+		this->m_ppara = ppara;
182
+	}
183
+
184
+	ProtocolI* getPptcl() {
185
+		return m_pptcl;
186
+	}
187
+
188
+	void setPptcl(ProtocolI* pptcl) {
189
+		this->m_pptcl = pptcl;
190
+	}
191
+
192
+	SubContractI* getPsubctact() const {
193
+		return m_psubctact;
194
+	}
195
+
196
+	void setPsubctact(SubContractI* psubctact) {
197
+		this->m_psubctact = psubctact;
198
+	}
199
+
200
+	std::vector<Packet* >& getVpacket() {
201
+		return m_vpacket;
202
+	}
203
+
204
+	void setVpacket(const std::vector<Packet* >& vpacket) {
205
+		this->m_vpacket = vpacket;
206
+	}
207
+
208
+	std::vector<Item* >& getVitem() {
209
+		return m_vitem;
210
+	}
211
+
212
+	void setVitem(const std::vector<Item* >& vitem) {
213
+		this->m_vitem = vitem;
214
+	}
215
+
216
+	HRESULT addItem(Item* item) {
217
+		bool isexist = false;
218
+
219
+		for (Item*& i : m_vitem) {
220
+			if (i->isEqual(*item)) {
221
+				isexist = true;
222
+				break;
223
+			}
224
+		}
225
+		if (!isexist) {
226
+			m_vitem.push_back(item);
227
+
228
+			return S_OK;
229
+		}
230
+		return S_FALSE;
231
+	}
232
+
233
+	HRESULT addPacket(Packet* packet) {
234
+		bool isexist = false;
235
+
236
+		for (Packet* & p : m_vpacket) {
237
+			if (p->isEqual(*packet)) {
238
+				isexist = true;
239
+				break;
240
+			}
241
+		}
242
+		if (!isexist) {
243
+			m_vpacket.push_back(packet);
244
+			return S_OK;
245
+		}
246
+		return S_FALSE;
247
+	}
248
+
249
+	ULONG getItemCount() {
250
+		return m_vitem.size();
251
+	}
252
+
253
+	ULONG getPacketCount() {
254
+		return m_vpacket.size();
255
+	}
256
+
257
+public:
258
+	bool isEqual(Device& device) {
259
+
260
+		if ((isGUIDEqual(this->m_hwguid,((device.getHwguid()))))
261
+				&& (this->m_hwname == ((device.getHwname())))
262
+				&& (this->m_hwnumber == device.getHwnumber())
263
+				&& (this->m_hwtype == device.getHwtype())) {
264
+			return true;
265
+		}
266
+
267
+		return false;
268
+	}
269
+
270
+	int getDafaulttime() const {
271
+		return m_dafaulttime;
272
+	}
273
+
274
+	void setDafaulttime(int dafaulttime) {
275
+		m_dafaulttime = dafaulttime;
276
+	}
277
+
278
+	int getDatimeout() const {
279
+		return m_datimeout;
280
+	}
281
+
282
+	void setDatimeout(int datimeout) {
283
+		m_datimeout = datimeout;
284
+	}
285
+
286
+	int getDatimer() const {
287
+		return m_datimer;
288
+	}
289
+
290
+	void setDatimer(int datimer) {
291
+		m_datimer = datimer;
292
+	}
293
+
294
+	int getFaultcount() const {
295
+		return m_faultcount;
296
+	}
297
+
298
+	void setFaultcount(int faultcount) {
299
+		m_faultcount = faultcount;
300
+	}
301
+
302
+	int getReadretrycount() const {
303
+		return m_readretrycount;
304
+	}
305
+
306
+	void setReadretrycount(int readretrycount) {
307
+		m_readretrycount = readretrycount;
308
+	}
309
+
310
+	int getWriteretrycount() const {
311
+		return m_writeretrycount;
312
+	}
313
+
314
+	void setWriteretrycount(int writeretrycount) {
315
+		m_writeretrycount = writeretrycount;
316
+	}
317
+
318
+	void outInfo() {
319
+
320
+	}
321
+
322
+private:
323
+	std::string m_protocolname;	//----设备通信协议名称
324
+	CLSID m_protocolguid;	//----设备通信协议组件标识符
325
+	ProtocolI* m_pptcl;	//----设备通信协议组件句柄
326
+
327
+	std::string m_hwname;	//----设备硬件通道名称
328
+	int m_hwtype;	//----设备硬件通道类型
329
+	int m_hwnumber;	//----设备硬件通道号
330
+	CLSID m_hwguid;	//----设备硬件通道组件标识符
331
+	HardwareI* m_phw;	//----设备硬件通道组件句柄
332
+
333
+	CLSID m_paraanalysisguid;	//----设备参数解析组件标识符
334
+	ParaAnalysisI* m_ppara;	//----设备参数分析组件句柄
335
+
336
+	CLSID m_subcontractguid;	//----设备分包参数组件标识符
337
+	SubContractI* m_psubctact;	//----设备分包组件句柄
338
+
339
+	std::string m_itemtable;	//----设备点表名称
340
+	int m_enable;	//----设备使能控制
341
+	int m_datimer;	//----采集周期
342
+	int m_datimeout;	//----采集超时时间
343
+	int m_dafaulttime;	//----采集故障恢复时间
344
+	int m_readretrycount;	//----读重试次数
345
+	int m_writeretrycount;	//----写重试次数
346
+	int m_faultcount;	//----采集故障次数
347
+
348
+	Base m_base;	//----公共参数
349
+
350
+	std::vector<Packet* > m_vpacket;	//----设备中的采集包集合
351
+	std::vector<Item* > m_vitem;	//----设备中采集点集合
352
+	Channel* m_parent;	//----父句柄
353
+};
354
+
355
+#endif /* SERVICEMODEL_DEVICE_H_ */

+ 604
- 0
servicemodel/Item.h Прегледај датотеку

@@ -0,0 +1,604 @@
1
+/*
2
+ * Item.h
3
+ *
4
+ *  Created on: 2016年11月10日
5
+ *      Author: Mr_zhu
6
+ *     Content: 
7
+ */
8
+
9
+#ifndef SERVICEMODEL_ITEM_H_
10
+#define SERVICEMODEL_ITEM_H_
11
+
12
+#include <string>
13
+
14
+#include "../common/Type.h"
15
+#include "Base.h"
16
+
17
+struct ParaAnalysisI;
18
+
19
+class Packet;
20
+
21
+class Item
22
+{
23
+public:
24
+	Item() :
25
+			m_ppara(NULL), m_index(0), m_sourcemin(0.0), m_sourcemax(0.0), m_realmin(0.0), m_realmax(0.0), m_enable(0), m_alarmenable(0), m_hisenable(0), m_histimes(
26
+					0), m_parent(NULL), m_ritem(NULL), lupdatetime(0), updatefreq(0), isFault(false), isReset(false)
27
+	{
28
+		xLock = PTHREAD_MUTEX_INITIALIZER;
29
+		xLock_1 = PTHREAD_MUTEX_INITIALIZER;
30
+	}
31
+	virtual ~Item()
32
+	{
33
+	}
34
+
35
+public:
36
+
37
+	const std::string& getFaultdata() const
38
+	{
39
+		return faultdata;
40
+	}
41
+
42
+	void setFaultdata(const std::string& faultdata)
43
+	{
44
+		this->faultdata = faultdata;
45
+	}
46
+
47
+	const std::string& getFaulttime() const
48
+	{
49
+		return faulttime;
50
+	}
51
+
52
+	void setFaulttime(const std::string& faulttime)
53
+	{
54
+		this->faulttime = faulttime;
55
+	}
56
+
57
+	bool isIsFault()
58
+	{
59
+		return isFault;
60
+	}
61
+
62
+	void setIsFault(bool isFault)
63
+	{
64
+		this->isFault = isFault;
65
+	}
66
+
67
+	bool isIsReset()
68
+	{
69
+		return isReset;
70
+	}
71
+
72
+	void setIsReset(bool isReset)
73
+	{
74
+		this->isReset = isReset;
75
+	}
76
+
77
+	const std::string& getResettime() const
78
+	{
79
+		return resettime;
80
+	}
81
+
82
+	void setResettime(const std::string& resettime)
83
+	{
84
+		this->resettime = resettime;
85
+	}
86
+
87
+	Base& getBase()
88
+	{
89
+		return m_base;
90
+	}
91
+
92
+	void setBase(const Base& base)
93
+	{
94
+		this->m_base = base;
95
+	}
96
+
97
+	const std::string& getAlarmcondition() const
98
+	{
99
+		return m_alarmcondition;
100
+	}
101
+
102
+	void setAlarmcondition(const std::string& alarmcondition)
103
+	{
104
+		if (!alarmcondition.empty())
105
+		{
106
+			m_alarmcondition = alarmcondition;
107
+		}
108
+	}
109
+
110
+	const std::string& getAlarmcontent() const
111
+	{
112
+		return m_alarmcontent;
113
+	}
114
+
115
+	void setAlarmcontent(const std::string& alarmcontent)
116
+	{
117
+		if (!alarmcontent.empty())
118
+		{
119
+			m_alarmcontent = alarmcontent;
120
+		}
121
+	}
122
+
123
+	int getAlarmenable() const
124
+	{
125
+		return m_alarmenable;
126
+	}
127
+
128
+	void setAlarmenable(int alarmenable)
129
+	{
130
+		m_alarmenable = alarmenable;
131
+	}
132
+
133
+	const std::string& getAlarmvalue() const
134
+	{
135
+		return m_alarmvalue;
136
+	}
137
+
138
+	void setAlarmvalue(const std::string& alarmvalue)
139
+	{
140
+		if (!alarmvalue.empty())
141
+		{
142
+			m_alarmvalue = alarmvalue;
143
+		}
144
+	}
145
+
146
+	int getEnable() const
147
+	{
148
+		return m_enable;
149
+	}
150
+
151
+	void setEnable(int enable)
152
+	{
153
+		m_enable = enable;
154
+	}
155
+
156
+	int getHisenable() const
157
+	{
158
+		return m_hisenable;
159
+	}
160
+
161
+	void setHisenable(int hisenable)
162
+	{
163
+		m_hisenable = hisenable;
164
+	}
165
+
166
+	const std::string& getHistimebase() const
167
+	{
168
+		return m_histimebase;
169
+	}
170
+
171
+	void setHistimebase(const std::string& histimebase)
172
+	{
173
+		if (!histimebase.empty())
174
+		{
175
+			m_histimebase = histimebase;
176
+		}
177
+	}
178
+
179
+	int getHistimes() const
180
+	{
181
+		return m_histimes;
182
+	}
183
+
184
+	void setHistimes(int histimes)
185
+	{
186
+		m_histimes = histimes;
187
+	}
188
+
189
+	const std::string& getHistype() const
190
+	{
191
+		return m_histype;
192
+	}
193
+
194
+	void setHistype(const std::string& histype)
195
+	{
196
+		if (!histype.empty())
197
+		{
198
+			m_histype = histype;
199
+		}
200
+	}
201
+
202
+	int getIndex() const
203
+	{
204
+		return m_index;
205
+	}
206
+
207
+	void setIndex(int index)
208
+	{
209
+		m_index = index;
210
+	}
211
+
212
+	const std::string& getInitvalue() const
213
+	{
214
+		return m_initvalue;
215
+	}
216
+
217
+	void setInitvalue(const std::string& initvalue)
218
+	{
219
+		if (!initvalue.empty())
220
+		{
221
+			m_initvalue = initvalue;
222
+		}
223
+	}
224
+
225
+	CLSID& getParaanalysisguid()
226
+	{
227
+		return m_paraanalysisguid;
228
+	}
229
+
230
+	void setParaanalysisguid(const CLSID& paraanalysisguid)
231
+	{
232
+		m_paraanalysisguid = paraanalysisguid;
233
+	}
234
+
235
+	double getRealmax() const
236
+	{
237
+		return m_realmax;
238
+	}
239
+
240
+	void setRealmax(double realmax)
241
+	{
242
+		m_realmax = realmax;
243
+	}
244
+
245
+	double getRealmin() const
246
+	{
247
+		return m_realmin;
248
+	}
249
+
250
+	void setRealmin(double realmin)
251
+	{
252
+		m_realmin = realmin;
253
+	}
254
+
255
+	const std::string& getResetcondition() const
256
+	{
257
+		return m_resetcondition;
258
+	}
259
+
260
+	void setResetcondition(const std::string& resetcondition)
261
+	{
262
+		if (!resetcondition.empty())
263
+		{
264
+			m_resetcondition = resetcondition;
265
+		}
266
+	}
267
+
268
+	const std::string& getResetvalue() const
269
+	{
270
+		return m_resetvalue;
271
+	}
272
+
273
+	void setResetvalue(const std::string& resetvalue)
274
+	{
275
+		if (!resetvalue.empty())
276
+		{
277
+			m_resetvalue = resetvalue;
278
+		}
279
+	}
280
+
281
+	double getSourcemax() const
282
+	{
283
+		return m_sourcemax;
284
+	}
285
+
286
+	void setSourcemax(double sourcemax)
287
+	{
288
+		m_sourcemax = sourcemax;
289
+	}
290
+
291
+	double getSourcemin() const
292
+	{
293
+		return m_sourcemin;
294
+	}
295
+
296
+	void setSourcemin(double sourcemin)
297
+	{
298
+		m_sourcemin = sourcemin;
299
+	}
300
+
301
+	const std::string& getValue() const
302
+	{
303
+		return m_value;
304
+	}
305
+
306
+	void setValue(const std::string& value)
307
+	{
308
+		if (!value.empty())
309
+		{
310
+
311
+			(void) pthread_mutex_lock(&xLock_1);
312
+			setValueO(m_value);
313
+
314
+			char t[256];
315
+			double sfvalue = 0;
316
+			std::string sdatatype = this->getBase().getParam("数据类型");
317
+
318
+			if((m_sourcemax-m_sourcemin)!=0)
319
+			{
320
+				if((sdatatype=="I")||(sdatatype=="B"))
321
+				{
322
+					int ivalue = strtol(value.c_str(),NULL,10);
323
+					sfvalue = (double)(((((double)ivalue-m_sourcemin)*(m_realmax-m_realmin))/(m_sourcemax-m_sourcemin))+m_realmin);
324
+					sprintf(t,"%.4f",sfvalue);
325
+					std::string str;
326
+					str = t;
327
+					m_value = str;
328
+				}
329
+				else
330
+				{
331
+					double ivalue = strtod(value.c_str(),NULL);
332
+					sfvalue = (double)(((((double)ivalue-m_sourcemin)*(m_realmax-m_realmin))/(m_sourcemax-m_sourcemin))+m_realmin);
333
+					sprintf(t,"%.4f",sfvalue);
334
+					std::string str;
335
+					str = t;
336
+					m_value = str;
337
+				}
338
+			}
339
+
340
+			struct timeval tv;
341
+			struct timezone tz;
342
+			struct tm *p;
343
+			gettimeofday(&tv, &tz);
344
+			p = localtime(&tv.tv_sec);
345
+
346
+			char timechar[255];
347
+			snprintf(timechar, 255, "%04d-%02d-%02d %02d:%02d:%02d,%3lf", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec,
348
+					(tv.tv_usec) * 0.001);
349
+
350
+			std::string result = timechar;
351
+
352
+			setSupdatetime(result);
353
+			long diff = (long)(tv.tv_sec * 1000 + tv.tv_usec*0.001) - lupdatetime;
354
+			setUpdatefreq(diff);
355
+
356
+			setLupdatetime((long)(tv.tv_sec * 1000 + tv.tv_usec*0.001));
357
+
358
+//			if(isTrigFaultOrReset(m_value,this->getAlarmvalue(),this->getAlarmcondition())&&!isFault&&!isReset) {
359
+//				this->setIsFault(true);
360
+//				trace("Item","报警触发");
361
+//				std::cout << isReset << "," << isFault << std::endl;
362
+//			}
363
+//
364
+//			if(isTrigFaultOrReset(m_value,this->getResetvalue(),this->getResetcondition())&&isFault&&!isReset) {
365
+//				this->setIsReset(true);
366
+//				trace("Item","报警复位");
367
+//				std::cout << isReset << "," << isFault << std::endl;
368
+//			}
369
+			(void) pthread_mutex_unlock(&xLock_1);
370
+		}
371
+	}
372
+
373
+	const std::string& getValueO() const
374
+	{
375
+		return m_value_o;
376
+	}
377
+
378
+	void setValueO(const std::string& valueO)
379
+	{
380
+		if (!valueO.empty())
381
+		{
382
+			m_value_o = valueO;
383
+		}
384
+	}
385
+
386
+	const std::string& getWvalue() const
387
+	{
388
+		return m_wvalue;
389
+	}
390
+
391
+	void setWvalue(const std::string& wvalue)
392
+	{
393
+		if (!wvalue.empty())
394
+		{
395
+			(void) pthread_mutex_lock(&xLock);
396
+			setWvalueO(m_wvalue);
397
+			m_wvalue = wvalue;
398
+			(void) pthread_mutex_unlock(&xLock);
399
+		}
400
+	}
401
+
402
+	const std::string& getWvalueO() const
403
+	{
404
+		return m_wvalue_o;
405
+	}
406
+
407
+	void setWvalueO(const std::string& wvalueO)
408
+	{
409
+		if (!wvalueO.empty())
410
+		{
411
+			m_wvalue_o = wvalueO;
412
+		}
413
+	}
414
+
415
+	const Packet* getParent() const
416
+	{
417
+		return m_parent;
418
+	}
419
+
420
+	void setParent(Packet* parent)
421
+	{
422
+		this->m_parent = parent;
423
+	}
424
+
425
+	const ParaAnalysisI* getPpara() const
426
+	{
427
+		return m_ppara;
428
+	}
429
+
430
+	void setPpara(ParaAnalysisI* ppara)
431
+	{
432
+		this->m_ppara = ppara;
433
+	}
434
+
435
+public:
436
+	bool isEqual(Item& item)
437
+	{
438
+		if ((this->getBase().getObjid() == item.getBase().getObjid())
439
+				|| (this->getBase().getName() == item.getBase().getName()))
440
+		{
441
+			return true;
442
+		}
443
+		return false;
444
+	}
445
+
446
+	void outInfo()
447
+	{
448
+
449
+	}
450
+
451
+	Item*& getRitem()
452
+	{
453
+		return m_ritem;
454
+	}
455
+
456
+	void setRitem(Item*& ritem)
457
+	{
458
+		m_ritem = ritem;
459
+	}
460
+
461
+	long getLupdatetime()
462
+	{
463
+		return lupdatetime;
464
+	}
465
+
466
+	void setLupdatetime(long lupdatetime)
467
+	{
468
+		this->lupdatetime = lupdatetime;
469
+	}
470
+
471
+	const std::string& getSupdatetime()
472
+	{
473
+		return supdatetime;
474
+	}
475
+
476
+	void setSupdatetime(const std::string& supdatetime)
477
+	{
478
+		this->supdatetime = supdatetime;
479
+	}
480
+
481
+	long getUpdatefreq()
482
+	{
483
+		return updatefreq;
484
+	}
485
+
486
+	void setUpdatefreq(long updatefreq)
487
+	{
488
+		this->updatefreq = updatefreq;
489
+	}
490
+
491
+private:
492
+	CLSID m_paraanalysisguid;	//----item's ParaAnalysisGUID
493
+	ParaAnalysisI* m_ppara;//----Item参数分析组件句柄
494
+
495
+	int m_index;//----item's index
496
+	double m_sourcemin;//----item's SourceMin
497
+	double m_sourcemax;//----item's SourceMax
498
+	double m_realmin;//----item's RealMin
499
+	double m_realmax;//----item's RealMax
500
+	std::string m_initvalue;//----item's InitValue
501
+	std::string m_value;//----item's Value
502
+	std::string m_value_o;//----item's Value_o
503
+
504
+	int m_enable;//----item's Enable
505
+	int m_alarmenable;//----item's AlarmEnable
506
+	std::string m_alarmcondition;//----item's AlarmCondition
507
+	std::string m_alarmvalue;//----item's AlarmValue
508
+	std::string m_resetcondition;//----item's ResetCondition
509
+	std::string m_resetvalue;//----item's ResetValue
510
+	std::string m_alarmcontent;//----item's AlarmContent
511
+	int m_hisenable;//----item's HisEnable
512
+	std::string m_histype;//----item's HisType
513
+	std::string m_histimebase;//----item's HisTimeBase
514
+	int m_histimes;//----item's HisTimes
515
+	std::string m_wvalue;//----item's write value
516
+	std::string m_wvalue_o;//----item's write value_o
517
+
518
+	Base m_base;
519
+	Packet* m_parent;
520
+	Item* m_ritem;
521
+
522
+	std::string supdatetime;
523
+	long lupdatetime;
524
+	long updatefreq;
525
+
526
+private:
527
+	pthread_mutex_t xLock;
528
+	pthread_mutex_t xLock_1;
529
+
530
+private:
531
+	bool isFault;//----故障标志位
532
+	bool isReset;//----复位标志位
533
+	std::string faulttime;//----故障发生时间
534
+	std::string resettime;//----故障结束时间
535
+	std::string faultdata;//----故障时刻的值
536
+
537
+//	std::string getLocalTime()
538
+//	{
539
+//		struct timeval tv;
540
+//		struct timezone tz;
541
+//		struct tm *p;
542
+//		gettimeofday(&tv, &tz);
543
+//		p = localtime(&tv.tv_sec);
544
+//
545
+//		char timechar[255];
546
+//		snprintf(timechar, 255, "%04d-%02d-%02d %02d:%02d:%02d,%3lf",
547
+//				1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour,
548
+//				p->tm_min, p->tm_sec, (tv.tv_usec) * 0.001);
549
+//
550
+//		std::string result = timechar;
551
+//		return result;
552
+//	}
553
+
554
+//	bool isTrigFaultOrReset(std::string src, std::string dst, std::string condition) {
555
+//		bool bresult = false;
556
+//
557
+//		if(this->getAlarmenable()==1) {
558
+//			double fsrc = 0.0;
559
+//			double fdst = 0.0;
560
+//
561
+//			fsrc = strtod(src.c_str(),NULL);
562
+//			fdst = strtod(dst.c_str(),NULL);
563
+//
564
+//			if(condition==">") {
565
+//				if(fsrc>fdst) {
566
+//					bresult = true;
567
+//				}
568
+//			}
569
+//			else if(condition==">=") {
570
+//				if(fsrc>=fdst) {
571
+//					bresult = true;
572
+//				}
573
+//			}
574
+//			else if(condition=="=") {
575
+//				if(fsrc==fdst) {
576
+//					bresult = true;
577
+//				}
578
+//			}
579
+//			else if(condition=="<=") {
580
+//				if(fsrc<=fdst) {
581
+//					bresult = true;
582
+//				}
583
+//			}
584
+//			else if(condition=="<") {
585
+//				if(fsrc<fdst) {
586
+//					bresult = true;
587
+//				}
588
+//			}
589
+//			else if(condition=="!=") {
590
+//				if(fsrc!=fdst) {
591
+//					bresult = true;
592
+//				}
593
+//			}
594
+//		}
595
+//		else
596
+//		{
597
+//			bresult = false;
598
+//		}
599
+//
600
+//		return bresult;
601
+//	}
602
+};
603
+
604
+#endif /* SERVICEMODEL_ITEM_H_ */

+ 153
- 0
servicemodel/Packet.h Прегледај датотеку

@@ -0,0 +1,153 @@
1
+/*
2
+ * Packet.h
3
+ *
4
+ *  Created on: 2016年11月10日
5
+ *      Author: Mr_zhu
6
+ *     Content: 
7
+ */
8
+
9
+#ifndef SERVICEMODEL_PACKET_H_
10
+#define SERVICEMODEL_PACKET_H_
11
+
12
+#include <vector>
13
+
14
+#include "../common/Type.h"
15
+#include "Base.h"
16
+#include "Item.h"
17
+
18
+class Device;
19
+
20
+class Packet
21
+{
22
+public:
23
+	Packet() :
24
+			m_parent(NULL)
25
+	{
26
+
27
+	}
28
+	virtual ~Packet()
29
+	{
30
+	}
31
+
32
+	const CLSID& getClsid() const
33
+	{
34
+		return m_clsid;
35
+	}
36
+
37
+	void setClsid(const CLSID& clsid)
38
+	{
39
+		this->m_clsid = clsid;
40
+	}
41
+
42
+	const Device* getParent() const
43
+	{
44
+		return m_parent;
45
+	}
46
+
47
+	void setParent(Device* parent)
48
+	{
49
+		this->m_parent = parent;
50
+	}
51
+
52
+	std::vector<Item*>& getVitem()
53
+	{
54
+		return m_vitem;
55
+	}
56
+
57
+	void setVitem(const std::vector<Item*>& vitem)
58
+	{
59
+		this->m_vitem = vitem;
60
+	}
61
+
62
+	Base& getBase()
63
+	{
64
+		return m_base;
65
+	}
66
+
67
+	void setBase(const Base& base)
68
+	{
69
+		this->m_base = base;
70
+	}
71
+
72
+	HRESULT addItem(Item* item)
73
+	{
74
+		bool isexist = false;
75
+
76
+		for (Item*& i : m_vitem)
77
+		{
78
+			if (i->isEqual(*item))
79
+			{
80
+				isexist = true;
81
+				break;
82
+			}
83
+		}
84
+		if (!isexist)
85
+		{
86
+			m_vitem.push_back(item);
87
+
88
+			return S_OK;
89
+		}
90
+		return S_FALSE;
91
+	}
92
+
93
+	ULONG getItemCount()
94
+	{
95
+		return m_vitem.size();
96
+	}
97
+
98
+
99
+public:
100
+	bool isEqual(Packet& packet)
101
+	{
102
+		bool bresult = true;
103
+
104
+		if ((packet.getClsid() == m_clsid) && (packet.getParent() == m_parent))
105
+		{
106
+			return true;
107
+		}
108
+		else
109
+		{
110
+			bresult = false;
111
+		}
112
+		std::vector<Item*>& v = packet.getVitem();
113
+		if (this->getItemCount() == packet.getItemCount())
114
+		{
115
+			for (unsigned int i = 0; i < m_vitem.size(); i++)
116
+			{
117
+				if (!(m_vitem.at(i)->isEqual(*(v.at(i)))))
118
+				{
119
+					bresult = false;
120
+					break;
121
+				}
122
+			}
123
+		}
124
+
125
+		return bresult;
126
+	}
127
+
128
+	void outInfo()
129
+	{
130
+
131
+	}
132
+
133
+	std::map<int, int>& getMregstartIndex()
134
+	{
135
+		return m_mregstart_index;
136
+	}
137
+
138
+	void setMregstartIndex(std::map<int, int>& mregstartIndex)
139
+	{
140
+		m_mregstart_index = mregstartIndex;
141
+	}
142
+
143
+private:
144
+	CLSID m_clsid;
145
+	Device* m_parent;
146
+	std::vector<Item*> m_vitem;
147
+
148
+	std::map<int, int> m_mregstart_index;
149
+
150
+	Base m_base;
151
+};
152
+
153
+#endif /* SERVICEMODEL_PACKET_H_ */

+ 34
- 0
test/main.cpp Прегледај датотеку

@@ -0,0 +1,34 @@
1
+/*
2
+ * main.cpp
3
+ *
4
+ *  Created on: 2016年12月7日
5
+ *      Author: nego
6
+ */
7
+
8
+#include "../service/impl/ProtocolImpl.h"
9
+#include "../servicemodel/Device.h"
10
+#include "../servicemodel/Item.h"
11
+#include "../servicemodel/Packet.h"
12
+
13
+int main() {
14
+	ProtocolI* pP = new ProtocolImpl();
15
+
16
+	Device* pdevice = new Device();
17
+	Packet* ppacket = new Packet();
18
+	Item* pitem = new Item();
19
+
20
+	pitem->setAlarmcondition("=");
21
+	pitem->setAlarmenable(1);
22
+	pitem->setAlarmvalue("1");
23
+	pitem->setValue("1");
24
+
25
+	char t[1024];
26
+	int len = 0;
27
+	pP->onRead(pdevice, ppacket, pitem, t, len);
28
+	pP->onWrite(pdevice, ppacket, pitem, t, len, "1", 1);
29
+
30
+	int deletelen = 0;
31
+	pP->isResponseOK(pdevice, ppacket, pitem, t, len);
32
+	pP->onResponse(pdevice, ppacket, pitem, t, len, deletelen);
33
+}
34
+

+ 273
- 0
util/easylogger/inc/elog.h Прегледај датотеку

@@ -0,0 +1,273 @@
1
+/*
2
+ * This file is part of the EasyLogger Library.
3
+ *
4
+ * Copyright (c) 2015-2019, Armink, <armink.ztl@gmail.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * 'Software'), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * Function: It is an head file for this library. You can see all be called functions.
26
+ * Created on: 2015-04-28
27
+ */
28
+
29
+#ifndef __ELOG_H__
30
+#define __ELOG_H__
31
+
32
+#include <elog_cfg.h>
33
+#include <stdint.h>
34
+#include <stddef.h>
35
+#include <stdbool.h>
36
+
37
+#ifdef __cplusplus
38
+extern "C" {
39
+#endif
40
+
41
+/* output log's level */
42
+#define ELOG_LVL_ASSERT                      0
43
+#define ELOG_LVL_ERROR                       1
44
+#define ELOG_LVL_WARN                        2
45
+#define ELOG_LVL_INFO                        3
46
+#define ELOG_LVL_DEBUG                       4
47
+#define ELOG_LVL_VERBOSE                     5
48
+
49
+/* the output silent level and all level for filter setting */
50
+#define ELOG_FILTER_LVL_SILENT               ELOG_LVL_ASSERT
51
+#define ELOG_FILTER_LVL_ALL                  ELOG_LVL_VERBOSE
52
+
53
+/* output log's level total number */
54
+#define ELOG_LVL_TOTAL_NUM                   6
55
+
56
+/* EasyLogger software version number */
57
+#define ELOG_SW_VERSION                      "2.2.99"
58
+
59
+/* EasyLogger assert for developer. */
60
+#ifdef ELOG_ASSERT_ENABLE
61
+    #define ELOG_ASSERT(EXPR)                                                 \
62
+    if (!(EXPR))                                                              \
63
+    {                                                                         \
64
+        if (elog_assert_hook == NULL) {                                       \
65
+            elog_a("elog", "(%s) has assert failed at %s:%ld.", #EXPR, __FUNCTION__, __LINE__); \
66
+            while (1);                                                        \
67
+        } else {                                                              \
68
+            elog_assert_hook(#EXPR, __FUNCTION__, __LINE__);                  \
69
+        }                                                                     \
70
+    }
71
+#else
72
+    #define ELOG_ASSERT(EXPR)                    ((void)0);
73
+#endif
74
+
75
+#ifndef ELOG_OUTPUT_ENABLE
76
+    #define elog_assert(tag, ...)
77
+    #define elog_error(tag, ...)
78
+    #define elog_warn(tag, ...)
79
+    #define elog_info(tag, ...)
80
+    #define elog_debug(tag, ...)
81
+    #define elog_verbose(tag, ...)
82
+#else /* ELOG_OUTPUT_ENABLE */
83
+    #if ELOG_OUTPUT_LVL >= ELOG_LVL_ASSERT
84
+        #define elog_assert(tag, ...) \
85
+                elog_output(ELOG_LVL_ASSERT, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
86
+    #else
87
+        #define elog_assert(tag, ...)
88
+    #endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_ASSERT */
89
+
90
+    #if ELOG_OUTPUT_LVL >= ELOG_LVL_ERROR
91
+        #define elog_error(tag, ...) \
92
+                elog_output(ELOG_LVL_ERROR, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
93
+    #else
94
+        #define elog_error(tag, ...)
95
+    #endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_ERROR */
96
+
97
+    #if ELOG_OUTPUT_LVL >= ELOG_LVL_WARN
98
+        #define elog_warn(tag, ...) \
99
+                elog_output(ELOG_LVL_WARN, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
100
+    #else
101
+        #define elog_warn(tag, ...)
102
+    #endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_WARN */
103
+
104
+    #if ELOG_OUTPUT_LVL >= ELOG_LVL_INFO
105
+        #define elog_info(tag, ...) \
106
+                elog_output(ELOG_LVL_INFO, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
107
+    #else
108
+        #define elog_info(tag, ...)
109
+    #endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_INFO */
110
+
111
+    #if ELOG_OUTPUT_LVL >= ELOG_LVL_DEBUG
112
+        #define elog_debug(tag, ...) \
113
+                elog_output(ELOG_LVL_DEBUG, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
114
+    #else
115
+        #define elog_debug(tag, ...)
116
+    #endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_DEBUG */
117
+
118
+    #if ELOG_OUTPUT_LVL == ELOG_LVL_VERBOSE
119
+        #define elog_verbose(tag, ...) \
120
+                elog_output(ELOG_LVL_VERBOSE, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
121
+    #else
122
+        #define elog_verbose(tag, ...)
123
+    #endif /* ELOG_OUTPUT_LVL == ELOG_LVL_VERBOSE */
124
+#endif /* ELOG_OUTPUT_ENABLE */
125
+
126
+/* all formats index */
127
+typedef enum {
128
+    ELOG_FMT_LVL    = 1 << 0, /**< level */
129
+    ELOG_FMT_TAG    = 1 << 1, /**< tag */
130
+    ELOG_FMT_TIME   = 1 << 2, /**< current time */
131
+    ELOG_FMT_P_INFO = 1 << 3, /**< process info */
132
+    ELOG_FMT_T_INFO = 1 << 4, /**< thread info */
133
+    ELOG_FMT_DIR    = 1 << 5, /**< file directory and name */
134
+    ELOG_FMT_FUNC   = 1 << 6, /**< function name */
135
+    ELOG_FMT_LINE   = 1 << 7, /**< line number */
136
+} ElogFmtIndex;
137
+
138
+/* macro definition for all formats */
139
+#define ELOG_FMT_ALL    (ELOG_FMT_LVL|ELOG_FMT_TAG|ELOG_FMT_TIME|ELOG_FMT_P_INFO|ELOG_FMT_T_INFO| \
140
+    ELOG_FMT_DIR|ELOG_FMT_FUNC|ELOG_FMT_LINE)
141
+
142
+/* output log's tag filter */
143
+typedef struct {
144
+    uint8_t level;
145
+    char tag[ELOG_FILTER_TAG_MAX_LEN + 1];
146
+    bool tag_use_flag; /**< false : tag is no used   true: tag is used */
147
+} ElogTagLvlFilter, *ElogTagLvlFilter_t;
148
+
149
+/* output log's filter */
150
+typedef struct {
151
+    uint8_t level;
152
+    char tag[ELOG_FILTER_TAG_MAX_LEN + 1];
153
+    char keyword[ELOG_FILTER_KW_MAX_LEN + 1];
154
+    ElogTagLvlFilter tag_lvl[ELOG_FILTER_TAG_LVL_MAX_NUM];
155
+} ElogFilter, *ElogFilter_t;
156
+
157
+/* easy logger */
158
+typedef struct {
159
+    ElogFilter filter;
160
+    size_t enabled_fmt_set[ELOG_LVL_TOTAL_NUM];
161
+    bool init_ok;
162
+    bool output_enabled;
163
+    bool output_lock_enabled;
164
+    bool output_is_locked_before_enable;
165
+    bool output_is_locked_before_disable;
166
+
167
+#ifdef ELOG_COLOR_ENABLE
168
+    bool text_color_enabled;
169
+#endif
170
+
171
+}EasyLogger, *EasyLogger_t;
172
+
173
+/* EasyLogger error code */
174
+typedef enum {
175
+    ELOG_NO_ERR,
176
+} ElogErrCode;
177
+
178
+/* elog.c */
179
+ElogErrCode elog_init(void);
180
+void elog_start(void);
181
+void elog_set_output_enabled(bool enabled);
182
+bool elog_get_output_enabled(void);
183
+void elog_set_text_color_enabled(bool enabled);
184
+bool elog_get_text_color_enabled(void);
185
+void elog_set_fmt(uint8_t level, size_t set);
186
+void elog_set_filter(uint8_t level, const char *tag, const char *keyword);
187
+void elog_set_filter_lvl(uint8_t level);
188
+void elog_set_filter_tag(const char *tag);
189
+void elog_set_filter_kw(const char *keyword);
190
+void elog_set_filter_tag_lvl(const char *tag, uint8_t level);
191
+uint8_t elog_get_filter_tag_lvl(const char *tag);
192
+void elog_raw(const char *format, ...);
193
+void elog_output(uint8_t level, const char *tag, const char *file, const char *func,
194
+        const long line, const char *format, ...);
195
+void elog_output_lock_enabled(bool enabled);
196
+extern void (*elog_assert_hook)(const char* expr, const char* func, size_t line);
197
+void elog_assert_set_hook(void (*hook)(const char* expr, const char* func, size_t line));
198
+int8_t elog_find_lvl(const char *log);
199
+const char *elog_find_tag(const char *log, uint8_t lvl, size_t *tag_len);
200
+void elog_hexdump(const char *name, uint8_t width, uint8_t *buf, uint16_t size);
201
+
202
+#define elog_a(tag, ...)     elog_assert(tag, __VA_ARGS__)
203
+#define elog_e(tag, ...)     elog_error(tag, __VA_ARGS__)
204
+#define elog_w(tag, ...)     elog_warn(tag, __VA_ARGS__)
205
+#define elog_i(tag, ...)     elog_info(tag, __VA_ARGS__)
206
+#define elog_d(tag, ...)     elog_debug(tag, __VA_ARGS__)
207
+#define elog_v(tag, ...)     elog_verbose(tag, __VA_ARGS__)
208
+
209
+/**
210
+ * log API short definition
211
+ * NOTE: The `LOG_TAG` and `LOG_LVL` must defined before including the <elog.h> when you want to use log_x API.
212
+ */
213
+#if !defined(LOG_TAG)
214
+    #define LOG_TAG          "NO_TAG"
215
+#endif
216
+#if !defined(LOG_LVL)
217
+    #define LOG_LVL          ELOG_LVL_VERBOSE
218
+#endif
219
+#if LOG_LVL >= ELOG_LVL_ASSERT
220
+    #define log_a(...)       elog_a(LOG_TAG, __VA_ARGS__)
221
+#else
222
+    #define log_a(...)       ((void)0);
223
+#endif
224
+#if LOG_LVL >= ELOG_LVL_ERROR
225
+    #define log_e(...)       elog_e(LOG_TAG, __VA_ARGS__)
226
+#else
227
+    #define log_e(...)       ((void)0);
228
+#endif
229
+#if LOG_LVL >= ELOG_LVL_WARN
230
+    #define log_w(...)       elog_w(LOG_TAG, __VA_ARGS__)
231
+#else
232
+    #define log_w(...)       ((void)0);
233
+#endif
234
+#if LOG_LVL >= ELOG_LVL_INFO
235
+    #define log_i(...)       elog_i(LOG_TAG, __VA_ARGS__)
236
+#else
237
+    #define log_i(...)       ((void)0);
238
+#endif
239
+#if LOG_LVL >= ELOG_LVL_DEBUG
240
+    #define log_d(...)       elog_d(LOG_TAG, __VA_ARGS__)
241
+#else
242
+    #define log_d(...)       ((void)0);
243
+#endif
244
+#if LOG_LVL >= ELOG_LVL_VERBOSE
245
+    #define log_v(...)       elog_v(LOG_TAG, __VA_ARGS__)
246
+#else
247
+    #define log_v(...)       ((void)0);
248
+#endif
249
+
250
+/* assert API short definition */
251
+#if !defined(assert)
252
+    #define assert           ELOG_ASSERT
253
+#endif
254
+
255
+/* elog_buf.c */
256
+void elog_buf_enabled(bool enabled);
257
+void elog_flush(void);
258
+
259
+/* elog_async.c */
260
+void elog_async_enabled(bool enabled);
261
+size_t elog_async_get_log(char *log, size_t size);
262
+size_t elog_async_get_line_log(char *log, size_t size);
263
+
264
+/* elog_utils.c */
265
+size_t elog_strcpy(size_t cur_len, char *dst, const char *src);
266
+size_t elog_cpyln(char *line, const char *log, size_t len);
267
+void *elog_memcpy(void *dst, const void *src, size_t count);
268
+
269
+#ifdef __cplusplus
270
+}
271
+#endif
272
+
273
+#endif /* __ELOG_H__ */

+ 67
- 0
util/easylogger/inc/elog_cfg.h Прегледај датотеку

@@ -0,0 +1,67 @@
1
+/*
2
+ * This file is part of the EasyLogger Library.
3
+ *
4
+ * Copyright (c) 2015, Armink, <armink.ztl@gmail.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * 'Software'), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * Function: It is the configure head file for this library.
26
+ * Created on: 2015-07-30
27
+ */
28
+
29
+#ifndef _ELOG_CFG_H_
30
+#define _ELOG_CFG_H_
31
+
32
+/* enable log output. default open this macro */
33
+#define ELOG_OUTPUT_ENABLE
34
+/* enable log write file. default open this macro */
35
+#define ELOG_FILE_ENABLE
36
+/* enable flush file cache. default open this macro */
37
+#define ELOG_FILE_FLUSH_CAHCE_ENABLE
38
+/* setting static output log level */
39
+#define ELOG_OUTPUT_LVL                      ELOG_LVL_INFO
40
+/* enable assert check */
41
+#define ELOG_ASSERT_ENABLE
42
+/* buffer size for every line's log */
43
+#define ELOG_LINE_BUF_SIZE                   512
44
+/* output line number max length */
45
+#define ELOG_LINE_NUM_MAX_LEN                5
46
+/* output filter's tag max length */
47
+#define ELOG_FILTER_TAG_MAX_LEN              16
48
+/* output filter's keyword max length */
49
+#define ELOG_FILTER_KW_MAX_LEN               16
50
+/* output filter's tag level max num */
51
+#define ELOG_FILTER_TAG_LVL_MAX_NUM          5
52
+/* output newline sign */
53
+#define ELOG_NEWLINE_SIGN                    "\n"
54
+/* enable log color */
55
+// #define ELOG_COLOR_ENABLE
56
+/* enable asynchronous output mode */
57
+#define ELOG_ASYNC_OUTPUT_ENABLE
58
+/* the highest output level for async mode, other level will sync output */
59
+#define ELOG_ASYNC_OUTPUT_LVL                ELOG_LVL_INFO
60
+/* buffer size for asynchronous output mode */
61
+#define ELOG_ASYNC_OUTPUT_BUF_SIZE           (ELOG_LINE_BUF_SIZE * 100)
62
+/* each asynchronous output's log which must end with newline sign */
63
+//#define ELOG_ASYNC_LINE_OUTPUT
64
+/* asynchronous output mode using POSIX pthread implementation */
65
+#define ELOG_ASYNC_OUTPUT_USING_PTHREAD
66
+
67
+#endif /* _ELOG_CFG_H_ */

+ 165
- 0
util/easylogger/plugins/file/elog_file.c Прегледај датотеку

@@ -0,0 +1,165 @@
1
+/*
2
+ * This file is part of the EasyLogger Library.
3
+ *
4
+ * Copyright (c) 2015-2019, Qintl, <qintl_linux@163.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * 'Software'), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * Function: Save log to file.
26
+ * Created on: 2019-01-05
27
+ */
28
+
29
+ #define LOG_TAG    "elog.file"
30
+
31
+#include <stdio.h>
32
+#include <stdbool.h>
33
+#include <stdlib.h>
34
+#include <string.h>
35
+
36
+#include "elog_file.h"
37
+
38
+/* initialize OK flag */
39
+static bool init_ok = false;
40
+static FILE *fp = NULL;
41
+static ElogFileCfg local_cfg;
42
+
43
+ElogErrCode elog_file_init(void)
44
+{
45
+    ElogErrCode result = ELOG_NO_ERR;
46
+    ElogFileCfg cfg;
47
+
48
+    if (init_ok)
49
+        goto __exit;
50
+
51
+    elog_file_port_init();
52
+
53
+    cfg.name = ELOG_FILE_NAME;
54
+    cfg.max_size = ELOG_FILE_MAX_SIZE;
55
+    cfg.max_rotate = ELOG_FILE_MAX_ROTATE;
56
+
57
+    elog_file_config(&cfg);
58
+
59
+    init_ok = true;
60
+__exit:
61
+    return result;
62
+}
63
+
64
+/*
65
+ * rotate the log file xxx.log.n-1 => xxx.log.n, and xxx.log => xxx.log.0
66
+ */
67
+static bool elog_file_rotate(void)
68
+{
69
+#define SUFFIX_LEN                     10
70
+    /* mv xxx.log.n-1 => xxx.log.n, and xxx.log => xxx.log.0 */
71
+    int n, err = 0;
72
+    char oldpath[256], newpath[256];
73
+    size_t base = strlen(local_cfg.name);
74
+    bool result = true;
75
+    FILE *tmp_fp;
76
+
77
+    memcpy(oldpath, local_cfg.name, base);
78
+    memcpy(newpath, local_cfg.name, base);
79
+
80
+    fclose(fp);
81
+
82
+    for (n = local_cfg.max_rotate - 1; n >= 0; --n) {
83
+        snprintf(oldpath + base, SUFFIX_LEN, n ? ".%d" : "", n - 1);
84
+        snprintf(newpath + base, SUFFIX_LEN, ".%d", n);
85
+        /* remove the old file */
86
+        if ((tmp_fp = fopen(newpath , "r")) != NULL) {
87
+            fclose(tmp_fp);
88
+            remove(newpath);
89
+        }
90
+        /* change the new log file to old file name */
91
+        if ((tmp_fp = fopen(oldpath , "r")) != NULL) {
92
+            fclose(tmp_fp);
93
+            err = rename(oldpath, newpath);
94
+        }
95
+
96
+        if (err < 0) {
97
+            result = false;
98
+            goto __exit;
99
+        }
100
+    }
101
+
102
+__exit:
103
+    /* reopen the file */
104
+    fp = fopen(local_cfg.name, "a+");
105
+
106
+    return result;
107
+}
108
+
109
+
110
+void elog_file_write(const char *log, size_t size)
111
+{
112
+    size_t file_size = 0;
113
+
114
+    ELOG_ASSERT(init_ok);
115
+    ELOG_ASSERT(log);
116
+
117
+    elog_file_port_lock();
118
+
119
+    fseek(fp, 0L, SEEK_END);
120
+    file_size = ftell(fp);
121
+
122
+    if (unlikely(file_size > local_cfg.max_size)) {
123
+#if ELOG_FILE_MAX_ROTATE > 0
124
+        if (!elog_file_rotate()) {
125
+            goto __exit;
126
+        }
127
+#else
128
+        goto __exit;
129
+#endif
130
+    }
131
+
132
+    fwrite(log, size, 1, fp);
133
+
134
+#ifdef ELOG_FILE_FLUSH_CAHCE_ENABLE
135
+    fflush(fp);
136
+#endif
137
+
138
+__exit:
139
+    elog_file_port_unlock();
140
+}
141
+
142
+void elog_file_deinit(void)
143
+{
144
+    ELOG_ASSERT(init_ok);
145
+
146
+    elog_file_port_deinit();
147
+    fclose(fp);
148
+}
149
+
150
+void elog_file_config(ElogFileCfg *cfg)
151
+{
152
+    if (fp) {
153
+        fclose(fp);
154
+    }
155
+
156
+    elog_file_port_lock();
157
+
158
+    local_cfg.name = cfg->name;
159
+    local_cfg.max_size = cfg->max_size;
160
+    local_cfg.max_rotate = cfg->max_rotate;
161
+
162
+    fp = fopen(local_cfg.name, "a+");
163
+
164
+    elog_file_port_unlock();
165
+}

+ 72
- 0
util/easylogger/plugins/file/elog_file.h Прегледај датотеку

@@ -0,0 +1,72 @@
1
+/*
2
+ * This file is part of the EasyLogger Library.
3
+ *
4
+ * Copyright (c) 2015-2019, Qintl, <qintl_linux@163.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * 'Software'), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * Function:  It is an head file for file log plugin. You can see all be called functions.
26
+ * Created on: 2019-01-05
27
+ */
28
+
29
+#ifndef __ELOG_FILE__H__
30
+#define __ELOG_FILE__H__
31
+
32
+#include <stdio.h>
33
+#include <elog.h>
34
+#include <elog_file_cfg.h>
35
+
36
+#ifdef __cplusplus
37
+extern "C" {
38
+#endif
39
+
40
+/* EasyLogger file log plugin's software version number */
41
+#define ELOG_FILE_SW_VERSION                "V1.0.0"
42
+#ifdef linux
43
+#define likely(x) __builtin_expect(!!(x), 1)
44
+#define unlikely(x) __builtin_expect(!!(x), 0)
45
+#else
46
+#define likely(x)   (x)
47
+#define unlikely(x) (x)
48
+#endif
49
+
50
+typedef struct {
51
+    char *name;              /* file name */
52
+    size_t max_size;         /* file max size */
53
+    int max_rotate;          /* max rotate file count */
54
+} ElogFileCfg;
55
+
56
+/* elog_file.c */
57
+ElogErrCode elog_file_init(void);
58
+void elog_file_write(const char *log, size_t size);
59
+void elog_file_config(ElogFileCfg *cfg);
60
+void elog_file_deinit(void);
61
+
62
+/* elog_file_port.c */
63
+ElogErrCode elog_file_port_init(void);
64
+void elog_file_port_lock(void);
65
+void elog_file_port_unlock(void);
66
+void elog_file_port_deinit(void);
67
+
68
+#ifdef __cplusplus
69
+}
70
+#endif
71
+
72
+#endif

+ 41
- 0
util/easylogger/plugins/file/elog_file_cfg.h Прегледај датотеку

@@ -0,0 +1,41 @@
1
+/*
2
+ * This file is part of the EasyLogger Library.
3
+ *
4
+ * Copyright (c) 2015-2019, Qintl, <qintl_linux@163.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * 'Software'), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * Function:  It is the configure head file for this flash log plugin.
26
+ * Created on: 2019-01-05
27
+ */
28
+
29
+#ifndef _ELOG_FILE_CFG_H_
30
+#define _ELOG_FILE_CFG_H_
31
+
32
+/* EasyLogger file log plugin's using file name */
33
+#define ELOG_FILE_NAME      "/mnt/logs/deecs_protocol_canBMSer.out"
34
+
35
+/* EasyLogger file log plugin's using file max size */
36
+#define ELOG_FILE_MAX_SIZE  (10 * 1024 * 1024)
37
+
38
+/* EasyLogger file log plugin's using max rotate file count */
39
+#define ELOG_FILE_MAX_ROTATE 5
40
+
41
+#endif /* _ELOG_FILE_CFG_H_ */

+ 160
- 0
util/easylogger/plugins/file/elog_file_port.c Прегледај датотеку

@@ -0,0 +1,160 @@
1
+/*
2
+ * This file is part of the EasyLogger Library.
3
+ *
4
+ * Copyright (c) 2015-2019, Qintl, <qintl_linux@163.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * 'Software'), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * Function:  Portable interface for EasyLogger's file log pulgin.
26
+ * Created on: 2019-01-05
27
+ */
28
+
29
+#include <stdio.h>
30
+#include <sys/types.h>
31
+#include <sys/stat.h>
32
+#include <fcntl.h>
33
+#include <sys/ipc.h>
34
+#include <sys/sem.h>
35
+
36
+#include <unistd.h>
37
+
38
+#include <elog_file.h>
39
+#include <elog_file_cfg.h>
40
+
41
+#define ELOG_FILE_SEM_KEY   ((key_t)0x19910612)
42
+#ifdef _SEM_SEMUN_UNDEFINED
43
+union semun {
44
+    int              val;    /* Value for SETVAL */
45
+    struct semid_ds *buf;    /* Buffer for IPC_STAT, IPC_SET */
46
+    unsigned short  *array;  /* Array for GETALL, SETALL */
47
+    struct seminfo  *__buf;  /* Buffer for IPC_INFO
48
+                                (Linux-specific) */
49
+};
50
+#endif
51
+
52
+static int semid = -1;
53
+static struct sembuf const up = {0, 1, SEM_UNDO};
54
+static struct sembuf const down = {0, -1, SEM_UNDO};
55
+
56
+static void lock_init(void);
57
+static int lock_open(void);
58
+/**
59
+ * EasyLogger flile log pulgin port initialize
60
+ *
61
+ * @return result
62
+ */
63
+ElogErrCode elog_file_port_init(void) {
64
+    ElogErrCode result = ELOG_NO_ERR;
65
+
66
+    lock_init();
67
+
68
+    return result;
69
+}
70
+
71
+/**
72
+ * file log lock
73
+ */
74
+void inline elog_file_port_lock(void)
75
+{
76
+    semid == -1 ? -1 : semop(semid, (struct sembuf *)&down, 1);
77
+}
78
+
79
+/**
80
+ * file log unlock
81
+ */
82
+void inline elog_file_port_unlock(void)
83
+{
84
+    semid == -1 ? -1 : semop(semid, (struct sembuf *)&up, 1);
85
+}
86
+/**
87
+ * file log deinit
88
+ */
89
+void elog_file_port_deinit(void)
90
+{
91
+
92
+}
93
+
94
+/**
95
+ * initialize the lock 
96
+ */
97
+static void lock_init(void)
98
+{
99
+    int id, rc;
100
+    union semun arg;
101
+    struct sembuf sembuf;
102
+
103
+    id = semget(ELOG_FILE_SEM_KEY, 1, IPC_CREAT | IPC_EXCL | 0666);
104
+    if(likely(id == -1)) {
105
+        id = lock_open();
106
+        if (id == -1)
107
+            goto __exit;
108
+    } else {
109
+        arg.val = 0;
110
+        rc = semctl(id, 0, SETVAL, arg);
111
+        if (rc == -1)
112
+            goto __exit;
113
+
114
+        sembuf.sem_num = 0;
115
+        sembuf.sem_op = 1;
116
+        sembuf.sem_flg = 0;
117
+
118
+        rc = semop(id, &sembuf, 1);
119
+        if (rc == -1)
120
+            goto __exit;
121
+    }
122
+
123
+    semid = id;
124
+__exit:
125
+    return ;
126
+}
127
+
128
+/**
129
+ * gets the lock 
130
+ */
131
+static int lock_open(void)
132
+{
133
+    int id, rc, i;
134
+    union semun arg;
135
+    struct semid_ds ds;
136
+
137
+    id = semget(ELOG_FILE_SEM_KEY, 1, 0666);
138
+    if(unlikely(id == -1))
139
+        goto err;
140
+
141
+    arg.buf = &ds;
142
+
143
+    for (i = 0; i < 10; i++) {
144
+        rc = semctl(id, 0, IPC_STAT, arg);
145
+        if (unlikely(rc == -1))
146
+            goto err;
147
+
148
+        if(ds.sem_otime != 0)
149
+            break;
150
+
151
+        usleep(10 * 1000);
152
+    }
153
+
154
+    if (unlikely(ds.sem_otime == 0))
155
+        goto err;
156
+
157
+    return id;
158
+err:
159
+    return -1;
160
+}

+ 146
- 0
util/easylogger/port/elog_port.c Прегледај датотеку

@@ -0,0 +1,146 @@
1
+/*
2
+ * This file is part of the EasyLogger Library.
3
+ *
4
+ * Copyright (c) 2015, Armink, <armink.ztl@gmail.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * 'Software'), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * Function: Portable interface for linux.
26
+ * Created on: 2015-04-28
27
+ */
28
+
29
+#include <elog.h>
30
+#include <pthread.h>
31
+#include <stddef.h>
32
+#include <stdio.h>
33
+#include <sys/time.h>
34
+#include <time.h>
35
+#include <unistd.h>
36
+
37
+#ifdef ELOG_FILE_ENABLE
38
+#include <elog_file.h>
39
+#endif
40
+static pthread_mutex_t output_lock;
41
+
42
+/**
43
+ * EasyLogger port initialize
44
+ *
45
+ * @return result
46
+ */
47
+ElogErrCode elog_port_init(void)
48
+{
49
+	ElogErrCode result = ELOG_NO_ERR;
50
+
51
+	pthread_mutex_init(&output_lock, NULL);
52
+
53
+#ifdef ELOG_FILE_ENABLE
54
+	elog_file_init();
55
+#endif
56
+
57
+	return result;
58
+}
59
+
60
+/**
61
+ * output log port interface
62
+ *
63
+ * @param log output of log
64
+ * @param size log size
65
+ */
66
+void elog_port_output(const char *log, size_t size)
67
+{
68
+	/* output to terminal */
69
+	printf("%.*s", (int) size, log);
70
+#ifdef ELOG_FILE_ENABLE
71
+	/* write the file */
72
+	elog_file_write(log, size);
73
+#endif 
74
+}
75
+
76
+/**
77
+ * output lock
78
+ */
79
+void elog_port_output_lock(void)
80
+{
81
+	pthread_mutex_lock(&output_lock);
82
+}
83
+
84
+/**
85
+ * output unlock
86
+ */
87
+void elog_port_output_unlock(void)
88
+{
89
+	pthread_mutex_unlock(&output_lock);
90
+}
91
+
92
+/**
93
+ * get current time interface
94
+ *
95
+ * @return current time
96
+ */
97
+const char *elog_port_get_time(void)
98
+{
99
+	static char cur_system_time[30] =
100
+	{ 0 };
101
+
102
+	struct timeval tv;
103
+	struct timezone tz;
104
+	struct tm *p;
105
+	gettimeofday(&tv, &tz);
106
+	p = localtime(&tv.tv_sec);
107
+
108
+	if(p == NULL) {
109
+		return "";
110
+	}
111
+
112
+	snprintf(cur_system_time, 26, "%04d-%02d-%02d %02d:%02d:%02d.%06ld", 1900 + p->tm_year, p->tm_mon + 1, p->tm_mday,
113
+			p->tm_hour, p->tm_min, p->tm_sec, tv.tv_usec);
114
+
115
+	return cur_system_time;
116
+}
117
+
118
+/**
119
+ * get current process name interface
120
+ *
121
+ * @return current process name
122
+ */
123
+const char *elog_port_get_p_info(void)
124
+{
125
+	static char cur_process_info[10] =
126
+	{ 0 };
127
+
128
+	snprintf(cur_process_info, 10, "pid:%04d", getpid());
129
+
130
+	return cur_process_info;
131
+}
132
+
133
+/**
134
+ * get current thread name interface
135
+ *
136
+ * @return current thread name
137
+ */
138
+const char *elog_port_get_t_info(void)
139
+{
140
+	static char cur_thread_info[10] =
141
+	{ 0 };
142
+
143
+	snprintf(cur_thread_info, 10, "tid:%04ld", pthread_self());
144
+
145
+	return cur_thread_info;
146
+}

+ 872
- 0
util/easylogger/src/elog.c Прегледај датотеку

@@ -0,0 +1,872 @@
1
+/*
2
+ * This file is part of the EasyLogger Library.
3
+ *
4
+ * Copyright (c) 2015-2018, Armink, <armink.ztl@gmail.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * 'Software'), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * Function: Initialize function and other general function.
26
+ * Created on: 2015-04-28
27
+ */
28
+
29
+#define LOG_TAG      "elog"
30
+
31
+#include <elog.h>
32
+#include <string.h>
33
+#include <stdarg.h>
34
+#include <stdio.h>
35
+
36
+#if !defined(ELOG_OUTPUT_LVL)
37
+    #error "Please configure static output log level (in elog_cfg.h)"
38
+#endif
39
+
40
+#if !defined(ELOG_LINE_NUM_MAX_LEN)
41
+    #error "Please configure output line number max length (in elog_cfg.h)"
42
+#endif
43
+
44
+#if !defined(ELOG_LINE_BUF_SIZE)
45
+    #error "Please configure buffer size for every line's log (in elog_cfg.h)"
46
+#endif
47
+
48
+#if !defined(ELOG_FILTER_TAG_MAX_LEN)
49
+    #error "Please configure output filter's tag max length (in elog_cfg.h)"
50
+#endif
51
+
52
+#if !defined(ELOG_FILTER_KW_MAX_LEN)
53
+    #error "Please configure output filter's keyword max length (in elog_cfg.h)"
54
+#endif
55
+
56
+#if !defined(ELOG_NEWLINE_SIGN)
57
+    #error "Please configure output newline sign (in elog_cfg.h)"
58
+#endif
59
+
60
+/* output filter's tag level max num */
61
+#ifndef ELOG_FILTER_TAG_LVL_MAX_NUM
62
+#define ELOG_FILTER_TAG_LVL_MAX_NUM          4
63
+#endif
64
+
65
+#ifdef ELOG_COLOR_ENABLE
66
+/**
67
+ * CSI(Control Sequence Introducer/Initiator) sign
68
+ * more information on https://en.wikipedia.org/wiki/ANSI_escape_code
69
+ */
70
+#define CSI_START                      "\033["
71
+#define CSI_END                        "\033[0m"
72
+/* output log front color */
73
+#define F_BLACK                        "30;"
74
+#define F_RED                          "31;"
75
+#define F_GREEN                        "32;"
76
+#define F_YELLOW                       "33;"
77
+#define F_BLUE                         "34;"
78
+#define F_MAGENTA                      "35;"
79
+#define F_CYAN                         "36;"
80
+#define F_WHITE                        "37;"
81
+/* output log background color */
82
+#define B_NULL
83
+#define B_BLACK                        "40;"
84
+#define B_RED                          "41;"
85
+#define B_GREEN                        "42;"
86
+#define B_YELLOW                       "43;"
87
+#define B_BLUE                         "44;"
88
+#define B_MAGENTA                      "45;"
89
+#define B_CYAN                         "46;"
90
+#define B_WHITE                        "47;"
91
+/* output log fonts style */
92
+#define S_BOLD                         "1m"
93
+#define S_UNDERLINE                    "4m"
94
+#define S_BLINK                        "5m"
95
+#define S_NORMAL                       "22m"
96
+/* output log default color definition: [front color] + [background color] + [show style] */
97
+#ifndef ELOG_COLOR_ASSERT
98
+#define ELOG_COLOR_ASSERT              (F_MAGENTA B_NULL S_NORMAL)
99
+#endif
100
+#ifndef ELOG_COLOR_ERROR
101
+#define ELOG_COLOR_ERROR               (F_RED B_NULL S_NORMAL)
102
+#endif
103
+#ifndef ELOG_COLOR_WARN
104
+#define ELOG_COLOR_WARN                (F_YELLOW B_NULL S_NORMAL)
105
+#endif
106
+#ifndef ELOG_COLOR_INFO
107
+#define ELOG_COLOR_INFO                (F_CYAN B_NULL S_NORMAL)
108
+#endif
109
+#ifndef ELOG_COLOR_DEBUG
110
+#define ELOG_COLOR_DEBUG               (F_GREEN B_NULL S_NORMAL)
111
+#endif
112
+#ifndef ELOG_COLOR_VERBOSE
113
+#define ELOG_COLOR_VERBOSE             (F_BLUE B_NULL S_NORMAL)
114
+#endif
115
+#endif /* ELOG_COLOR_ENABLE */
116
+
117
+/* EasyLogger object */
118
+static EasyLogger elog;
119
+/* every line log's buffer */
120
+static char log_buf[ELOG_LINE_BUF_SIZE] = { 0 };
121
+/* level output info */
122
+static const char *level_output_info[] = {
123
+        [ELOG_LVL_ASSERT]  = "A/",
124
+        [ELOG_LVL_ERROR]   = "E/",
125
+        [ELOG_LVL_WARN]    = "W/",
126
+        [ELOG_LVL_INFO]    = "I/",
127
+        [ELOG_LVL_DEBUG]   = "D/",
128
+        [ELOG_LVL_VERBOSE] = "V/",
129
+};
130
+
131
+#ifdef ELOG_COLOR_ENABLE
132
+/* color output info */
133
+static const char *color_output_info[] = {
134
+        [ELOG_LVL_ASSERT]  = ELOG_COLOR_ASSERT,
135
+        [ELOG_LVL_ERROR]   = ELOG_COLOR_ERROR,
136
+        [ELOG_LVL_WARN]    = ELOG_COLOR_WARN,
137
+        [ELOG_LVL_INFO]    = ELOG_COLOR_INFO,
138
+        [ELOG_LVL_DEBUG]   = ELOG_COLOR_DEBUG,
139
+        [ELOG_LVL_VERBOSE] = ELOG_COLOR_VERBOSE,
140
+};
141
+#endif /* ELOG_COLOR_ENABLE */
142
+
143
+static bool get_fmt_enabled(uint8_t level, size_t set);
144
+static void elog_set_filter_tag_lvl_default();
145
+
146
+/* EasyLogger assert hook */
147
+void (*elog_assert_hook)(const char* expr, const char* func, size_t line);
148
+
149
+extern void elog_port_output(const char *log, size_t size);
150
+extern void elog_port_output_lock(void);
151
+extern void elog_port_output_unlock(void);
152
+
153
+/**
154
+ * EasyLogger initialize.
155
+ *
156
+ * @return result
157
+ */
158
+ElogErrCode elog_init(void) {
159
+    extern ElogErrCode elog_port_init(void);
160
+    extern ElogErrCode elog_async_init(void);
161
+
162
+    ElogErrCode result = ELOG_NO_ERR;
163
+
164
+    if (elog.init_ok == true) {
165
+        return result;
166
+    }
167
+
168
+    /* port initialize */
169
+    result = elog_port_init();
170
+    if (result != ELOG_NO_ERR) {
171
+        return result;
172
+    }
173
+
174
+#ifdef ELOG_ASYNC_OUTPUT_ENABLE
175
+    result = elog_async_init();
176
+    if (result != ELOG_NO_ERR) {
177
+        return result;
178
+    }
179
+#endif
180
+
181
+    /* enable the output lock */
182
+    elog_output_lock_enabled(true);
183
+    /* output locked status initialize */
184
+    elog.output_is_locked_before_enable = false;
185
+    elog.output_is_locked_before_disable = false;
186
+
187
+#ifdef ELOG_COLOR_ENABLE
188
+    /* disable text color by default */
189
+    elog_set_text_color_enabled(false);
190
+#endif
191
+
192
+    /* set level is ELOG_LVL_VERBOSE */
193
+    elog_set_filter_lvl(ELOG_LVL_VERBOSE);
194
+
195
+    /* set tag_level to default val */
196
+    elog_set_filter_tag_lvl_default();
197
+
198
+    elog.init_ok = true;
199
+
200
+    return result;
201
+}
202
+
203
+/**
204
+ * EasyLogger start after initialize.
205
+ */
206
+void elog_start(void) {
207
+    /* enable output */
208
+    elog_set_output_enabled(true);
209
+
210
+#if defined(ELOG_ASYNC_OUTPUT_ENABLE)
211
+    elog_async_enabled(true);
212
+#elif defined(ELOG_BUF_OUTPUT_ENABLE)
213
+    elog_buf_enabled(true);
214
+#endif
215
+
216
+    /* show version */
217
+    log_i("EasyLogger V%s is initialize success.", ELOG_SW_VERSION);
218
+}
219
+
220
+/**
221
+ * set output enable or disable
222
+ *
223
+ * @param enabled TRUE: enable FALSE: disable
224
+ */
225
+void elog_set_output_enabled(bool enabled) {
226
+    ELOG_ASSERT((enabled == false) || (enabled == true));
227
+
228
+    elog.output_enabled = enabled;
229
+}
230
+
231
+#ifdef ELOG_COLOR_ENABLE
232
+/**
233
+ * set log text color enable or disable
234
+ * 
235
+ * @param enabled TRUE: enable FALSE:disable
236
+ */
237
+void elog_set_text_color_enabled(bool enabled) {
238
+    elog.text_color_enabled = enabled;
239
+}
240
+
241
+/**
242
+ * get log text color enable status
243
+ *
244
+ * @return enable or disable
245
+ */
246
+bool elog_get_text_color_enabled(void) {
247
+    return elog.text_color_enabled;
248
+}
249
+#endif /* ELOG_COLOR_ENABLE */
250
+
251
+/**
252
+ * get output is enable or disable
253
+ *
254
+ * @return enable or disable
255
+ */
256
+bool elog_get_output_enabled(void) {
257
+    return elog.output_enabled;
258
+}
259
+
260
+/**
261
+ * set log output format. only enable or disable
262
+ *
263
+ * @param level level
264
+ * @param set format set
265
+ */
266
+void elog_set_fmt(uint8_t level, size_t set) {
267
+    ELOG_ASSERT(level <= ELOG_LVL_VERBOSE);
268
+
269
+    elog.enabled_fmt_set[level] = set;
270
+}
271
+
272
+/**
273
+ * set log filter all parameter
274
+ *
275
+ * @param level level
276
+ * @param tag tag
277
+ * @param keyword keyword
278
+ */
279
+void elog_set_filter(uint8_t level, const char *tag, const char *keyword) {
280
+    ELOG_ASSERT(level <= ELOG_LVL_VERBOSE);
281
+
282
+    elog_set_filter_lvl(level);
283
+    elog_set_filter_tag(tag);
284
+    elog_set_filter_kw(keyword);
285
+}
286
+
287
+/**
288
+ * set log filter's level
289
+ *
290
+ * @param level level
291
+ */
292
+void elog_set_filter_lvl(uint8_t level) {
293
+    ELOG_ASSERT(level <= ELOG_LVL_VERBOSE);
294
+
295
+    elog.filter.level = level;
296
+}
297
+
298
+/**
299
+ * set log filter's tag
300
+ *
301
+ * @param tag tag
302
+ */
303
+void elog_set_filter_tag(const char *tag) {
304
+    strncpy(elog.filter.tag, tag, ELOG_FILTER_TAG_MAX_LEN);
305
+}
306
+
307
+/**
308
+ * set log filter's keyword
309
+ *
310
+ * @param keyword keyword
311
+ */
312
+void elog_set_filter_kw(const char *keyword) {
313
+    strncpy(elog.filter.keyword, keyword, ELOG_FILTER_KW_MAX_LEN);
314
+}
315
+
316
+/**
317
+ * lock output 
318
+ */
319
+void elog_output_lock(void) {
320
+    if (elog.output_lock_enabled) {
321
+        elog_port_output_lock();
322
+        elog.output_is_locked_before_disable = true;
323
+    } else {
324
+        elog.output_is_locked_before_enable = true;
325
+    }
326
+}
327
+
328
+/**
329
+ * unlock output
330
+ */
331
+void elog_output_unlock(void) {
332
+    if (elog.output_lock_enabled) {
333
+        elog_port_output_unlock();
334
+        elog.output_is_locked_before_disable = false;
335
+    } else {
336
+        elog.output_is_locked_before_enable = false;
337
+    }
338
+}
339
+
340
+/**
341
+ * set log filter's tag level val to default
342
+ */
343
+static void elog_set_filter_tag_lvl_default()
344
+{
345
+    uint8_t i = 0;
346
+
347
+    for (i =0; i< ELOG_FILTER_TAG_LVL_MAX_NUM; i++){
348
+        memset(elog.filter.tag_lvl[i].tag, '\0', ELOG_FILTER_TAG_MAX_LEN + 1);
349
+        elog.filter.tag_lvl[i].level = ELOG_FILTER_LVL_SILENT;
350
+        elog.filter.tag_lvl[i].tag_use_flag = false;
351
+    }
352
+}
353
+
354
+/**
355
+ * Set the filter's level by different tag.
356
+ * The log on this tag which level is less than it will stop output.
357
+ *
358
+ * example:
359
+ *     // the example tag log enter silent mode
360
+ *     elog_set_filter_tag_lvl("example", ELOG_FILTER_LVL_SILENT);
361
+ *     // the example tag log which level is less than INFO level will stop output
362
+ *     elog_set_filter_tag_lvl("example", ELOG_LVL_INFO);
363
+ *     // remove example tag's level filter, all level log will resume output
364
+ *     elog_set_filter_tag_lvl("example", ELOG_FILTER_LVL_ALL);
365
+ *
366
+ * @param tag log tag
367
+ * @param level The filter level. When the level is ELOG_FILTER_LVL_SILENT, the log enter silent mode.
368
+ *        When the level is ELOG_FILTER_LVL_ALL, it will remove this tag's level filer.
369
+ *        Then all level log will resume output.
370
+ *
371
+ */
372
+void elog_set_filter_tag_lvl(const char *tag, uint8_t level)
373
+{
374
+    ELOG_ASSERT(level <= ELOG_LVL_VERBOSE);
375
+    ELOG_ASSERT(tag != ((void *)0));
376
+    uint8_t i = 0;
377
+
378
+    if (!elog.init_ok) {
379
+        return;
380
+    }
381
+
382
+    elog_port_output_lock();
383
+    /* find the tag in arr */
384
+    for (i =0; i< ELOG_FILTER_TAG_LVL_MAX_NUM; i++){
385
+        if (elog.filter.tag_lvl[i].tag_use_flag == true &&
386
+            !strncmp(tag, elog.filter.tag_lvl[i].tag,ELOG_FILTER_TAG_MAX_LEN)){
387
+            break;
388
+        }
389
+    }
390
+
391
+    if (i < ELOG_FILTER_TAG_LVL_MAX_NUM){
392
+        /* find OK */
393
+        if (level == ELOG_FILTER_LVL_ALL){
394
+            /* remove current tag's level filter when input level is the lowest level */
395
+             elog.filter.tag_lvl[i].tag_use_flag = false;
396
+             memset(elog.filter.tag_lvl[i].tag, '\0', ELOG_FILTER_TAG_MAX_LEN + 1);
397
+             elog.filter.tag_lvl[i].level = ELOG_FILTER_LVL_SILENT;
398
+        } else{
399
+            elog.filter.tag_lvl[i].level = level;
400
+        }
401
+    } else{
402
+        /* only add the new tag's level filer when level is not ELOG_FILTER_LVL_ALL */
403
+        if (level != ELOG_FILTER_LVL_ALL){
404
+            for (i =0; i< ELOG_FILTER_TAG_LVL_MAX_NUM; i++){
405
+                if (elog.filter.tag_lvl[i].tag_use_flag == false){
406
+                    strncpy(elog.filter.tag_lvl[i].tag, tag, ELOG_FILTER_TAG_MAX_LEN);
407
+                    elog.filter.tag_lvl[i].level = level;
408
+                    elog.filter.tag_lvl[i].tag_use_flag = true;
409
+                    break;
410
+                }
411
+            }
412
+        }
413
+    }
414
+    elog_output_unlock();
415
+}
416
+
417
+/**
418
+ * get the level on tag's level filer
419
+ *
420
+ * @param tag tag
421
+ *
422
+ * @return It will return the lowest level when tag was not found.
423
+ *         Other level will return when tag was found.
424
+ */
425
+uint8_t elog_get_filter_tag_lvl(const char *tag)
426
+{
427
+    ELOG_ASSERT(tag != ((void *)0));
428
+    uint8_t i = 0;
429
+    uint8_t level = ELOG_FILTER_LVL_ALL;
430
+
431
+    if (!elog.init_ok) {
432
+        return level;
433
+    }
434
+
435
+    elog_port_output_lock();
436
+    /* find the tag in arr */
437
+    for (i =0; i< ELOG_FILTER_TAG_LVL_MAX_NUM; i++){
438
+        if (elog.filter.tag_lvl[i].tag_use_flag == true &&
439
+            !strncmp(tag, elog.filter.tag_lvl[i].tag,ELOG_FILTER_TAG_MAX_LEN)){
440
+            level = elog.filter.tag_lvl[i].level;
441
+            break;
442
+        }
443
+    }
444
+    elog_output_unlock();
445
+
446
+    return level;
447
+}
448
+
449
+/**
450
+ * output RAW format log
451
+ *
452
+ * @param format output format
453
+ * @param ... args
454
+ */
455
+void elog_raw(const char *format, ...) {
456
+    va_list args;
457
+    size_t log_len = 0;
458
+    int fmt_result;
459
+
460
+    /* check output enabled */
461
+    if (!elog.output_enabled) {
462
+        return;
463
+    }
464
+
465
+    /* args point to the first variable parameter */
466
+    va_start(args, format);
467
+
468
+    /* lock output */
469
+    elog_output_lock();
470
+
471
+    /* package log data to buffer */
472
+    fmt_result = vsnprintf(log_buf, ELOG_LINE_BUF_SIZE, format, args);
473
+
474
+    /* output converted log */
475
+    if ((fmt_result > -1) && (fmt_result <= ELOG_LINE_BUF_SIZE)) {
476
+        log_len = fmt_result;
477
+    } else {
478
+        log_len = ELOG_LINE_BUF_SIZE;
479
+    }
480
+    /* output log */
481
+#if defined(ELOG_ASYNC_OUTPUT_ENABLE)
482
+    extern void elog_async_output(uint8_t level, const char *log, size_t size);
483
+    /* raw log will using assert level */
484
+    elog_async_output(ELOG_LVL_ASSERT, log_buf, log_len);
485
+#elif defined(ELOG_BUF_OUTPUT_ENABLE)
486
+    extern void elog_buf_output(const char *log, size_t size);
487
+    elog_buf_output(log_buf, log_len);
488
+#else
489
+    elog_port_output(log_buf, log_len);
490
+#endif
491
+    /* unlock output */
492
+    elog_output_unlock();
493
+
494
+    va_end(args);
495
+}
496
+
497
+/**
498
+ * output the log
499
+ *
500
+ * @param level level
501
+ * @param tag tag
502
+ * @param file file name
503
+ * @param func function name
504
+ * @param line line number
505
+ * @param format output format
506
+ * @param ... args
507
+ *
508
+ */
509
+void elog_output(uint8_t level, const char *tag, const char *file, const char *func,
510
+        const long line, const char *format, ...) {
511
+    extern const char *elog_port_get_time(void);
512
+    extern const char *elog_port_get_p_info(void);
513
+    extern const char *elog_port_get_t_info(void);
514
+
515
+    size_t tag_len = strlen(tag), log_len = 0, newline_len = strlen(ELOG_NEWLINE_SIGN);
516
+    char line_num[ELOG_LINE_NUM_MAX_LEN + 1] = { 0 };
517
+    char tag_sapce[ELOG_FILTER_TAG_MAX_LEN / 2 + 1] = { 0 };
518
+    va_list args;
519
+    int fmt_result;
520
+
521
+    ELOG_ASSERT(level <= ELOG_LVL_VERBOSE);
522
+
523
+    /* check output enabled */
524
+    if (!elog.output_enabled) {
525
+        return;
526
+    }
527
+    /* level filter */
528
+    if (level > elog.filter.level || level > elog_get_filter_tag_lvl(tag)) {
529
+        return;
530
+    } else if (!strstr(tag, elog.filter.tag)) { /* tag filter */
531
+        return;
532
+    }
533
+    /* args point to the first variable parameter */
534
+    va_start(args, format);
535
+    /* lock output */
536
+    elog_output_lock();
537
+
538
+#ifdef ELOG_COLOR_ENABLE
539
+    /* add CSI start sign and color info */
540
+    if (elog.text_color_enabled) {
541
+        log_len += elog_strcpy(log_len, log_buf + log_len, CSI_START);
542
+        log_len += elog_strcpy(log_len, log_buf + log_len, color_output_info[level]);
543
+    }
544
+#endif
545
+
546
+    /* package level info */
547
+    if (get_fmt_enabled(level, ELOG_FMT_LVL)) {
548
+        log_len += elog_strcpy(log_len, log_buf + log_len, level_output_info[level]);
549
+    }
550
+    /* package tag info */
551
+    if (get_fmt_enabled(level, ELOG_FMT_TAG)) {
552
+        log_len += elog_strcpy(log_len, log_buf + log_len, tag);
553
+        /* if the tag length is less than 50% ELOG_FILTER_TAG_MAX_LEN, then fill space */
554
+        if (tag_len <= ELOG_FILTER_TAG_MAX_LEN / 2) {
555
+            memset(tag_sapce, ' ', ELOG_FILTER_TAG_MAX_LEN / 2 - tag_len);
556
+            log_len += elog_strcpy(log_len, log_buf + log_len, tag_sapce);
557
+        }
558
+        log_len += elog_strcpy(log_len, log_buf + log_len, " ");
559
+    }
560
+    /* package time, process and thread info */
561
+    if (get_fmt_enabled(level, ELOG_FMT_TIME | ELOG_FMT_P_INFO | ELOG_FMT_T_INFO)) {
562
+        log_len += elog_strcpy(log_len, log_buf + log_len, "[");
563
+        /* package time info */
564
+        if (get_fmt_enabled(level, ELOG_FMT_TIME)) {
565
+            log_len += elog_strcpy(log_len, log_buf + log_len, elog_port_get_time());
566
+            if (get_fmt_enabled(level, ELOG_FMT_P_INFO | ELOG_FMT_T_INFO)) {
567
+                log_len += elog_strcpy(log_len, log_buf + log_len, " ");
568
+            }
569
+        }
570
+        /* package process info */
571
+        if (get_fmt_enabled(level, ELOG_FMT_P_INFO)) {
572
+            log_len += elog_strcpy(log_len, log_buf + log_len, elog_port_get_p_info());
573
+            if (get_fmt_enabled(level, ELOG_FMT_T_INFO)) {
574
+                log_len += elog_strcpy(log_len, log_buf + log_len, " ");
575
+            }
576
+        }
577
+        /* package thread info */
578
+        if (get_fmt_enabled(level, ELOG_FMT_T_INFO)) {
579
+            log_len += elog_strcpy(log_len, log_buf + log_len, elog_port_get_t_info());
580
+        }
581
+        log_len += elog_strcpy(log_len, log_buf + log_len, "] ");
582
+    }
583
+    /* package file directory and name, function name and line number info */
584
+    if (get_fmt_enabled(level, ELOG_FMT_DIR | ELOG_FMT_FUNC | ELOG_FMT_LINE)) {
585
+        log_len += elog_strcpy(log_len, log_buf + log_len, "(");
586
+        /* package time info */
587
+        if (get_fmt_enabled(level, ELOG_FMT_DIR)) {
588
+            log_len += elog_strcpy(log_len, log_buf + log_len, file);
589
+            if (get_fmt_enabled(level, ELOG_FMT_FUNC)) {
590
+                log_len += elog_strcpy(log_len, log_buf + log_len, " ");
591
+            } else if (get_fmt_enabled(level, ELOG_FMT_LINE)) {
592
+                log_len += elog_strcpy(log_len, log_buf + log_len, ":");
593
+            }
594
+        }
595
+        /* package process info */
596
+        if (get_fmt_enabled(level, ELOG_FMT_FUNC)) {
597
+            log_len += elog_strcpy(log_len, log_buf + log_len, func);
598
+            if (get_fmt_enabled(level, ELOG_FMT_LINE)) {
599
+                log_len += elog_strcpy(log_len, log_buf + log_len, ":");
600
+            }
601
+        }
602
+        /* package thread info */
603
+        if (get_fmt_enabled(level, ELOG_FMT_LINE)) {
604
+            snprintf(line_num, ELOG_LINE_NUM_MAX_LEN, "%ld", line);
605
+            log_len += elog_strcpy(log_len, log_buf + log_len, line_num);
606
+        }
607
+        log_len += elog_strcpy(log_len, log_buf + log_len, ")");
608
+    }
609
+    /* package other log data to buffer. '\0' must be added in the end by vsnprintf. */
610
+    fmt_result = vsnprintf(log_buf + log_len, ELOG_LINE_BUF_SIZE - log_len, format, args);
611
+
612
+    va_end(args);
613
+    /* calculate log length */
614
+    if ((log_len + fmt_result <= ELOG_LINE_BUF_SIZE) && (fmt_result > -1)) {
615
+        log_len += fmt_result;
616
+    } else {
617
+        /* using max length */
618
+        log_len = ELOG_LINE_BUF_SIZE;
619
+    }
620
+    /* overflow check and reserve some space for CSI end sign and newline sign */
621
+#ifdef ELOG_COLOR_ENABLE
622
+    if (log_len + (sizeof(CSI_END) - 1) + newline_len > ELOG_LINE_BUF_SIZE) {
623
+        /* using max length */
624
+        log_len = ELOG_LINE_BUF_SIZE;
625
+        /* reserve some space for CSI end sign */
626
+        log_len -= (sizeof(CSI_END) - 1);
627
+#else
628
+    if (log_len + newline_len > ELOG_LINE_BUF_SIZE) {
629
+        /* using max length */
630
+        log_len = ELOG_LINE_BUF_SIZE;
631
+#endif /* ELOG_COLOR_ENABLE */
632
+        /* reserve some space for newline sign */
633
+        log_len -= newline_len;
634
+    }
635
+    /* keyword filter */
636
+    if (elog.filter.keyword[0] != '\0') {
637
+        /* add string end sign */
638
+        log_buf[log_len] = '\0';
639
+        /* find the keyword */
640
+        if (!strstr(log_buf, elog.filter.keyword)) {
641
+            /* unlock output */
642
+            elog_output_unlock();
643
+            return;
644
+        }
645
+    }
646
+
647
+#ifdef ELOG_COLOR_ENABLE
648
+    /* add CSI end sign */
649
+    if (elog.text_color_enabled) {
650
+        log_len += elog_strcpy(log_len, log_buf + log_len, CSI_END);
651
+    }
652
+#endif
653
+
654
+    /* package newline sign */
655
+    log_len += elog_strcpy(log_len, log_buf + log_len, ELOG_NEWLINE_SIGN);
656
+    /* output log */
657
+#if defined(ELOG_ASYNC_OUTPUT_ENABLE)
658
+    extern void elog_async_output(uint8_t level, const char *log, size_t size);
659
+    elog_async_output(level, log_buf, log_len);
660
+#elif defined(ELOG_BUF_OUTPUT_ENABLE)
661
+    extern void elog_buf_output(const char *log, size_t size);
662
+    elog_buf_output(log_buf, log_len);
663
+#else
664
+    elog_port_output(log_buf, log_len);
665
+#endif
666
+    /* unlock output */
667
+    elog_output_unlock();
668
+}
669
+
670
+/**
671
+ * get format enabled
672
+ *
673
+ * @param level level
674
+ * @param set format set
675
+ *
676
+ * @return enable or disable
677
+ */
678
+static bool get_fmt_enabled(uint8_t level, size_t set) {
679
+    ELOG_ASSERT(level <= ELOG_LVL_VERBOSE);
680
+
681
+    if (elog.enabled_fmt_set[level] & set) {
682
+        return true;
683
+    } else {
684
+        return false;
685
+    }
686
+}
687
+
688
+/**
689
+ * enable or disable logger output lock
690
+ * @note disable this lock is not recommended except you want output system exception log
691
+ *
692
+ * @param enabled true: enable  false: disable
693
+ */
694
+void elog_output_lock_enabled(bool enabled) {
695
+    elog.output_lock_enabled = enabled;
696
+    /* it will re-lock or re-unlock before output lock enable */
697
+    if (elog.output_lock_enabled) {
698
+        if (!elog.output_is_locked_before_disable && elog.output_is_locked_before_enable) {
699
+            /* the output lock is unlocked before disable, and the lock will unlocking after enable */
700
+            elog_port_output_lock();
701
+        } else if (elog.output_is_locked_before_disable && !elog.output_is_locked_before_enable) {
702
+            /* the output lock is locked before disable, and the lock will locking after enable */
703
+            elog_port_output_unlock();
704
+        }
705
+    }
706
+}
707
+
708
+/**
709
+ * Set a hook function to EasyLogger assert. It will run when the expression is false.
710
+ *
711
+ * @param hook the hook function
712
+ */
713
+void elog_assert_set_hook(void (*hook)(const char* expr, const char* func, size_t line)) {
714
+    elog_assert_hook = hook;
715
+}
716
+
717
+/**
718
+ * find the log level
719
+ * @note make sure the log level is output on each format
720
+ *
721
+ * @param log log buffer
722
+ *
723
+ * @return log level, found failed will return -1
724
+ */
725
+int8_t elog_find_lvl(const char *log) {
726
+    ELOG_ASSERT(log);
727
+    /* make sure the log level is output on each format */
728
+    ELOG_ASSERT(elog.enabled_fmt_set[ELOG_LVL_ASSERT] & ELOG_FMT_LVL);
729
+    ELOG_ASSERT(elog.enabled_fmt_set[ELOG_LVL_ERROR] & ELOG_FMT_LVL);
730
+    ELOG_ASSERT(elog.enabled_fmt_set[ELOG_LVL_WARN] & ELOG_FMT_LVL);
731
+    ELOG_ASSERT(elog.enabled_fmt_set[ELOG_LVL_INFO] & ELOG_FMT_LVL);
732
+    ELOG_ASSERT(elog.enabled_fmt_set[ELOG_LVL_DEBUG] & ELOG_FMT_LVL);
733
+    ELOG_ASSERT(elog.enabled_fmt_set[ELOG_LVL_VERBOSE] & ELOG_FMT_LVL);
734
+
735
+#ifdef ELOG_COLOR_ENABLE
736
+    uint8_t i;
737
+    size_t csi_start_len = strlen(CSI_START);
738
+    for(i = 0; i < ELOG_LVL_TOTAL_NUM; i ++) {
739
+        if (!strncmp(color_output_info[i], log + csi_start_len, strlen(color_output_info[i]))) {
740
+            return i;
741
+        }
742
+    }
743
+    /* found failed */
744
+    return -1;
745
+#else
746
+    switch (log[0]) {
747
+    case 'A': return ELOG_LVL_ASSERT;
748
+    case 'E': return ELOG_LVL_ERROR;
749
+    case 'W': return ELOG_LVL_WARN;
750
+    case 'I': return ELOG_LVL_INFO;
751
+    case 'D': return ELOG_LVL_DEBUG;
752
+    case 'V': return ELOG_LVL_VERBOSE;
753
+    default: return -1;
754
+    }
755
+#endif
756
+}
757
+
758
+/**
759
+ * find the log tag
760
+ * @note make sure the log tag is output on each format
761
+ * @note the tag don't have space in it
762
+ *
763
+ * @param log log buffer
764
+ * @param lvl log level, you can get it by @see elog_find_lvl
765
+ * @param tag_len found tag length
766
+ *
767
+ * @return log tag, found failed will return NULL
768
+ */
769
+const char *elog_find_tag(const char *log, uint8_t lvl, size_t *tag_len) {
770
+    const char *tag = NULL, *tag_end = NULL;
771
+
772
+    ELOG_ASSERT(log);
773
+    ELOG_ASSERT(tag_len);
774
+    ELOG_ASSERT(lvl < ELOG_LVL_TOTAL_NUM);
775
+    /* make sure the log tag is output on each format */
776
+    ELOG_ASSERT(elog.enabled_fmt_set[lvl] & ELOG_FMT_TAG);
777
+
778
+#ifdef ELOG_COLOR_ENABLE
779
+    tag = log + strlen(CSI_START) + strlen(color_output_info[lvl]) + strlen(level_output_info[lvl]);
780
+#else
781
+    tag = log + strlen(level_output_info[lvl]);
782
+#endif
783
+    /* find the first space after tag */
784
+    if ((tag_end = memchr(tag, ' ', ELOG_FILTER_TAG_MAX_LEN)) != NULL) {
785
+        *tag_len = tag_end - tag;
786
+    } else {
787
+        tag = NULL;
788
+    }
789
+
790
+    return tag;
791
+}
792
+
793
+/**
794
+ * dump the hex format data to log
795
+ *
796
+ * @param name name for hex object, it will show on log header
797
+ * @param width hex number for every line, such as: 16, 32
798
+ * @param buf hex buffer
799
+ * @param size buffer size
800
+ */
801
+void elog_hexdump(const char *name, uint8_t width, uint8_t *buf, uint16_t size)
802
+{
803
+#define __is_print(ch)       ((unsigned int)((ch) - ' ') < 127u - ' ')
804
+
805
+    uint16_t i, j;
806
+    uint16_t log_len = 0;
807
+    char dump_string[8] = {0};
808
+    int fmt_result;
809
+
810
+    if (!elog.output_enabled) {
811
+        return;
812
+    }
813
+
814
+    /* level filter */
815
+    if (ELOG_LVL_DEBUG > elog.filter.level) {
816
+        return;
817
+    } else if (!strstr(name, elog.filter.tag)) { /* tag filter */
818
+        return;
819
+    }
820
+
821
+    /* lock output */
822
+    elog_output_lock();
823
+
824
+    for (i = 0; i < size; i += width) {
825
+        /* package header */
826
+        fmt_result = snprintf(log_buf, ELOG_LINE_BUF_SIZE, "D/HEX %s: %04X-%04X: ", name, i, i + width - 1);
827
+        /* calculate log length */
828
+        if ((fmt_result > -1) && (fmt_result <= ELOG_LINE_BUF_SIZE)) {
829
+            log_len = fmt_result;
830
+        } else {
831
+            log_len = ELOG_LINE_BUF_SIZE;
832
+        }
833
+        /* dump hex */
834
+        for (j = 0; j < width; j++) {
835
+            if (i + j < size) {
836
+                snprintf(dump_string, sizeof(dump_string), "%02X ", buf[i + j]);
837
+            } else {
838
+                strncpy(dump_string, "   ", sizeof(dump_string));
839
+            }
840
+            log_len += elog_strcpy(log_len, log_buf + log_len, dump_string);
841
+            if ((j + 1) % 8 == 0) {
842
+                log_len += elog_strcpy(log_len, log_buf + log_len, " ");
843
+            }
844
+        }
845
+        log_len += elog_strcpy(log_len, log_buf + log_len, "  ");
846
+        /* dump char for hex */
847
+        for (j = 0; j < width; j++) {
848
+            if (i + j < size) {
849
+                snprintf(dump_string, sizeof(dump_string), "%c", __is_print(buf[i + j]) ? buf[i + j] : '.');
850
+                log_len += elog_strcpy(log_len, log_buf + log_len, dump_string);
851
+            }
852
+        }
853
+        /* overflow check and reserve some space for newline sign */
854
+        if (log_len + strlen(ELOG_NEWLINE_SIGN) > ELOG_LINE_BUF_SIZE) {
855
+            log_len = ELOG_LINE_BUF_SIZE - strlen(ELOG_NEWLINE_SIGN);
856
+        }
857
+        /* package newline sign */
858
+        log_len += elog_strcpy(log_len, log_buf + log_len, ELOG_NEWLINE_SIGN);
859
+        /* do log output */
860
+#if defined(ELOG_ASYNC_OUTPUT_ENABLE)
861
+        extern void elog_async_output(uint8_t level, const char *log, size_t size);
862
+        elog_async_output(ELOG_LVL_DEBUG, log_buf, log_len);
863
+#elif defined(ELOG_BUF_OUTPUT_ENABLE)
864
+        extern void elog_buf_output(const char *log, size_t size);
865
+    elog_buf_output(log_buf, log_len);
866
+#else
867
+        elog_port_output(log_buf, log_len);
868
+#endif
869
+    }
870
+    /* unlock output */
871
+    elog_output_unlock();
872
+}

+ 352
- 0
util/easylogger/src/elog_async.c Прегледај датотеку

@@ -0,0 +1,352 @@
1
+/*
2
+ * This file is part of the EasyLogger Library.
3
+ *
4
+ * Copyright (c) 2016-2017, Armink, <armink.ztl@gmail.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * 'Software'), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * Function: Logs asynchronous output.
26
+ * Created on: 2016-11-06
27
+ */
28
+
29
+#include <elog.h>
30
+#include <string.h>
31
+
32
+#ifdef ELOG_ASYNC_OUTPUT_ENABLE
33
+
34
+#ifdef ELOG_ASYNC_OUTPUT_USING_PTHREAD
35
+#include <pthread.h>
36
+#include <sched.h>
37
+#include <semaphore.h>
38
+/* thread default stack size */
39
+#ifndef ELOG_ASYNC_OUTPUT_PTHREAD_STACK_SIZE
40
+#if PTHREAD_STACK_MIN > 4*1024
41
+#define ELOG_ASYNC_OUTPUT_PTHREAD_STACK_SIZE     PTHREAD_STACK_MIN
42
+#else
43
+#define ELOG_ASYNC_OUTPUT_PTHREAD_STACK_SIZE     (1*1024)
44
+#endif
45
+/* thread default priority */
46
+#ifndef ELOG_ASYNC_OUTPUT_PTHREAD_PRIORITY
47
+#define ELOG_ASYNC_OUTPUT_PTHREAD_PRIORITY       (sched_get_priority_max(SCHED_RR) - 1)
48
+#endif
49
+/* output thread poll get log buffer size  */
50
+#ifndef ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE
51
+#define ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE         (ELOG_LINE_BUF_SIZE - 4)
52
+#endif
53
+#endif /* ELOG_ASYNC_OUTPUT_USING_PTHREAD */
54
+
55
+/* asynchronous output log notice */
56
+static sem_t output_notice;
57
+/* asynchronous output pthread thread */
58
+static pthread_t async_output_thread;
59
+#endif /* ELOG_ASYNC_OUTPUT_USING_PTHREAD */
60
+
61
+/* the highest output level for async mode, other level will sync output */
62
+#ifdef ELOG_ASYNC_OUTPUT_LVL
63
+#define OUTPUT_LVL                               ELOG_ASYNC_OUTPUT_LVL
64
+#else
65
+#define OUTPUT_LVL                               ELOG_LVL_ASSERT
66
+#endif /* ELOG_ASYNC_OUTPUT_LVL */
67
+
68
+/* buffer size for asynchronous output mode */
69
+#ifdef ELOG_ASYNC_OUTPUT_BUF_SIZE
70
+#define OUTPUT_BUF_SIZE                          ELOG_ASYNC_OUTPUT_BUF_SIZE
71
+#else
72
+#define OUTPUT_BUF_SIZE                          (ELOG_LINE_BUF_SIZE * 10)
73
+#endif /* ELOG_ASYNC_OUTPUT_BUF_SIZE */
74
+
75
+/* Initialize OK flag */
76
+static bool init_ok = false;
77
+/* asynchronous output mode enabled flag */
78
+static bool is_enabled = false;
79
+/* asynchronous output mode's ring buffer */
80
+static char log_buf[OUTPUT_BUF_SIZE] = { 0 };
81
+/* log ring buffer write index */
82
+static size_t write_index = 0;
83
+/* log ring buffer read index */
84
+static size_t read_index = 0;
85
+/* log ring buffer full flag */
86
+static bool buf_is_full = false;
87
+/* log ring buffer empty flag */
88
+static bool buf_is_empty = true;
89
+
90
+extern void elog_port_output(const char *log, size_t size);
91
+extern void elog_output_lock(void);
92
+extern void elog_output_unlock(void);
93
+
94
+/**
95
+ * asynchronous output ring buffer used size
96
+ *
97
+ * @return used size
98
+ */
99
+static size_t elog_async_get_buf_used(void) {
100
+    if (write_index > read_index) {
101
+        return write_index - read_index;
102
+    } else {
103
+        if (!buf_is_full && !buf_is_empty) {
104
+            return OUTPUT_BUF_SIZE - (read_index - write_index);
105
+        } else if (buf_is_full) {
106
+            return OUTPUT_BUF_SIZE;
107
+        } else {
108
+            return 0;
109
+        }
110
+    }
111
+}
112
+
113
+/**
114
+ * asynchronous output ring buffer remain space
115
+ *
116
+ * @return remain space
117
+ */
118
+static size_t async_get_buf_space(void) {
119
+    return OUTPUT_BUF_SIZE - elog_async_get_buf_used();
120
+}
121
+
122
+/**
123
+ * put log to asynchronous output ring buffer
124
+ *
125
+ * @param log put log buffer
126
+ * @param size log size
127
+ *
128
+ * @return put log size, the log which beyond ring buffer space will be dropped
129
+ */
130
+static size_t async_put_log(const char *log, size_t size) {
131
+    size_t space = 0;
132
+
133
+    space = async_get_buf_space();
134
+    /* no space */
135
+    if (!space) {
136
+        size = 0;
137
+        goto __exit;
138
+    }
139
+    /* drop some log */
140
+    if (space <= size) {
141
+        size = space;
142
+        buf_is_full = true;
143
+    }
144
+
145
+    if (write_index + size < OUTPUT_BUF_SIZE) {
146
+        memcpy(log_buf + write_index, log, size);
147
+        write_index += size;
148
+    } else {
149
+        memcpy(log_buf + write_index, log, OUTPUT_BUF_SIZE - write_index);
150
+        memcpy(log_buf, log + OUTPUT_BUF_SIZE - write_index,
151
+                size - (OUTPUT_BUF_SIZE - write_index));
152
+        write_index += size - OUTPUT_BUF_SIZE;
153
+    }
154
+
155
+    buf_is_empty = false;
156
+
157
+__exit:
158
+
159
+    return size;
160
+}
161
+
162
+#ifdef ELOG_ASYNC_LINE_OUTPUT
163
+/**
164
+ * Get line log from asynchronous output ring buffer.
165
+ * It will copy all log when the newline sign isn't find.
166
+ *
167
+ * @param log get line log buffer
168
+ * @param size line log size
169
+ *
170
+ * @return get line log size, the log size is less than ring buffer used size
171
+ */
172
+size_t elog_async_get_line_log(char *log, size_t size) {
173
+    size_t used = 0, cpy_log_size = 0;
174
+    /* lock output */
175
+    elog_output_lock();
176
+    used = elog_async_get_buf_used();
177
+
178
+    /* no log */
179
+    if (!used || !size) {
180
+        goto __exit;
181
+    }
182
+    /* less log */
183
+    if (used <= size) {
184
+        size = used;
185
+    }
186
+
187
+    if (read_index + size < OUTPUT_BUF_SIZE) {
188
+        cpy_log_size = elog_cpyln(log, log_buf + read_index, size);
189
+        read_index += cpy_log_size;
190
+    } else {
191
+        cpy_log_size = elog_cpyln(log, log_buf + read_index, OUTPUT_BUF_SIZE - read_index);
192
+        if (cpy_log_size == OUTPUT_BUF_SIZE - read_index) {
193
+            cpy_log_size += elog_cpyln(log + cpy_log_size, log_buf, size - cpy_log_size);
194
+            read_index += cpy_log_size - OUTPUT_BUF_SIZE;
195
+        } else {
196
+            read_index += cpy_log_size;
197
+        }
198
+    }
199
+
200
+    if (used == cpy_log_size) {
201
+        buf_is_empty = true;
202
+    }
203
+
204
+    if (cpy_log_size) {
205
+        buf_is_full = false;
206
+    }
207
+
208
+__exit:
209
+    /* lock output */
210
+    elog_output_unlock();
211
+    return cpy_log_size;
212
+}
213
+#else
214
+/**
215
+ * get log from asynchronous output ring buffer
216
+ *
217
+ * @param log get log buffer
218
+ * @param size log size
219
+ *
220
+ * @return get log size, the log size is less than ring buffer used size
221
+ */
222
+size_t elog_async_get_log(char *log, size_t size) {
223
+    size_t used = 0;
224
+    /* lock output */
225
+    elog_output_lock();
226
+    used = elog_async_get_buf_used();
227
+    /* no log */
228
+    if (!used || !size) {
229
+        size = 0;
230
+        goto __exit;
231
+    }
232
+    /* less log */
233
+    if (used <= size) {
234
+        size = used;
235
+        buf_is_empty = true;
236
+    }
237
+
238
+    if (read_index + size < OUTPUT_BUF_SIZE) {
239
+        memcpy(log, log_buf + read_index, size);
240
+        read_index += size;
241
+    } else {
242
+        memcpy(log, log_buf + read_index, OUTPUT_BUF_SIZE - read_index);
243
+        memcpy(log + OUTPUT_BUF_SIZE - read_index, log_buf,
244
+                size - (OUTPUT_BUF_SIZE - read_index));
245
+        read_index += size - OUTPUT_BUF_SIZE;
246
+    }
247
+
248
+    buf_is_full = false;
249
+
250
+__exit:
251
+    /* lock output */
252
+    elog_output_unlock();
253
+    return size;
254
+}
255
+#endif /* ELOG_ASYNC_LINE_OUTPUT */
256
+
257
+void elog_async_output(uint8_t level, const char *log, size_t size) {
258
+    /* this function must be implement by user when ELOG_ASYNC_OUTPUT_USING_PTHREAD is not defined */
259
+    extern void elog_async_output_notice(void);
260
+    size_t put_size;
261
+
262
+    if (is_enabled) {
263
+        if (level >= OUTPUT_LVL) {
264
+            put_size = async_put_log(log, size);
265
+            /* notify output log thread */
266
+            if (put_size > 0) {
267
+                elog_async_output_notice();
268
+            }
269
+        } else {
270
+            elog_port_output(log, size);
271
+        }
272
+    } else {
273
+        elog_port_output(log, size);
274
+    }
275
+}
276
+
277
+#ifdef ELOG_ASYNC_OUTPUT_USING_PTHREAD
278
+void elog_async_output_notice(void) {
279
+    sem_post(&output_notice);
280
+}
281
+
282
+static void *async_output(void *arg) {
283
+    size_t get_log_size = 0;
284
+    static char poll_get_buf[ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE];
285
+
286
+    while(true) {
287
+        /* waiting log */
288
+        sem_wait(&output_notice);
289
+        /* polling gets and outputs the log */
290
+        while(true) {
291
+
292
+#ifdef ELOG_ASYNC_LINE_OUTPUT
293
+            get_log_size = elog_async_get_line_log(poll_get_buf, ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE);
294
+#else
295
+            get_log_size = elog_async_get_log(poll_get_buf, ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE);
296
+#endif
297
+
298
+            if (get_log_size) {
299
+                elog_port_output(poll_get_buf, get_log_size);
300
+            } else {
301
+                break;
302
+            }
303
+        }
304
+    }
305
+    return NULL;
306
+}
307
+#endif
308
+
309
+/**
310
+ * enable or disable asynchronous output mode
311
+ * the log will be output directly when mode is disabled
312
+ *
313
+ * @param enabled true: enabled, false: disabled
314
+ */
315
+void elog_async_enabled(bool enabled) {
316
+    is_enabled = enabled;
317
+}
318
+
319
+/**
320
+ * asynchronous output mode initialize
321
+ *
322
+ * @return result
323
+ */
324
+ElogErrCode elog_async_init(void) {
325
+    ElogErrCode result = ELOG_NO_ERR;
326
+
327
+    if (init_ok) {
328
+        return result;
329
+    }
330
+
331
+#ifdef ELOG_ASYNC_OUTPUT_USING_PTHREAD
332
+    pthread_attr_t thread_attr;
333
+    struct sched_param thread_sched_param;
334
+
335
+    sem_init(&output_notice, 0, 0);
336
+
337
+    pthread_attr_init(&thread_attr);
338
+    pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
339
+    pthread_attr_setstacksize(&thread_attr, ELOG_ASYNC_OUTPUT_PTHREAD_STACK_SIZE);
340
+    pthread_attr_setschedpolicy(&thread_attr, SCHED_RR);
341
+    thread_sched_param.sched_priority = ELOG_ASYNC_OUTPUT_PTHREAD_PRIORITY;
342
+    pthread_attr_setschedparam(&thread_attr, &thread_sched_param);
343
+    pthread_create(&async_output_thread, &thread_attr, async_output, NULL);
344
+    pthread_attr_destroy(&thread_attr);
345
+#endif
346
+
347
+    init_ok = true;
348
+
349
+    return result;
350
+}
351
+
352
+#endif /* ELOG_ASYNC_OUTPUT_ENABLE */

+ 104
- 0
util/easylogger/src/elog_buf.c Прегледај датотеку

@@ -0,0 +1,104 @@
1
+/*
2
+ * This file is part of the EasyLogger Library.
3
+ *
4
+ * Copyright (c) 2016, Armink, <armink.ztl@gmail.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * 'Software'), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * Function: Logs buffered output.
26
+ * Created on: 2016-11-09
27
+ */
28
+
29
+#include <elog.h>
30
+#include <string.h>
31
+
32
+#ifdef ELOG_BUF_OUTPUT_ENABLE
33
+#if !defined(ELOG_BUF_OUTPUT_BUF_SIZE)
34
+    #error "Please configure buffer size for buffered output mode (in elog_cfg.h)"
35
+#endif
36
+
37
+/* buffered output mode's buffer */
38
+static char log_buf[ELOG_BUF_OUTPUT_BUF_SIZE] = { 0 };
39
+/* log buffer current write size */
40
+static size_t buf_write_size = 0;
41
+/* buffered output mode enabled flag */
42
+static bool is_enabled = false;
43
+
44
+extern void elog_port_output(const char *log, size_t size);
45
+extern void elog_output_lock(void);
46
+extern void elog_output_unlock(void);
47
+
48
+/**
49
+ * output buffered logs when buffer is full
50
+ *
51
+ * @param log will be buffered line's log
52
+ * @param size log size
53
+ */
54
+void elog_buf_output(const char *log, size_t size) {
55
+    size_t write_size = 0, write_index = 0;
56
+
57
+    if (!is_enabled) {
58
+        elog_port_output(log, size);
59
+        return;
60
+    }
61
+
62
+    while (true) {
63
+        if (buf_write_size + size > ELOG_BUF_OUTPUT_BUF_SIZE) {
64
+            write_size = ELOG_BUF_OUTPUT_BUF_SIZE - buf_write_size;
65
+            memcpy(log_buf + buf_write_size, log + write_index, write_size);
66
+            write_index += write_size;
67
+            size -= write_size;
68
+            buf_write_size += write_size;
69
+            /* output log */
70
+            elog_port_output(log_buf, buf_write_size);
71
+            /* reset write index */
72
+            buf_write_size = 0;
73
+        } else {
74
+            memcpy(log_buf + buf_write_size, log + write_index, size);
75
+            buf_write_size += size;
76
+            break;
77
+        }
78
+    }
79
+}
80
+
81
+/**
82
+ * flush all buffered logs to output device
83
+ */
84
+void elog_flush(void) {
85
+    /* lock output */
86
+    elog_output_lock();
87
+    /* output log */
88
+    elog_port_output(log_buf, buf_write_size);
89
+    /* reset write index */
90
+    buf_write_size = 0;
91
+    /* unlock output */
92
+    elog_output_unlock();
93
+}
94
+
95
+/**
96
+ * enable or disable buffered output mode
97
+ * the log will be output directly when mode is disabled
98
+ *
99
+ * @param enabled true: enabled, false: disabled
100
+ */
101
+void elog_buf_enabled(bool enabled) {
102
+    is_enabled = enabled;
103
+}
104
+#endif /* ELOG_BUF_OUTPUT_ENABLE */

+ 103
- 0
util/easylogger/src/elog_utils.c Прегледај датотеку

@@ -0,0 +1,103 @@
1
+/*
2
+ * This file is part of the EasyLogger Library.
3
+ *
4
+ * Copyright (c) 2015-2018, Armink, <armink.ztl@gmail.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * 'Software'), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * Function: Some utils for this library.
26
+ * Created on: 2015-04-28
27
+ */
28
+
29
+#include <elog.h>
30
+#include <string.h>
31
+
32
+/**
33
+ * another copy string function
34
+ *
35
+ * @param cur_len current copied log length, max size is ELOG_LINE_BUF_SIZE
36
+ * @param dst destination
37
+ * @param src source
38
+ *
39
+ * @return copied length
40
+ */
41
+size_t elog_strcpy(size_t cur_len, char *dst, const char *src) {
42
+    const char *src_old = src;
43
+
44
+    assert(dst);
45
+    assert(src);
46
+
47
+    while (*src != 0) {
48
+        /* make sure destination has enough space */
49
+        if (cur_len++ < ELOG_LINE_BUF_SIZE) {
50
+            *dst++ = *src++;
51
+        } else {
52
+            break;
53
+        }
54
+    }
55
+    return src - src_old;
56
+}
57
+
58
+/**
59
+ * Copy line log split by newline sign. It will copy all log when the newline sign isn't find.
60
+ *
61
+ * @param line line log buffer
62
+ * @param log origin log buffer
63
+ * @param len origin log buffer length
64
+ *
65
+ * @return copy size
66
+ */
67
+size_t elog_cpyln(char *line, const char *log, size_t len) {
68
+    size_t newline_len = strlen(ELOG_NEWLINE_SIGN), copy_size = 0;
69
+
70
+    assert(line);
71
+    assert(log);
72
+
73
+    while (len--) {
74
+        *line++ = *log++;
75
+        copy_size++;
76
+        if (copy_size >= newline_len && !strncmp(log - newline_len, ELOG_NEWLINE_SIGN, newline_len)) {
77
+            break;
78
+        }
79
+    }
80
+    return copy_size;
81
+}
82
+
83
+/**
84
+ * This function will copy memory content from source address to destination
85
+ * address.
86
+ *
87
+ * @param dst the address of destination memory
88
+ * @param src  the address of source memory
89
+ * @param count the copied length
90
+ *
91
+ * @return the address of destination memory
92
+ */
93
+void *elog_memcpy(void *dst, const void *src, size_t count) {
94
+    char *tmp = (char *) dst, *s = (char *) src;
95
+
96
+    assert(dst);
97
+    assert(src);
98
+
99
+    while (count--)
100
+        *tmp++ = *s++;
101
+
102
+    return dst;
103
+}

+ 2356
- 0
util/iLOG/LOG.c
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 653
- 0
util/iLOG/LOG.h Прегледај датотеку

@@ -0,0 +1,653 @@
1
+#ifndef _H_LOG_
2
+#define _H_LOG_
3
+
4
+/*
5
+ * iLOG3 - log function library written in c
6
+ * author	: calvin
7
+ * email	: calvinwilliams.c@gmail.com
8
+ * LastVersion	: v1.0.11
9
+ *
10
+ * Licensed under the LGPL v2.1, see the file LICENSE in base directory.
11
+ */
12
+
13
+#ifdef __cplusplus
14
+extern "C" {
15
+#endif
16
+
17
+#if ( defined _WIN32 )
18
+#ifndef _WINDLL_FUNC
19
+#define _WINDLL_FUNC		_declspec(dllexport)
20
+#endif
21
+#elif ( defined __unix ) || ( defined _AIX ) || ( defined __linux__ ) || ( defined __hpux )
22
+#ifndef _WINDLL_FUNC
23
+#define _WINDLL_FUNC
24
+#endif
25
+#endif
26
+
27
+#include <stdio.h>
28
+#include <stdlib.h>
29
+#include <string.h>
30
+#include <ctype.h>
31
+#include <time.h>
32
+#include <stdarg.h>
33
+#include <sys/stat.h>
34
+#include <sys/types.h>
35
+#include <errno.h>
36
+
37
+#if ( defined _WIN32 )
38
+#include <windows.h>
39
+#include <share.h>
40
+#include <io.h>
41
+#include <fcntl.h>
42
+#elif ( defined __unix ) || ( defined _AIX ) || ( defined __linux__ ) || ( defined __hpux )
43
+#include <fcntl.h>
44
+#include <unistd.h>
45
+#include <sys/time.h>
46
+#include <syslog.h>
47
+#include <pthread.h>
48
+#endif
49
+
50
+#if ( defined __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199901 )
51
+struct tm *localtime_r(const time_t *timep, struct tm *result);
52
+#endif
53
+
54
+/* ��������ֵ�� */ /* function returns value macros */
55
+#define LOG_RETURN_ERROR_ALLOC		-11	/* �����ڴ�ʧ�� */ /* alloc memory failure */
56
+#define LOG_RETURN_ERROR_INTERNAL	-12	/* �ڲ����� */ /* internal error */
57
+#define LOG_RETURN_ERROR_ALLOC_MAX	-13	/* �ڴ�ʹ�ó��� */ /* memory usage transfinite */
58
+#define LOG_RETURN_ERROR_PARAMETER	-14	/* �������� */ /* parameter invalid */
59
+#define LOG_RETURN_ERROR_NOTSUPPORT	-17	/* �ݲ�֧�� */ /* not support */
60
+#define LOG_RETURN_ERROR_CREATEFILE	-21	/* �����ļ�ʧ�� */ /* failed to create file */
61
+#define LOG_RETURN_ERROR_OPENFILE	-22	/* ���ļ�ʧ�� */ /* failed to open file  */
62
+#define LOG_RETURN_ERROR_WRITEFILE	-23	/* д�ļ�ʧ�� */ /* failed to write file */
63
+
64
+/********************************************************/
65
+/*   ������������ The basic features are as follows   */
66
+/********************************************************/
67
+
68
+/* ��־������� */ /* log output type macros */
69
+#define LOG_OUTPUT_NOSET	-1	/* ������ */ /* no set */
70
+#define LOG_OUTPUT_STDOUT	1	/* ��׼��� */ /* stdout */
71
+#define LOG_OUTPUT_STDERR	2	/* ��׼������� */ /* stderr */
72
+#define LOG_OUTPUT_SYSLOG	3	/* UNIX&Linux��syslog �� Windows��WINDOWS EVENT */
73
+#define LOG_OUTPUT_FILE		11	/* �ļ� */ /* file */
74
+#define LOG_OUTPUT_CALLBACK	21	/* ��ʹ���Զ�����־����ص������� */ /* using custom log output callback function */
75
+
76
+/* ��־�ȼ��� */ /* log level macros */
77
+#define LOG_LEVEL_DEBUG		0	/* ���Եȼ� */ /* debug level */
78
+#define LOG_LEVEL_INFO		1	/* ��ͨ��Ϣ�ȼ� */ /* info level */
79
+#define LOG_LEVEL_WARN		2	/* ����ȼ� */ /* warn level */
80
+#define LOG_LEVEL_ERROR		3	/* ����ȼ� */ /* error level */
81
+#define LOG_LEVEL_FATAL		4	/* ���ش���ȼ� */ /* error level */
82
+#define LOG_LEVEL_NOLOG		5	/* ����Ҫ�����־ */ /* no log */
83
+
84
+#define LOG_LEVEL_DEFAULT	LOG_LEVEL_NOLOG
85
+
86
+/* ����־�����Ϻ� */ /* Line logging combination style macros */
87
+#define LOG_STYLE_DATE		1	/* ����"YYYY-MM-DD" */ /* date "YYYY-MM-DD" */
88
+#define LOG_STYLE_DATETIME	2	/* ����ʱ��"YYYY-MM-DD hh:mm:ss" */ /* date time "YYYY-MM-DD hh:mm:ss" */
89
+#define LOG_STYLE_DATETIMEMS	4	/* ����ʱ�����"YYYY-MM-DD hh:mm:ss.6ms"������ʱ����껥�⣬�����Զ�ѡ����Ϣ�����ģ� */ /* date time "YYYY-MM-DD hh:mm:ss.6ms" */
90
+#define LOG_STYLE_LOGLEVEL	8	/* ��־�ȼ� */ /* log level */
91
+#define LOG_STYLE_PID		16	/* ����id */ /* pid */
92
+#define LOG_STYLE_TID		32	/* �߳�id */ /* tid */
93
+#define LOG_STYLE_SOURCE	64	/* "Դ�����ļ���:Դ�����к�" */ /* source file name and row number */
94
+#define LOG_STYLE_FORMAT	128	/* Ӧ����־�� */ /* application text */
95
+#define LOG_STYLE_NEWLINE	256	/* ���� */ /* new line */
96
+#define LOG_STYLE_CUSTLABEL1	512	/* �Զ����ǩ1 */ /* custom label1 */
97
+#define LOG_STYLE_CUSTLABEL2	1024	/* �Զ����ǩ2 */ /* custom label2 */
98
+#define LOG_STYLE_CUSTLABEL3	2048	/* �Զ����ǩ3 */ /* custom label3 */
99
+#define LOG_STYLE_CALLBACK	4096	/* ��ʹ���Զ�������־���ص������� */ /* using custom log style callback function  */
100
+
101
+#define LOG_STYLES_DEFAULT	0
102
+
103
+/* ������ */ /* other macros */
104
+#ifndef MAXLEN_FILENAME
105
+#define MAXLEN_FILENAME		256
106
+#endif
107
+
108
+typedef struct tagLOG LOG ;
109
+typedef struct tagLOGBUF LOGBUF ;
110
+
111
+/* ������־������� */ /* log handle functions */
112
+_WINDLL_FUNC LOG *CreateLogHandle();
113
+_WINDLL_FUNC void DestroyLogHandle( LOG *g );
114
+
115
+/* �Զ���򿪡�������ر���־�������� */ /* custom open , write , close log callback functions */
116
+typedef int funcOpenLog( LOG *g , char *log_pathfilename , void **open_handle );
117
+typedef int funcWriteLog( LOG *g , void **open_handle , int log_level , char *buf , long len , long *writelen );
118
+typedef int funcChangeTest( LOG *g , void **test_handle );
119
+typedef int funcCloseLog( LOG *g , void **open_handle );
120
+
121
+#define LOG_NO_OUTPUTFUNC	NULL , NULL , NULL , NULL , NULL , NULL
122
+
123
+/* �Զ�������־��������� */ /* custom log style callback functions */
124
+typedef int funcLogStyle( LOG *g , LOGBUF *logbuf , const char *c_filename , long c_fileline , int log_level , const char *format , va_list valist );
125
+
126
+#define LOG_NO_STYLEFUNC	NULL
127
+
128
+#define func_log_style		funcLogStyle
129
+
130
+/* ����������ú��� */ /* set log handle environment */
131
+_WINDLL_FUNC int SetLogOutput( LOG *g , int output , char *log_pathfilename , funcOpenLog *pfuncOpenLogFirst , funcOpenLog *pfuncOpenLog , funcWriteLog *pfuncWriteLog , funcChangeTest *pfuncChangeTest , funcCloseLog *pfuncCloseLog , funcCloseLog *pfuncCloseLogFinally );
132
+_WINDLL_FUNC int SetLogOutput2( LOG *g , int output , funcOpenLog *pfuncOpenLogFirst , funcOpenLog *pfuncOpenLog , funcWriteLog *pfuncWriteLog , funcChangeTest *pfuncChangeTest , funcCloseLog *pfuncCloseLog , funcCloseLog *pfuncCloseLogFinally , char *log_pathfilename_format , ... );
133
+_WINDLL_FUNC int SetLogLevel( LOG *g , int log_level );
134
+_WINDLL_FUNC int SetLogStyles( LOG *g , long log_styles , funcLogStyle *pfuncLogStyle );
135
+
136
+/* д��־���� */ /* output log */
137
+_WINDLL_FUNC int WriteLog( LOG *g , char *c_filename , long c_fileline , int log_level , char *format , ... );
138
+_WINDLL_FUNC int DebugLog( LOG *g , const char *c_filename , long c_fileline , const char *format , ... );
139
+_WINDLL_FUNC int InfoLog( LOG *g , const char *c_filename , long c_fileline , const char *format , ... );
140
+_WINDLL_FUNC int WarnLog( LOG *g , const char *c_filename , long c_fileline , const char *format , ... );
141
+_WINDLL_FUNC int ErrorLog( LOG *g , const char *c_filename , long c_fileline , const char *format , ... );
142
+_WINDLL_FUNC int FatalLog( LOG *g , const char *c_filename , long c_fileline , const char *format , ... );
143
+
144
+/* дʮ�����ƿ���־���� */ /* output hex log */
145
+_WINDLL_FUNC int WriteHexLog( LOG *g , char *c_filename , long c_fileline , int log_level , char *buffer , long buflen , char *format , ... );
146
+_WINDLL_FUNC int DebugHexLog( LOG *g , char *c_filename , long c_fileline , char *buffer , long buflen , char *format , ... );
147
+_WINDLL_FUNC int InfoHexLog( LOG *g , char *c_filename , long c_fileline , char *buffer , long buflen , char *format , ... );
148
+_WINDLL_FUNC int WarnHexLog( LOG *g , char *c_filename , long c_fileline , char *buffer , long buflen , char *format , ... );
149
+_WINDLL_FUNC int ErrorHexLog( LOG *g , char *c_filename , long c_fileline , char *buffer , long buflen , char *format , ... );
150
+_WINDLL_FUNC int FatalHexLog( LOG *g , char *c_filename , long c_fileline , char *buffer , long buflen , char *format , ... );
151
+
152
+#if ( defined __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199901 )
153
+
154
+/* д��־�����Ŀɱ������ */ /* output log macros */
155
+#define WRITELOG( _g_ , _log_level_ , ... )	WriteLog( _g_ , __FILE__ , __LINE__ , _log_level_ , __VA_ARGS__ );
156
+#define DEBUGLOG( _g_ , ... )			DebugLog( _g_ , __FILE__ , __LINE__ , __VA_ARGS__ );
157
+#define INFOLOG( _g_ , ... )			InfoLog( _g_ , __FILE__ , __LINE__ , __VA_ARGS__ );
158
+#define WARNLOG( _g_ , ... )			WarnLog( _g_ , __FILE__ , __LINE__ , __VA_ARGS__ );
159
+#define ERRORLOG( _g_ , ... )			ErrorLog( _g_ , __FILE__ , __LINE__ , __VA_ARGS__ );
160
+#define FATALLOG( _g_ , ... )			FatalLog( _g_ , __FILE__ , __LINE__ , __VA_ARGS__ );
161
+
162
+/* дʮ�����ƿ���־�Ŀɱ������ */ /* output hex log macros */
163
+#define WRITEHEXLOG( _g_ , _log_level_ , _buf_ , _buf_size_ , ... )	WriteHexLog( _g_ , __FILE__ , __LINE__ , _log_level_ , _buf_ , _buf_size_ , __VA_ARGS__ );
164
+#define DEBUGHEXLOG( _g_ , _buf_ , _buf_size_ , ... )			DebugHexLog( _g_ , __FILE__ , __LINE__ , _buf_ , _buf_size_ , __VA_ARGS__ );
165
+#define INFOHEXLOG( _g_ , _buf_ , _buf_size_ , ... )			InfoHexLog( _g_ , __FILE__ , __LINE__ , _buf_ , _buf_size_ , __VA_ARGS__ );
166
+#define WARNHEXLOG( _g_ , _buf_ , _buf_size_ , ... )			WarnHexLog( _g_ , __FILE__ , __LINE__ , _buf_ , _buf_size_ , __VA_ARGS__ );
167
+#define ERRORHEXLOG( _g_ , _buf_ , _buf_size_ , ... )			ErrorHexLog( _g_ , __FILE__ , __LINE__ , _buf_ , _buf_size_ , __VA_ARGS__ );
168
+#define FATALHEXLOG( _g_ , _buf_ , _buf_size_ , ... )			FatalHexLog( _g_ , __FILE__ , __LINE__ , _buf_ , _buf_size_ , __VA_ARGS__ );
169
+
170
+#endif
171
+
172
+/* ����滻�� */
173
+#define create_log_handle	CreateLogHandle
174
+#define destroy_log_handle	DestroyLogHandle
175
+
176
+#define func_open_log		funcOpenLog
177
+#define func_write_log		funcWriteLog
178
+#define func_change_test	funcChangeTest
179
+#define func_close_log		funcCloseLog
180
+
181
+#define set_log_output		SetLogOutput
182
+#define set_log_output2		SetLogOutput2
183
+#define set_log_level		SetLogLevel
184
+#define set_log_styles		SetLogStyles
185
+
186
+#define write_log		WriteLog
187
+#define debug_log		DebugLog
188
+#define info_log		InfoLog
189
+#define warn_log		WarnLog
190
+#define error_log		ErrorLog
191
+#define fatal_log		FatalLog
192
+
193
+#define write_hex_log		WriteHexLog
194
+#define debug_hex_log		DebugHexLog
195
+#define info_hex_log		InfoHexLog
196
+#define warn_hex_log		WarnHexLog
197
+#define error_hex_log		ErrorHexLog
198
+#define fatal_hex_log		FatalHexLog
199
+
200
+#if ( defined _WIN32 ) || ( defined __linux__ ) || ( defined _AIX ) || ( defined __hpux )
201
+
202
+_WINDLL_FUNC LOG *CreateLogHandleG();
203
+_WINDLL_FUNC void DestroyLogHandleG();
204
+
205
+_WINDLL_FUNC int SetLogOutputG( int output , char *log_pathfilename , funcOpenLog *pfuncOpenLogFirst , funcOpenLog *pfuncOpenLog , funcWriteLog *pfuncWriteLog , funcChangeTest *pfuncChangeTest , funcCloseLog *pfuncCloseLog , funcCloseLog *pfuncCloseLogFinally );
206
+_WINDLL_FUNC int SetLogLevelG( int log_level );
207
+_WINDLL_FUNC int SetLogStylesG( long log_styles , funcLogStyle *pfuncLogStyles );
208
+#if ( defined __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199901 )
209
+#define SetLogOutput2G(_output_,_pfuncOpenLogFirst_,_pfuncOpenLog_,_pfuncWriteLog_,_pfuncChangeTest_,_pfuncCloseLog_,_pfuncCloseLogFinally_,_log_pathfilename_format_,...) \
210
+	SetLogOutput2(_output_,_pfuncOpenLogFirst_,_pfuncOpenLog_,_pfuncWriteLog_,_pfuncChangeTest_,_pfuncCloseLog_,_pfuncCloseLogFinally_,_log_pathfilename_format_,__VA_ARGS__)
211
+#endif
212
+
213
+/* д��־�����������̱߳��ش洢��ȱʡ��־����ĺ������ϰ汾�� */ /* output log for TLS */
214
+_WINDLL_FUNC int WriteLogG( char *c_filename , long c_fileline , int log_level , char *format , ... );
215
+_WINDLL_FUNC int DebugLogG( char *c_filename , long c_fileline , char *format , ... );
216
+_WINDLL_FUNC int InfoLogG( char *c_filename , long c_fileline , char *format , ... );
217
+_WINDLL_FUNC int WarnLogG( char *c_filename , long c_fileline , char *format , ... );
218
+_WINDLL_FUNC int ErrorLogG( char *c_filename , long c_fileline , char *format , ... );
219
+_WINDLL_FUNC int FatalLogG( char *c_filename , long c_fileline , char *format , ... );
220
+
221
+/* дʮ�����ƿ���־�����������̱߳��ش洢��ȱʡ��־����ĺ������ϰ汾�� */ /* output hex log for TLS */
222
+_WINDLL_FUNC int WriteHexLogG( char *c_filename , long c_fileline , int log_level , char *buffer , long buflen , char *format , ... );
223
+_WINDLL_FUNC int DebugHexLogG( char *c_filename , long c_fileline , char *buffer , long buflen , char *format , ... );
224
+_WINDLL_FUNC int InfoHexLogG( char *c_filename , long c_fileline , char *buffer , long buflen , char *format , ... );
225
+_WINDLL_FUNC int WarnHexLogG( char *c_filename , long c_fileline , char *buffer , long buflen , char *format , ... );
226
+_WINDLL_FUNC int ErrorHexLogG( char *c_filename , long c_fileline , char *buffer , long buflen , char *format , ... );
227
+_WINDLL_FUNC int FatalHexLogG( char *c_filename , long c_fileline , char *buffer , long buflen , char *format , ... );
228
+
229
+#if ( defined __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199901 )
230
+
231
+/* д��־�����Ŀɱ�����꣨�����̱߳��ش洢��ȱʡ��־����ĺ������ϰ汾�� */  /* output log macros for TLS */
232
+#define WRITELOGG( _log_level_ , ... )	WriteLogG( __FILE__ , __LINE__ , _log_level_ , __VA_ARGS__ );
233
+#define DEBUGLOGG( ... )		DebugLogG( __FILE__ , __LINE__ , __VA_ARGS__ );
234
+#define INFOLOGG( ... )			InfoLogG( __FILE__ , __LINE__ , __VA_ARGS__ );
235
+#define WARNLOGG( ... )			WarnLogG( __FILE__ , __LINE__ , __VA_ARGS__ );
236
+#define ERRORLOGG( ... )		ErrorLogG( __FILE__ , __LINE__ , __VA_ARGS__ );
237
+#define FATALLOGG( ... )		FatalLogG( __FILE__ , __LINE__ , __VA_ARGS__ );
238
+
239
+/* дʮ�����ƿ���־�Ŀɱ�����꣨�����̱߳��ش洢��ȱʡ��־����ĺ������ϰ汾�� */ /* output hex log macros for TLS */
240
+#define WRITEHEXLOGG( _log_level_ , _buf_ , _buf_size_ , ... )	WriteHexLogG( __FILE__ , __LINE__ , _log_level_ , _buf_ , _buf_size_ , __VA_ARGS__ );
241
+#define DEBUGHEXLOGG( _buf_ , _buf_size_ , ... )		DebugHexLogG( __FILE__ , __LINE__ , _buf_ , _buf_size_ , __VA_ARGS__ );
242
+#define INFOHEXLOGG( _buf_ , _buf_size_ , ... )			InfoHexLogG( __FILE__ , __LINE__ , _buf_ , _buf_size_ , __VA_ARGS__ );
243
+#define WARNHEXLOGG( _buf_ , _buf_size_ , ... )			WarnHexLogG( __FILE__ , __LINE__ , _buf_ , _buf_size_ , __VA_ARGS__ );
244
+#define ERRORHEXLOGG( _buf_ , _buf_size_ , ... )		ErrorHexLogG( __FILE__ , __LINE__ , _buf_ , _buf_size_ , __VA_ARGS__ );
245
+#define FATALHEXLOGG( _buf_ , _buf_size_ , ... )		FatalHexLogG( __FILE__ , __LINE__ , _buf_ , _buf_size_ , __VA_ARGS__ );
246
+
247
+#endif
248
+
249
+/* ����滻�� */
250
+#define create_log_handle_g	CreateLogHandleG
251
+#define destroy_log_handle_g	DestroyLogHandleG
252
+
253
+#define set_log_output_g	SetLogOutputG
254
+#define set_log_level_g		SetLogLevelG
255
+#define set_log_styles_g	SetLogStylesG
256
+#define set_log_output2_g	SetLogOutput2G
257
+
258
+#define write_log_g		WriteLogG
259
+#define debug_log_g		DebugLogG
260
+#define info_log_g		InfoLogG
261
+#define warn_log_g		WarnLogG
262
+#define error_log_g		ErrorLogG
263
+#define fatal_log_g		FatalLogG
264
+
265
+#define write_hex_log_g		WriteHexLogG
266
+#define debug_hex_log_g		DebugHexLogG
267
+#define info_hex_log_g		InfoHexLogG
268
+#define warn_hex_log_g		WarnHexLogG
269
+#define error_hex_log_g		ErrorHexLogG
270
+#define fatal_hex_log_g		FatalHexLogG
271
+
272
+#endif
273
+
274
+/********************************************************/
275
+/* ����Ϊ�߼����� The following is a advanced features  */
276
+/********************************************************/
277
+
278
+/* �Զ�������־�ȼ��ص��������� */ /* custom check log level callback function */
279
+typedef int funcFilterLog( LOG *g , void **open_handle , int log_level , char *buf , long len );
280
+
281
+#define func_filter_log		funcFilterLog
282
+
283
+/* �Զ����ǩ���� */ /* custom tag amount */
284
+#define LOG_MAXCNT_CUST_LABEL		3
285
+/* �Զ����ǩ��󳤶� */ /* custom tag maximum length */
286
+#define LOG_MAXLEN_CUST_LABEL		32
287
+
288
+/* ��־ѡ�� */ /* log options */
289
+#define LOG_OPTION_OPEN_AND_CLOSE		1	/* ÿ�ζ�����־��д��־���ر���־ */ /* open , write , close log every time */
290
+#define LOG_OPTION_CHANGE_TEST			2	/* ����ļ��䶯 */ /* detect log changed and reopen it */
291
+#define LOG_OPTION_OPEN_ONCE			4	/* ��־��һ�β��ر� */ /* open log once */
292
+#define LOG_OPTION_SET_OUTPUT_BY_FILENAME	8	/* �Զ������ļ�������������� */ /* reset log output type automatically */
293
+							/* "#stdout" -> LOG_OUTPUT_STDOUT */
294
+							/* "#stderr" -> LOG_OUTPUT_STDERR */
295
+							/* "#syslog" -> LOG_OUTPUT_SYSLOG */
296
+#define LOG_OPTION_FILENAME_APPEND_DOT_LOG	16	/* ��־����ļ������Զ�����".log" */ /* append ".log" */
297
+
298
+#define LOG_OPTION_OPEN_DEFAULT			LOG_OPTION_CHANGE_TEST
299
+
300
+/* ��־ת��ģʽ */ /* log rotate mode */
301
+#define LOG_ROTATEMODE_NONE		0	/* ��ת�� */ /* no rotate */
302
+#define LOG_ROTATEMODE_SIZE		1	/* ����־�ļ���Сת�����ͺ���SetLogRotateSize���ʹ�ã�ת���ļ�����ʽ"ԭ��־�ļ���.���" */ /* according to log file size turn log */
303
+#define LOG_ROTATEMODE_PER_DAY		2	/* ��ÿ��ת����ת���ļ�����ʽ"ԭ��־�ļ���.����������������" */ /* according to daily turn log */
304
+#define LOG_ROTATEMODE_PER_HOUR		3	/* ��Сʱת����ת���ļ�����ʽ"ԭ��־�ļ���.����������������_Сʱ" */ /* according to hours turn log  */
305
+
306
+/* ��־ת��ȱʡֵ */ /* log rotate default macros */
307
+#define LOG_ROTATE_SIZE_FILE_COUNT_DEFAULT		99999999
308
+#define LOG_ROTATE_SIZE_PRESSURE_FACTOR_DEFAULT		0
309
+#define LOG_FSYNC_PERIOD				10000
310
+
311
+/* �Զ�����־ת��ǰ��ص��������� */ /* custom turn log file callback function */
312
+typedef int funcBeforeRotateFile( LOG *g , char *rotate_log_pathfilename );
313
+typedef int funcAfterRotateFile( LOG *g , char *rotate_log_pathfilename );
314
+
315
+#define func_before_rotate_file		funcBeforeRotateFile
316
+#define func_after_rotate_file		funcAfterRotateFile
317
+
318
+/* ��������Сȱʡֵ */ /* default buffer size */
319
+#define LOG_BUFSIZE_DEFAULT		(1024)		/* ȱʡ����־��������С */
320
+#define LOG_BUFSIZE_MAX			(16*1024)	/* �������־��������С */
321
+#define LOG_HEXLOG_BUFSIZE_DEFAULT	(4*1024)	/* ȱʡʮ�����ƿ���־��������С */
322
+#define LOG_HEXLOG_BUFSIZE_MAX		(100*1024)	/* ���ʮ�����ƿ���־��������С */
323
+
324
+/* �߼�����������ú��� */ /* senior handle environment setting function */
325
+_WINDLL_FUNC int SetLogOptions( LOG *g , int log_options );
326
+_WINDLL_FUNC int SetLogFileChangeTest( LOG *g , long interval );
327
+_WINDLL_FUNC int SetLogFsyncPeriod( LOG *g , long period );
328
+_WINDLL_FUNC int SetLogCustLabel( LOG *g , int index , char *cust_label );
329
+_WINDLL_FUNC int SetLogRotateMode( LOG *g , int rotate_mode );
330
+_WINDLL_FUNC int SetLogRotateSize( LOG *g , long log_rotate_size );
331
+_WINDLL_FUNC int SetLogRotatePressureFactor( LOG *g , long pressure_factor );
332
+_WINDLL_FUNC int SetLogRotateFileCount( LOG *g , long rotate_file_count );
333
+_WINDLL_FUNC int SetBeforeRotateFileFunc( LOG *g , funcAfterRotateFile *pfuncAfterRotateFile );
334
+_WINDLL_FUNC int SetAfterRotateFileFunc( LOG *g , funcAfterRotateFile *pfuncAfterRotateFile );
335
+_WINDLL_FUNC int SetFilterLogFunc( LOG *g , funcFilterLog *pfuncFilterLog );
336
+_WINDLL_FUNC int SetLogBufferSize( LOG *g , long log_bufsize , long max_log_bufsize );
337
+_WINDLL_FUNC int SetHexLogBufferSize( LOG *g , long hexlog_bufsize , long max_log_hexbufsize );
338
+_WINDLL_FUNC int SetLogOutputFuncDirectly( LOG *g , funcOpenLog *pfuncOpenLogFirst , funcOpenLog *pfuncOpenLog , funcWriteLog *pfuncWriteLog , funcChangeTest *pfuncChangeTest , funcCloseLog *pfuncCloseLog , funcCloseLog *pfuncCloseLogFinally );
339
+_WINDLL_FUNC int SetLogStyleFuncDirectly( LOG *g , funcLogStyle *pfuncLogStyle );
340
+
341
+/* ����滻�� */
342
+#define set_log_options			SetLogOptions
343
+#define set_log_file_change_test	SetLogFileChangeTest
344
+#define set_log_fsync_period		SetLogFsyncPeriod
345
+#define set_log_cust_label		SetLogCustLabel
346
+#define set_log_rotate_mode		SetLogRotateMode
347
+#define set_log_rotate_size		SetLogRotateSize
348
+#define set_log_rotate_pressure_factor	SetLogRotatePressureFactor
349
+#define set_log_rotate_file_count	SetLogRotateFileCount
350
+#define set_before_rotate_file_func	SetBeforeRotateFileFunc
351
+#define set_after_rotate_file_func	SetAfterRotateFileFunc
352
+#define set_filter_log_func		SetFilterLogFunc
353
+#define set_log_buffer_size		SetLogBufferSize
354
+#define set_hex_log_buffer_size		SetHexLogBufferSize
355
+#define set_log_output_func_directly	SetLogOutputFuncDirectly
356
+#define set_log_stlye_func_directly	SetLogStyleFuncDirectly
357
+
358
+#if ( defined _WIN32 ) || ( defined __linux__ ) || ( defined _AIX ) || ( defined __hpux )
359
+_WINDLL_FUNC int SetLogOptionsG( int log_options );
360
+_WINDLL_FUNC int SetLogFileChangeTestG( long interval );
361
+_WINDLL_FUNC int SetLogFsyncPeriodG( long period );
362
+_WINDLL_FUNC int SetLogCustLabelG( int index , char *cust_label );
363
+_WINDLL_FUNC int SetLogRotateModeG( int rotate_mode );
364
+_WINDLL_FUNC int SetLogRotateSizeG( long log_rotate_size );
365
+_WINDLL_FUNC int SetLogRotatePressureFactorG( long pressure_factor );
366
+_WINDLL_FUNC int SetLogRotateFileCountG( long rotate_file_count );
367
+_WINDLL_FUNC int SetBeforeRotateFileFuncG( funcAfterRotateFile *pfuncAfterRotateFile );
368
+_WINDLL_FUNC int SetAfterRotateFileFuncG( funcAfterRotateFile *pfuncAfterRotateFile );
369
+_WINDLL_FUNC int SetFilterLogFuncG( funcFilterLog *pfuncFilterLog );
370
+_WINDLL_FUNC int SetLogBufferSizeG( long log_bufsize , long max_log_bufsize );
371
+_WINDLL_FUNC int SetHexLogBufferSizeG( long hexlog_bufsize , long max_log_hexbufsize );
372
+_WINDLL_FUNC int SetLogOutputFuncDirectlyG( funcOpenLog *pfuncOpenLogFirst , funcOpenLog *pfuncOpenLog , funcWriteLog *pfuncWriteLog , funcChangeTest *pfuncChangeTest , funcCloseLog *pfuncCloseLog , funcCloseLog *pfuncCloseLogFinally );
373
+_WINDLL_FUNC int SetLogStyleFuncDirectlyG( funcLogStyle *pfuncLogStyle );
374
+#endif
375
+
376
+/* ����滻�� */
377
+#define set_log_options_g			SetLogOptionsG
378
+#define set_log_file_change_test_g		SetLogFileChangeTestG
379
+#define set_log_fsync_period_g			SetLogFsyncPeriodG
380
+#define set_log_cust_label_g			SetLogCustLabelG
381
+#define set_log_rotate_mode_g			SetLogRotateModeG
382
+#define set_log_rotate_size_g			SetLogRotateSizeG
383
+#define set_log_rotate_pressure_factor_g	SetLogRotatePressureFactorG
384
+#define set_log_rotate_file_count_g		SetLogRotateFileCountG
385
+#define set_before_rotate_file_func_g		SetBeforeRotateFileFuncG
386
+#define set_after_rotate_file_func_g		SetAfterRotateFileFuncG
387
+#define set_filter_log_func_g			SetFilterLogFuncG
388
+#define set_log_buffer_size_g			SetLogBufferSizeG
389
+#define set_hex_log_buffer_size_g		SetHexLogBufferSizeG
390
+#define set_log_output_func_directly_g		SetLogOutputFuncDirectlyG
391
+#define set_log_stlye_func_directly_g		SetLogStyleFuncDirectlyG
392
+
393
+#define TEST_LOGLEVEL_NOTENOUGH(_log_level_,_g_)	( (_log_level_) < (_g_)->log_level )
394
+#define TEST_ATTRIBUTE(_param_,_attr_)			( ( _param_ & _attr_ ) == _attr_ )
395
+#define TEST_NOT_ATTRIBUTE(_param_,_attr_)		( ( _param_ & _attr_ ) != _attr_ )
396
+#define TEST_STDSTREAM(_fd_)				( (_fd_) != FD_NULL && ( (_fd_) == STDOUT_HANDLE || (_fd_) == STDERR_HANDLE ) )
397
+#define TEST_FILEFD(_fd_)				( (_fd_) != FD_NULL && (_fd_) != STDOUT_HANDLE && (_fd_) != STDERR_HANDLE )
398
+
399
+#if ( defined _WIN32 ) || ( defined __linux__ ) || ( defined _AIX ) || ( defined __hpux )
400
+/* �õ������̱߳��ش洢��ȱʡ��־����ĺ����汾 */ /* log handle get/set function for TLS */
401
+_WINDLL_FUNC LOG *GetGlobalLOG();
402
+_WINDLL_FUNC void SetGlobalLOG( LOG *g );
403
+#define get_global_log	GetGlobalLOG
404
+#define set_global_log	SetGlobalLOG
405
+#endif
406
+
407
+/********************************************************/
408
+/* ����Ϊ���ӿ��� the following development for the hook*/
409
+/********************************************************/
410
+
411
+/* ƽ̨�� */ /* platfrom macros */
412
+#if ( defined _WIN32 )
413
+#define LOG_NEWLINE		"\r\n"
414
+#define LOG_NEWLINE_LEN		2
415
+#define SNPRINTF		_snprintf
416
+#define VSNPRINTF		_vsnprintf
417
+#define STDOUT_HANDLE		1
418
+#define STDERR_HANDLE		2
419
+#define FD_NULL			-1
420
+#define WRITE			_write
421
+#define STAT			_stat
422
+#define ACCESS			_access
423
+#define ACCESS_OK		00
424
+#define RENAME			rename
425
+#define UNLINK			unlink
426
+#elif ( defined __unix ) || ( defined _AIX ) || ( defined __linux__ ) || ( defined __hpux )
427
+#define LOG_NEWLINE		"\n"
428
+#define LOG_NEWLINE_LEN		1
429
+#define SNPRINTF		snprintf
430
+#define VSNPRINTF		vsnprintf
431
+#define STDOUT_HANDLE		STDOUT_FILENO
432
+#define STDERR_HANDLE		STDERR_FILENO
433
+#define FD_NULL			-1
434
+#define WRITE			write
435
+#define STAT			stat
436
+#define ACCESS			access
437
+#define ACCESS_OK		F_OK
438
+#define RENAME			rename
439
+#define UNLINK			unlink
440
+#endif
441
+
442
+/* ����� */ /* code macros */
443
+#if ( defined _WIN32 )
444
+#define SYSTEMTIME2TIMEVAL_USEC(_syst_,_tv_) \
445
+		(_tv_).tv_usec = (_syst_).wMilliseconds * 1000 ;
446
+#define SYSTEMTIME2TM(_syst_,_stime_) \
447
+		(_stime_).tm_year = (_syst_).wYear - 1900 ; \
448
+		(_stime_).tm_mon = (_syst_).wMonth - 1 ; \
449
+		(_stime_).tm_mday = (_syst_).wDay ; \
450
+		(_stime_).tm_hour = (_syst_).wHour ; \
451
+		(_stime_).tm_min = (_syst_).wMinute ; \
452
+		(_stime_).tm_sec = (_syst_).wSecond ;
453
+#define LOCALTIME(_tt_,_stime_) \
454
+	{ \
455
+		SYSTEMTIME	stNow ; \
456
+		GetLocalTime( & stNow ); \
457
+		SYSTEMTIME2TM( stNow , (_stime_) ); \
458
+	}
459
+#elif ( defined __unix ) || ( defined _AIX ) || ( defined __linux__ ) || ( defined __hpux )
460
+#define LOCALTIME(_tt_,_stime_) \
461
+	localtime_r(&(_tt_),&(_stime_));
462
+#endif
463
+
464
+#ifndef STRCMP
465
+#define STRCMP(_a_,_C_,_b_) ( strcmp(_a_,_b_) _C_ 0 )
466
+#define STRNCMP(_a_,_C_,_b_,_n_) ( strncmp(_a_,_b_,_n_) _C_ 0 )
467
+#endif
468
+
469
+#ifndef STRICMP
470
+#if ( defined _WIN32 )
471
+#define STRICMP(_a_,_C_,_b_) ( stricmp(_a_,_b_) _C_ 0 )
472
+#define STRNICMP(_a_,_C_,_b_,_n_) ( strnicmp(_a_,_b_,_n_) _C_ 0 )
473
+#elif ( defined __unix ) || ( defined _AIX ) || ( defined __linux__ ) || ( defined __hpux )
474
+#define STRICMP(_a_,_C_,_b_) ( strcasecmp(_a_,_b_) _C_ 0 )
475
+#define STRNICMP(_a_,_C_,_b_,_n_) ( strncasecmp(_a_,_b_,_n_) _C_ 0 )
476
+#endif
477
+#endif
478
+
479
+#define OFFSET_BUFPTR(_logbuf_,_offset_len_) \
480
+	if( _offset_len_ > 0 && _offset_len_ <= (_logbuf_)->buf_remain_len && (_logbuf_)->bufptr[0] ) \
481
+	{ \
482
+		(_logbuf_)->bufptr += _offset_len_ ; \
483
+		(_logbuf_)->buf_remain_len -= _offset_len_ ; \
484
+	} \
485
+
486
+#define OFFSET_BUFPTR_IN_LOOP(_logbuf_,_offset_len_) \
487
+	if( _offset_len_ > 0 && _offset_len_ <= (_logbuf_)->buf_remain_len && (_logbuf_)->bufptr[0] ) \
488
+	{ \
489
+		(_logbuf_)->bufptr += _offset_len_ ; \
490
+		(_logbuf_)->buf_remain_len -= _offset_len_ ; \
491
+	} \
492
+	else \
493
+	{ \
494
+		break; \
495
+	} \
496
+
497
+_WINDLL_FUNC int SetOpenFlag( LOG *g , char open_flag );
498
+_WINDLL_FUNC char IsLogOpened( LOG *g );
499
+
500
+_WINDLL_FUNC int GetLogLevel( LOG *g );
501
+
502
+_WINDLL_FUNC LOGBUF *GetLogBuffer( LOG *g );
503
+_WINDLL_FUNC LOGBUF *GetHexLogBuffer( LOG *g );
504
+
505
+_WINDLL_FUNC long FormatLogBuffer( LOG *g , LOGBUF *logbuf , const char *format , ... );
506
+_WINDLL_FUNC long FormatLogBufferV( LOG *g , LOGBUF *logbuf , const char *format , va_list valist );
507
+_WINDLL_FUNC long MemcatLogBuffer( LOG *g , LOGBUF *logbuf , const char *append , long len );
508
+
509
+#define set_open_flag		SetOpenFlag
510
+#define is_log_opened		IsLogOpened
511
+
512
+#define get_log_level		GetLogLevel
513
+
514
+#define get_log_buffer		GetLogBuffer
515
+#define get_hex_log_buffer	GetHexLogBuffer
516
+
517
+#define format_log_buffer	FormatLogBuffer
518
+#define format_log_buffer_v	FormatLogBufferV
519
+#define memcat_log_buffer	MemcatLogBuffer
520
+
521
+/* ��־�������ṹ */ /* log buffer structure */
522
+struct tagLOGBUF
523
+{
524
+	long			max_buf_size ;
525
+	long			buf_size ;
526
+	char			*bufbase ;
527
+	char			*bufptr ;
528
+	long			buf_remain_len ;
529
+} ;
530
+
531
+/* ��־����ṹ */ /* log handle structure */
532
+struct tagLOG
533
+{
534
+	/* ���� */ /* basic */
535
+	int			output ;
536
+	char			log_pathfilename[ MAXLEN_FILENAME + 1 ];
537
+	funcOpenLog		*pfuncOpenLogFirst ;
538
+	funcOpenLog		*pfuncOpenLog ;
539
+	funcWriteLog		*pfuncWriteLog ;
540
+	funcChangeTest		*pfuncChangeTest ;
541
+	funcCloseLog		*pfuncCloseLog ;
542
+	funcCloseLog		*pfuncCloseLogFinally ;
543
+	void			*open_handle ;
544
+	void			*test_handle ;
545
+	
546
+	int			fd ;
547
+#if ( defined _WIN32 )
548
+	HANDLE			hFile ;
549
+#endif
550
+	
551
+	char			open_flag ;
552
+	
553
+	/* ��־�ȼ� */ /* log level */
554
+	int			log_level ;
555
+	
556
+	funcFilterLog		*pfuncFilterLog ;
557
+	
558
+	/* ����־��� */ /* log style */
559
+	long			log_styles ;
560
+	funcLogStyle		*pfuncLogStyle ;
561
+	/* �����и�ʽ��񣬹�����ʽ�������飬����д��־ʱ�����������־������ */
562
+	funcLogStyle		*pfuncLogStyles[ 30 + 1 ] ;
563
+	int			style_func_count ;
564
+	
565
+	/* ��־ѡ�� */ /* log options */
566
+	int			log_options ;
567
+	
568
+	long			file_change_test_interval ;
569
+	long			file_change_test_no ;
570
+	struct STAT		file_change_stat ;
571
+	long			fsync_period ;
572
+	long			fsync_elapse ;
573
+	
574
+	/* �Զ����ǩ */ /* custom labels */
575
+	char			cust_label[LOG_MAXCNT_CUST_LABEL][ LOG_MAXLEN_CUST_LABEL + 1 ] ;
576
+	
577
+	/* ��־ת�� */ /* log rotate */
578
+	int			rotate_mode ;
579
+	long			log_rotate_size ;
580
+	long			rotate_file_no ;
581
+	long			rotate_file_count ;
582
+	long			pressure_factor ;
583
+	
584
+	long			skip_count ;
585
+	
586
+	funcAfterRotateFile	*pfuncAfterRotateFile ;
587
+	funcBeforeRotateFile	*pfuncBeforeRotateFile ;
588
+	
589
+	/* ����־������ */ /* log buffer */
590
+	LOGBUF			logbuf ;
591
+	
592
+	/* ʮ��������־������ */ /* hex log buffer */
593
+	LOGBUF			hexlogbuf ;
594
+	
595
+	/* һ������ */ /* level 1 cache */
596
+	struct timeval		cache1_tv ;
597
+	struct tm		cache1_stime ;
598
+	
599
+	/* �������� */ /* level 2 cache */
600
+	struct timeval		cache2_logstyle_tv ;
601
+	struct tm		cache2_logstyle_stime ;
602
+	char			cache2_logstyle_date_buf[ 10 + 1 ] ;
603
+	long			cache2_logstyle_date_buf_len ;
604
+	char			cache2_logstyle_datetime_buf[ 19 + 1 ] ;
605
+	long			cache2_logstyle_datetime_buf_len ;
606
+	
607
+	unsigned long		cache2_logstyle_pid ;
608
+	char			cache2_logstyle_pid_buf[ 20 + 1 ] ;
609
+	long			cache2_logstyle_pid_buf_len ;
610
+	
611
+	unsigned long		cache2_logstyle_tid ;
612
+	char			cache2_logstyle_tid_buf[ 20 + 1 ] ;
613
+	long			cache2_logstyle_tid_buf_len ;
614
+	
615
+	struct timeval		cache2_rotate_tv ;
616
+	struct tm		cache2_rotate_stime ;
617
+	
618
+	/* ת���ļ��� */ /* rotate file lock */
619
+#if ( defined _WIN32 )
620
+	HANDLE			rotate_lock ;
621
+#elif ( defined __unix ) || ( defined _AIX ) || ( defined __linux__ ) || ( defined __hpux )
622
+	int			rotate_lock ;
623
+	struct flock		lock ;
624
+#endif
625
+} ;
626
+
627
+/********************************************************/
628
+/* ����Ϊ�����ӿ� the following for the assist interface*/
629
+/********************************************************/
630
+
631
+/* ���ø������� */ /* config assist functions */
632
+_WINDLL_FUNC int ConvertLogOutput_atoi( char *output_desc , int *p_log_output );
633
+_WINDLL_FUNC int ConvertLogLevel_atoi( char *log_level_desc , int *p_log_level );
634
+_WINDLL_FUNC int ConvertLogLevel_itoa( int log_level , char **log_level_desc );
635
+_WINDLL_FUNC int ConvertLogStyle_atol( char *line_style_desc , long *p_line_style );
636
+_WINDLL_FUNC int ConvertLogOption_atol( char *log_option_desc , long *p_log_option );
637
+_WINDLL_FUNC int ConvertLogRotateMode_atoi( char *rotate_mode_desc , int *p_rotate_mode );
638
+_WINDLL_FUNC int ConvertBufferSize_atol( char *bufsize_desc , long *p_bufsize );
639
+
640
+#define convert_log_output_atoi		ConvertLogOutput_atoi
641
+#define convert_log_level_atoi		ConvertLogLevel_atoi
642
+#define convert_log_level_itoa		ConvertLogLevel_itoa
643
+#define convert_log_style_atol		ConvertLogStyle_atol
644
+#define cnovert_log_option_atol		ConvertLogOption_atol
645
+#define convert_log_rotate_mode_atoi	ConvertLogRotateMode_atoi
646
+#define convert_buffer_size_atol	ConvertBufferSize_atol
647
+
648
+#ifdef __cplusplus
649
+}
650
+#endif
651
+
652
+#endif
653
+

Loading…
Откажи
Сачувај