Showing
98 changed files
with
4079 additions
and
0 deletions
Too many changes to show.
To preserve performance only 98 of 98+ files are displayed.
.gitignore
0 → 100644
1 | +# Miscellaneous | ||
2 | +*.class | ||
3 | +*.log | ||
4 | +*.pyc | ||
5 | +*.swp | ||
6 | +.DS_Store | ||
7 | +.atom/ | ||
8 | +.buildlog/ | ||
9 | +.history | ||
10 | +.svn/ | ||
11 | +migrate_working_dir/ | ||
12 | + | ||
13 | +# IntelliJ related | ||
14 | +*.iml | ||
15 | +*.ipr | ||
16 | +*.iws | ||
17 | +.idea/ | ||
18 | + | ||
19 | +# The .vscode folder contains launch configuration and tasks you configure in | ||
20 | +# VS Code which you may wish to be included in version control, so this line | ||
21 | +# is commented out by default. | ||
22 | +#.vscode/ | ||
23 | + | ||
24 | +# Flutter/Dart/Pub related | ||
25 | +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. | ||
26 | +/pubspec.lock | ||
27 | +**/doc/api/ | ||
28 | +.dart_tool/ | ||
29 | +build/ |
.metadata
0 → 100644
1 | +# This file tracks properties of this Flutter project. | ||
2 | +# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
3 | +# | ||
4 | +# This file should be version controlled and should not be manually edited. | ||
5 | + | ||
6 | +version: | ||
7 | + revision: "7f20e5d18ce4cb80c621533090a7c5113f5bdc52" | ||
8 | + channel: "stable" | ||
9 | + | ||
10 | +project_type: plugin | ||
11 | + | ||
12 | +# Tracks metadata for the flutter migrate command | ||
13 | +migration: | ||
14 | + platforms: | ||
15 | + - platform: root | ||
16 | + create_revision: 7f20e5d18ce4cb80c621533090a7c5113f5bdc52 | ||
17 | + base_revision: 7f20e5d18ce4cb80c621533090a7c5113f5bdc52 | ||
18 | + - platform: android | ||
19 | + create_revision: 7f20e5d18ce4cb80c621533090a7c5113f5bdc52 | ||
20 | + base_revision: 7f20e5d18ce4cb80c621533090a7c5113f5bdc52 | ||
21 | + - platform: ios | ||
22 | + create_revision: 7f20e5d18ce4cb80c621533090a7c5113f5bdc52 | ||
23 | + base_revision: 7f20e5d18ce4cb80c621533090a7c5113f5bdc52 | ||
24 | + | ||
25 | + # User provided section | ||
26 | + | ||
27 | + # List of Local paths (relative to this file) that should be | ||
28 | + # ignored by the migrate tool. | ||
29 | + # | ||
30 | + # Files that are not part of the templates will be ignored by default. | ||
31 | + unmanaged_files: | ||
32 | + - 'lib/main.dart' | ||
33 | + - 'ios/Runner.xcodeproj/project.pbxproj' |
CHANGELOG.md
0 → 100644
LICENSE
0 → 100644
1 | +MIT License | ||
2 | + | ||
3 | +Permission is hereby granted, free of charge, to any person obtaining a copy | ||
4 | +of this software and associated documentation files (the "Software"), to deal | ||
5 | +in the Software without restriction, including without limitation the rights | ||
6 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
7 | +copies of the Software, and to permit persons to whom the Software is | ||
8 | +furnished to do so, subject to the following conditions: | ||
9 | + | ||
10 | +The above copyright notice and this permission notice shall be included in all | ||
11 | +copies or substantial portions of the Software. | ||
12 | + | ||
13 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
14 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
15 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
16 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
17 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
18 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
19 | +SOFTWARE. |
README.md
0 → 100644
1 | +# flutter_xlog | ||
2 | + | ||
3 | +A plugin for use [Mars-XLog](https://github.com/Tencent/mars) in flutter project. | ||
4 | + | ||
5 | +## Usage | ||
6 | + | ||
7 | +### import package | ||
8 | +``` | ||
9 | + | ||
10 | +import 'package:flutter_xlog/flutter_xlog.dart' | ||
11 | + | ||
12 | +``` | ||
13 | +### open XLog | ||
14 | +``` | ||
15 | + | ||
16 | +await XLog.open(XLogConfig(cacheDir: cacheDir, logDir: logDir, consoleLogOpen: true)); | ||
17 | + | ||
18 | +``` | ||
19 | +### write log | ||
20 | +``` | ||
21 | + | ||
22 | +XLog.i("MyApp", "build _MyAppState"); | ||
23 | + | ||
24 | +``` | ||
25 | + | ||
26 | +### close XLog | ||
27 | +You maybe want to close XLog because of switch user's account. | ||
28 | +``` | ||
29 | + | ||
30 | +XLog.close() | ||
31 | + | ||
32 | +``` | ||
33 | + | ||
34 | +## Android Issues | ||
35 | + | ||
36 | +### keep XLog classes in proguard file | ||
37 | +``` | ||
38 | +-keep class com.tencent.mars.** {*;} | ||
39 | +``` | ||
40 | + | ||
41 | +### pick libc++_shared | ||
42 | +When you run with debug mode, you may encounter a problem like this: | ||
43 | +``` | ||
44 | + 2 files found with path 'lib/arm64-v8a/libc++_shared.so' from inputs: | ||
45 | + - xxxx | ||
46 | + - xxxx | ||
47 | +``` | ||
48 | +To solve that problem, we recommend you to copy the libc++_shared.so to your app project and then pick it in build.gradle like this: | ||
49 | +``` | ||
50 | + packagingOptions { | ||
51 | + pickFirst 'jniLibs/armeabi-v7a/libc++_shared.so' | ||
52 | + pickFirst 'jniLibs/arm64-v8a/libc++_shared.so' | ||
53 | + } | ||
54 | +``` | ||
55 | + | ||
56 | +### iOS Issues | ||
57 | + | ||
58 | +Mars-XLog currently does not support iOS simulator. So you can only use it on iphone devices. | ||
59 | + |
analysis_options.yaml
0 → 100644
android/.gitignore
0 → 100644
android/build.gradle
0 → 100644
1 | +group 'com.tencent.xlog' | ||
2 | +version '1.0-SNAPSHOT' | ||
3 | + | ||
4 | +buildscript { | ||
5 | + ext.kotlin_version = '1.7.10' | ||
6 | + repositories { | ||
7 | + google() | ||
8 | + mavenCentral() | ||
9 | + } | ||
10 | + | ||
11 | + dependencies { | ||
12 | + classpath 'com.android.tools.build:gradle:7.3.0' | ||
13 | + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | ||
14 | + } | ||
15 | +} | ||
16 | + | ||
17 | +rootProject.allprojects { | ||
18 | + repositories { | ||
19 | + google() | ||
20 | + mavenCentral() | ||
21 | + } | ||
22 | +} | ||
23 | + | ||
24 | +apply plugin: 'com.android.library' | ||
25 | +apply plugin: 'kotlin-android' | ||
26 | + | ||
27 | +android { | ||
28 | + | ||
29 | + compileSdkVersion 33 | ||
30 | + | ||
31 | + compileOptions { | ||
32 | + sourceCompatibility JavaVersion.VERSION_1_8 | ||
33 | + targetCompatibility JavaVersion.VERSION_1_8 | ||
34 | + } | ||
35 | + | ||
36 | + kotlinOptions { | ||
37 | + jvmTarget = '1.8' | ||
38 | + } | ||
39 | + | ||
40 | + sourceSets { | ||
41 | + main.java.srcDirs += 'src/main/kotlin' | ||
42 | + main.java.srcDirs += 'src/main/java' | ||
43 | + main.jniLibs.srcDirs += 'src/main/jniLibs' | ||
44 | + } | ||
45 | + | ||
46 | + defaultConfig { | ||
47 | + minSdkVersion 19 | ||
48 | + } | ||
49 | +} |
android/settings.gradle
0 → 100644
1 | +rootProject.name = 'flutter_xlog' |
android/src/main/AndroidManifest.xml
0 → 100644
1 | +package com.tencent.mars.xlog; | ||
2 | + | ||
3 | +import android.content.Context; | ||
4 | +import android.os.Handler; | ||
5 | +import android.os.Looper; | ||
6 | +import android.os.Process; | ||
7 | +import android.widget.Toast; | ||
8 | + | ||
9 | +import java.util.HashMap; | ||
10 | +import java.util.Map; | ||
11 | + | ||
12 | + | ||
13 | +/** | ||
14 | + * @author zhaoyuan zhangweizang | ||
15 | + */ | ||
16 | +public class Log { | ||
17 | + private static final String TAG = "mars.xlog.log"; | ||
18 | + | ||
19 | + public static final int LEVEL_VERBOSE = 0; | ||
20 | + public static final int LEVEL_DEBUG = 1; | ||
21 | + public static final int LEVEL_INFO = 2; | ||
22 | + public static final int LEVEL_WARNING = 3; | ||
23 | + public static final int LEVEL_ERROR = 4; | ||
24 | + public static final int LEVEL_FATAL = 5; | ||
25 | + public static final int LEVEL_NONE = 6; | ||
26 | + | ||
27 | + // defaults to LEVEL_NONE | ||
28 | + private static int level = LEVEL_NONE; | ||
29 | + public static Context toastSupportContext = null; | ||
30 | + | ||
31 | + public interface LogImp { | ||
32 | + | ||
33 | + void logV(long logInstancePtr, String tag, String filename, String funcname, int linuxTid, int pid, long tid, long maintid, String log); | ||
34 | + | ||
35 | + void logI(long logInstancePtr, String tag, String filename, String funcname, int linuxTid, int pid, long tid, long maintid, String log); | ||
36 | + | ||
37 | + void logD(long logInstancePtr, String tag, String filename, String funcname, int linuxTid, int pid, long tid, long maintid, String log); | ||
38 | + | ||
39 | + void logW(long logInstancePtr, String tag, String filename, String funcname, int linuxTid, int pid, long tid, long maintid, String log); | ||
40 | + | ||
41 | + void logE(long logInstancePtr, String tag, String filename, String funcname, int linuxTid, int pid, long tid, long maintid, String log); | ||
42 | + | ||
43 | + void logF(long logInstancePtr, String tag, String filename, String funcname, int linuxTid, int pid, long tid, long maintid, String log); | ||
44 | + | ||
45 | + int getLogLevel(long logInstancePtr); | ||
46 | + | ||
47 | + void setAppenderMode(long logInstancePtr, int mode); | ||
48 | + | ||
49 | + long openLogInstance(int level, int mode, String cacheDir, String logDir, String nameprefix, int cacheDays); | ||
50 | + | ||
51 | + long getXlogInstance(String nameprefix); | ||
52 | + | ||
53 | + void releaseXlogInstance(String nameprefix); | ||
54 | + | ||
55 | + void appenderOpen(int level, int mode, String cacheDir, String logDir, String nameprefix, int cacheDays); | ||
56 | + | ||
57 | + void appenderClose(); | ||
58 | + | ||
59 | + void appenderFlush(long logInstancePtr, boolean isSync); | ||
60 | + | ||
61 | + void setConsoleLogOpen(long logInstancePtr, boolean isOpen); | ||
62 | + | ||
63 | + void setMaxFileSize(long logInstancePtr, long aliveSeconds); | ||
64 | + | ||
65 | + void setMaxAliveTime(long logInstancePtr, long aliveSeconds); | ||
66 | + | ||
67 | + } | ||
68 | + | ||
69 | + private static LogImp debugLog = new LogImp() { | ||
70 | + private Handler handler = new Handler(Looper.getMainLooper()); | ||
71 | + | ||
72 | + @Override | ||
73 | + public void logV(long logInstancePtr, String tag, String filename, String funcname, int line, int pid, long tid, long maintid, String log) { | ||
74 | + if (level <= LEVEL_VERBOSE) { | ||
75 | + android.util.Log.v(tag, log); | ||
76 | + } | ||
77 | + } | ||
78 | + | ||
79 | + @Override | ||
80 | + public void logI(long logInstancePtr, String tag, String filename, String funcname, int line, int pid, long tid, long maintid, String log) { | ||
81 | + if (level <= LEVEL_INFO) { | ||
82 | + android.util.Log.i(tag, log); | ||
83 | + } | ||
84 | + } | ||
85 | + | ||
86 | + @Override | ||
87 | + public void logD(long logInstancePtr, String tag, String filename, String funcname, int line, int pid, long tid, long maintid, String log) { | ||
88 | + if (level <= LEVEL_DEBUG) { | ||
89 | + android.util.Log.d(tag, log); | ||
90 | + } | ||
91 | + | ||
92 | + } | ||
93 | + | ||
94 | + @Override | ||
95 | + public void logW(long logInstancePtr, String tag, String filename, String funcname, int line, int pid, long tid, long maintid, String log) { | ||
96 | + if (level <= LEVEL_WARNING) { | ||
97 | + android.util.Log.w(tag, log); | ||
98 | + } | ||
99 | + | ||
100 | + } | ||
101 | + | ||
102 | + @Override | ||
103 | + public void logE(long logInstancePtr, String tag, String filename, String funcname, int line, int pid, long tid, long maintid, String log) { | ||
104 | + if (level <= LEVEL_ERROR) { | ||
105 | + android.util.Log.e(tag, log); | ||
106 | + } | ||
107 | + } | ||
108 | + | ||
109 | + | ||
110 | + @Override | ||
111 | + public void logF(long logInstancePtr, String tag, String filename, String funcname, int line, int pid, long tid, long maintid, final String log) { | ||
112 | + if (level > LEVEL_FATAL) { | ||
113 | + return; | ||
114 | + } | ||
115 | + android.util.Log.e(tag, log); | ||
116 | + if (toastSupportContext != null) { | ||
117 | + handler.post(new Runnable() { | ||
118 | + @Override | ||
119 | + public void run() { | ||
120 | + Toast.makeText(toastSupportContext, log, Toast.LENGTH_LONG).show(); | ||
121 | + } | ||
122 | + }); | ||
123 | + } | ||
124 | + } | ||
125 | + | ||
126 | + @Override | ||
127 | + public int getLogLevel(long logInstancePtr) { | ||
128 | + return level; | ||
129 | + } | ||
130 | + | ||
131 | + @Override | ||
132 | + public void setAppenderMode(long logInstancePtr, int mode) { | ||
133 | + | ||
134 | + } | ||
135 | + | ||
136 | + @Override | ||
137 | + public long openLogInstance(int level, int mode, String cacheDir, String logDir, String nameprefix, int cacheDays) { | ||
138 | + return 0; | ||
139 | + } | ||
140 | + | ||
141 | + @Override | ||
142 | + public long getXlogInstance(String nameprefix) { | ||
143 | + return 0; | ||
144 | + } | ||
145 | + | ||
146 | + @Override | ||
147 | + public void releaseXlogInstance(String nameprefix) { | ||
148 | + | ||
149 | + } | ||
150 | + | ||
151 | + @Override | ||
152 | + public void appenderOpen(int level, int mode, String cacheDir, String logDir, String nameprefix, int cacheDays) { | ||
153 | + | ||
154 | + } | ||
155 | + | ||
156 | + @Override | ||
157 | + public void appenderClose() { | ||
158 | + | ||
159 | + } | ||
160 | + | ||
161 | + @Override | ||
162 | + public void appenderFlush(long logInstancePtr, boolean isSync) { | ||
163 | + } | ||
164 | + | ||
165 | + @Override | ||
166 | + public void setConsoleLogOpen(long logInstancePtr, boolean isOpen) { | ||
167 | + | ||
168 | + } | ||
169 | + | ||
170 | + @Override | ||
171 | + public void setMaxAliveTime(long logInstancePtr, long aliveSeconds) { | ||
172 | + | ||
173 | + } | ||
174 | + | ||
175 | + @Override | ||
176 | + public void setMaxFileSize(long logInstancePtr, long aliveSeconds) { | ||
177 | + | ||
178 | + } | ||
179 | + | ||
180 | + }; | ||
181 | + | ||
182 | + private static LogImp logImp = debugLog; | ||
183 | + | ||
184 | + public static void setLogImp(LogImp imp) { | ||
185 | + logImp = imp; | ||
186 | + } | ||
187 | + | ||
188 | + public static LogImp getImpl() { | ||
189 | + return logImp; | ||
190 | + } | ||
191 | + | ||
192 | + public static void appenderOpen(int level, int mode, String cacheDir, String logDir, String nameprefix, int cacheDays) { | ||
193 | + if (logImp != null) { | ||
194 | + logImp.appenderOpen(level, mode, cacheDir, logDir, nameprefix, cacheDays); | ||
195 | + } | ||
196 | + } | ||
197 | + | ||
198 | + public static void appenderClose() { | ||
199 | + if (logImp != null) { | ||
200 | + logImp.appenderClose(); | ||
201 | + for (Map.Entry<String, LogInstance> entry : sLogInstanceMap.entrySet()) { | ||
202 | + closeLogInstance(entry.getKey()); | ||
203 | + } | ||
204 | + } | ||
205 | + } | ||
206 | + | ||
207 | + public static void appenderFlush() { | ||
208 | + if (logImp != null) { | ||
209 | + logImp.appenderFlush(0, false); | ||
210 | + for (Map.Entry<String, LogInstance> entry : sLogInstanceMap.entrySet()) { | ||
211 | + entry.getValue().appenderFlush(); | ||
212 | + } | ||
213 | + } | ||
214 | + } | ||
215 | + | ||
216 | + public static void appenderFlushSync(boolean isSync) { | ||
217 | + if (logImp != null) { | ||
218 | + logImp.appenderFlush(0, isSync); | ||
219 | + | ||
220 | + } | ||
221 | + } | ||
222 | + | ||
223 | + public static int getLogLevel() { | ||
224 | + if (logImp != null) { | ||
225 | + return logImp.getLogLevel(0); | ||
226 | + } | ||
227 | + return LEVEL_NONE; | ||
228 | + } | ||
229 | + | ||
230 | + public static void setLevel(final int level, final boolean jni) { | ||
231 | + Log.level = level; | ||
232 | + android.util.Log.w(TAG, "new log level: " + level); | ||
233 | + | ||
234 | + if (jni) { | ||
235 | + android.util.Log.e(TAG, "no jni log level support"); | ||
236 | + } | ||
237 | + } | ||
238 | + | ||
239 | + public static void setConsoleLogOpen(boolean isOpen) { | ||
240 | + if (logImp != null) { | ||
241 | + logImp.setConsoleLogOpen(0, isOpen); | ||
242 | + } | ||
243 | + } | ||
244 | + | ||
245 | + /** | ||
246 | + * use f(tag, format, obj) instead | ||
247 | + * | ||
248 | + * @param tag | ||
249 | + * @param msg | ||
250 | + */ | ||
251 | + public static void f(final String tag, final String msg) { | ||
252 | + f(tag, msg, (Object[]) null); | ||
253 | + } | ||
254 | + | ||
255 | + /** | ||
256 | + * use e(tag, format, obj) instead | ||
257 | + * | ||
258 | + * @param tag | ||
259 | + * @param msg | ||
260 | + */ | ||
261 | + public static void e(final String tag, final String msg) { | ||
262 | + e(tag, msg, (Object[]) null); | ||
263 | + } | ||
264 | + | ||
265 | + /** | ||
266 | + * use w(tag, format, obj) instead | ||
267 | + * | ||
268 | + * @param tag | ||
269 | + * @param msg | ||
270 | + */ | ||
271 | + public static void w(final String tag, final String msg) { | ||
272 | + w(tag, msg, (Object[]) null); | ||
273 | + } | ||
274 | + | ||
275 | + /** | ||
276 | + * use i(tag, format, obj) instead | ||
277 | + * | ||
278 | + * @param tag | ||
279 | + * @param msg | ||
280 | + */ | ||
281 | + public static void i(final String tag, final String msg) { | ||
282 | + i(tag, msg, (Object[]) null); | ||
283 | + } | ||
284 | + | ||
285 | + /** | ||
286 | + * use d(tag, format, obj) instead | ||
287 | + * | ||
288 | + * @param tag | ||
289 | + * @param msg | ||
290 | + */ | ||
291 | + public static void d(final String tag, final String msg) { | ||
292 | + d(tag, msg, (Object[]) null); | ||
293 | + } | ||
294 | + | ||
295 | + /** | ||
296 | + * use v(tag, format, obj) instead | ||
297 | + * | ||
298 | + * @param tag | ||
299 | + * @param msg | ||
300 | + */ | ||
301 | + public static void v(final String tag, final String msg) { | ||
302 | + v(tag, msg, (Object[]) null); | ||
303 | + } | ||
304 | + | ||
305 | + public static void f(String tag, final String format, final Object... obj) { | ||
306 | + if (logImp != null && logImp.getLogLevel(0) <= LEVEL_FATAL) { | ||
307 | + final String log = obj == null ? format : String.format(format, obj); | ||
308 | + logImp.logF(0, tag, "", "", 0, Process.myPid(), Thread.currentThread().getId(), Looper.getMainLooper().getThread().getId(), log); | ||
309 | + } | ||
310 | + } | ||
311 | + | ||
312 | + public static void e(String tag, final String format, final Object... obj) { | ||
313 | + if (logImp != null && logImp.getLogLevel(0) <= LEVEL_ERROR) { | ||
314 | + String log = obj == null ? format : String.format(format, obj); | ||
315 | + if (log == null) { | ||
316 | + log = ""; | ||
317 | + } | ||
318 | + logImp.logE(0, tag, "", "", 0, Process.myPid(), Thread.currentThread().getId(), Looper.getMainLooper().getThread().getId(), log); | ||
319 | + } | ||
320 | + } | ||
321 | + | ||
322 | + public static void w(String tag, final String format, final Object... obj) { | ||
323 | + if (logImp != null && logImp.getLogLevel(0) <= LEVEL_WARNING) { | ||
324 | + String log = obj == null ? format : String.format(format, obj); | ||
325 | + if (log == null) { | ||
326 | + log = ""; | ||
327 | + } | ||
328 | + logImp.logW(0, tag, "", "", 0, Process.myPid(), Thread.currentThread().getId(), Looper.getMainLooper().getThread().getId(), log); | ||
329 | + } | ||
330 | + } | ||
331 | + | ||
332 | + public static void i(String tag, final String format, final Object... obj) { | ||
333 | + if (logImp != null && logImp.getLogLevel(0) <= LEVEL_INFO) { | ||
334 | + String log = obj == null ? format : String.format(format, obj); | ||
335 | + if (log == null) { | ||
336 | + log = ""; | ||
337 | + } | ||
338 | + logImp.logI(0, tag, "", "", 0, Process.myPid(), Thread.currentThread().getId(), Looper.getMainLooper().getThread().getId(), log); | ||
339 | + } | ||
340 | + } | ||
341 | + | ||
342 | + public static void d(String tag, final String format, final Object... obj) { | ||
343 | + if (logImp != null && logImp.getLogLevel(0) <= LEVEL_DEBUG) { | ||
344 | + String log = obj == null ? format : String.format(format, obj); | ||
345 | + if (log == null) { | ||
346 | + log = ""; | ||
347 | + } | ||
348 | + logImp.logD(0, tag, "", "", 0, Process.myPid(), Thread.currentThread().getId(), Looper.getMainLooper().getThread().getId(), log); | ||
349 | + } | ||
350 | + } | ||
351 | + | ||
352 | + public static void v(String tag, final String format, final Object... obj) { | ||
353 | + if (logImp != null && logImp.getLogLevel(0) <= LEVEL_VERBOSE) { | ||
354 | + String log = obj == null ? format : String.format(format, obj); | ||
355 | + if (log == null) { | ||
356 | + log = ""; | ||
357 | + } | ||
358 | + logImp.logV(0, tag, "", "", 0, Process.myPid(), Thread.currentThread().getId(), Looper.getMainLooper().getThread().getId(), log); | ||
359 | + } | ||
360 | + } | ||
361 | + | ||
362 | + public static void printErrStackTrace(String tag, Throwable tr, final String format, final Object... obj) { | ||
363 | + if (logImp != null && logImp.getLogLevel(0) <= LEVEL_ERROR) { | ||
364 | + String log = obj == null ? format : String.format(format, obj); | ||
365 | + if (log == null) { | ||
366 | + log = ""; | ||
367 | + } | ||
368 | + log += " " + android.util.Log.getStackTraceString(tr); | ||
369 | + logImp.logE(0, tag, "", "", 0, Process.myPid(), Thread.currentThread().getId(), Looper.getMainLooper().getThread().getId(), log); | ||
370 | + } | ||
371 | + } | ||
372 | + | ||
373 | + // private static final String SYS_INFO; | ||
374 | + | ||
375 | + // static { | ||
376 | + // final StringBuilder sb = new StringBuilder(); | ||
377 | + // try { | ||
378 | + // sb.append("VERSION.RELEASE:[" + android.os.Build.VERSION.RELEASE); | ||
379 | + // sb.append("] VERSION.CODENAME:[" + android.os.Build.VERSION.CODENAME); | ||
380 | + // sb.append("] VERSION.INCREMENTAL:[" + android.os.Build.VERSION.INCREMENTAL); | ||
381 | + // sb.append("] BOARD:[" + android.os.Build.BOARD); | ||
382 | + // sb.append("] DEVICE:[" + android.os.Build.DEVICE); | ||
383 | + // sb.append("] DISPLAY:[" + android.os.Build.DISPLAY); | ||
384 | + // sb.append("] FINGERPRINT:[" + android.os.Build.FINGERPRINT); | ||
385 | + // sb.append("] HOST:[" + android.os.Build.HOST); | ||
386 | + // sb.append("] MANUFACTURER:[" + android.os.Build.MANUFACTURER); | ||
387 | + // sb.append("] MODEL:[" + android.os.Build.MODEL); | ||
388 | + // sb.append("] PRODUCT:[" + android.os.Build.PRODUCT); | ||
389 | + // sb.append("] TAGS:[" + android.os.Build.TAGS); | ||
390 | + // sb.append("] TYPE:[" + android.os.Build.TYPE); | ||
391 | + // sb.append("] USER:[" + android.os.Build.USER + "]"); | ||
392 | + // } catch (Throwable e) { | ||
393 | + // e.printStackTrace(); | ||
394 | + // } | ||
395 | + | ||
396 | + // SYS_INFO = sb.toString(); | ||
397 | + // } | ||
398 | + | ||
399 | + // public static String getSysInfo() { | ||
400 | + // return SYS_INFO; | ||
401 | + // } | ||
402 | + | ||
403 | + private static Map<String, LogInstance> sLogInstanceMap = new HashMap<>(); | ||
404 | + | ||
405 | + public static LogInstance openLogInstance(int level, int mode, String cacheDir, String logDir, String nameprefix, int cacheDays) { | ||
406 | + synchronized (sLogInstanceMap) { | ||
407 | + if (sLogInstanceMap.containsKey(nameprefix)) { | ||
408 | + return sLogInstanceMap.get(nameprefix); | ||
409 | + } | ||
410 | + LogInstance instance = new LogInstance(level, mode, cacheDir, logDir, nameprefix, cacheDays); | ||
411 | + sLogInstanceMap.put(nameprefix, instance); | ||
412 | + return instance; | ||
413 | + } | ||
414 | + } | ||
415 | + | ||
416 | + public static void closeLogInstance(String prefix) { | ||
417 | + synchronized (sLogInstanceMap) { | ||
418 | + if (null != logImp) { | ||
419 | + if (sLogInstanceMap.containsKey(prefix)) { | ||
420 | + LogInstance logInstance = sLogInstanceMap.remove(prefix); | ||
421 | + logImp.releaseXlogInstance(prefix); | ||
422 | + logInstance.mLogInstancePtr = 0; | ||
423 | + } | ||
424 | + } | ||
425 | + } | ||
426 | + } | ||
427 | + | ||
428 | + public static LogInstance getLogInstance(String prefix) { | ||
429 | + synchronized (sLogInstanceMap) { | ||
430 | + if (sLogInstanceMap.containsKey(prefix)) { | ||
431 | + return sLogInstanceMap.get(prefix); | ||
432 | + } | ||
433 | + return null; | ||
434 | + } | ||
435 | + } | ||
436 | + | ||
437 | + public static class LogInstance { | ||
438 | + | ||
439 | + private long mLogInstancePtr = 0; | ||
440 | + | ||
441 | + private String mPrefix = null; | ||
442 | + | ||
443 | + private LogInstance(int level, int mode, String cacheDir, String logDir, String nameprefix, int cacheDays) { | ||
444 | + if (logImp != null) { | ||
445 | + mLogInstancePtr = logImp.openLogInstance(level, mode, cacheDir, logDir, nameprefix, cacheDays); | ||
446 | + mPrefix = nameprefix; | ||
447 | + } | ||
448 | + } | ||
449 | + | ||
450 | + public void f(String tag, final String format, final Object... obj) { | ||
451 | + if (logImp != null && getLogLevel() <= LEVEL_FATAL && mLogInstancePtr != 0) { | ||
452 | + final String log = obj == null ? format : String.format(format, obj); | ||
453 | + logImp.logF(mLogInstancePtr, tag, "", "", Process.myTid(), Process.myPid(), Thread.currentThread().getId(), Looper.getMainLooper().getThread().getId(), log); | ||
454 | + } | ||
455 | + } | ||
456 | + | ||
457 | + public void e(String tag, final String format, final Object... obj) { | ||
458 | + if (logImp != null && getLogLevel() <= LEVEL_ERROR && mLogInstancePtr != 0) { | ||
459 | + String log = obj == null ? format : String.format(format, obj); | ||
460 | + if (log == null) { | ||
461 | + log = ""; | ||
462 | + } | ||
463 | + logImp.logE(mLogInstancePtr, tag, "", "", Process.myTid(), Process.myPid(), Thread.currentThread().getId(), Looper.getMainLooper().getThread().getId(), log); | ||
464 | + } | ||
465 | + } | ||
466 | + | ||
467 | + public void w(String tag, final String format, final Object... obj) { | ||
468 | + if (logImp != null && getLogLevel() <= LEVEL_WARNING && mLogInstancePtr != 0) { | ||
469 | + String log = obj == null ? format : String.format(format, obj); | ||
470 | + if (log == null) { | ||
471 | + log = ""; | ||
472 | + } | ||
473 | + logImp.logW(mLogInstancePtr, tag, "", "", Process.myTid(), Process.myPid(), Thread.currentThread().getId(), Looper.getMainLooper().getThread().getId(), log); | ||
474 | + } | ||
475 | + } | ||
476 | + | ||
477 | + public void i(String tag, final String format, final Object... obj) { | ||
478 | + if (logImp != null && getLogLevel() <= LEVEL_INFO && mLogInstancePtr != 0) { | ||
479 | + String log = obj == null ? format : String.format(format, obj); | ||
480 | + if (log == null) { | ||
481 | + log = ""; | ||
482 | + } | ||
483 | + logImp.logI(mLogInstancePtr, tag, "", "", Process.myTid(), Process.myPid(), Thread.currentThread().getId(), Looper.getMainLooper().getThread().getId(), log); | ||
484 | + } | ||
485 | + } | ||
486 | + | ||
487 | + public void d(String tag, final String format, final Object... obj) { | ||
488 | + if (logImp != null && getLogLevel() <= LEVEL_DEBUG && mLogInstancePtr != 0) { | ||
489 | + String log = obj == null ? format : String.format(format, obj); | ||
490 | + if (log == null) { | ||
491 | + log = ""; | ||
492 | + } | ||
493 | + logImp.logD(mLogInstancePtr, tag, "", "", Process.myTid(), Process.myPid(), Thread.currentThread().getId(), Looper.getMainLooper().getThread().getId(), log); | ||
494 | + } | ||
495 | + } | ||
496 | + | ||
497 | + public void v(String tag, final String format, final Object... obj) { | ||
498 | + if (logImp != null && getLogLevel() <= LEVEL_VERBOSE && mLogInstancePtr != 0) { | ||
499 | + String log = obj == null ? format : String.format(format, obj); | ||
500 | + if (log == null) { | ||
501 | + log = ""; | ||
502 | + } | ||
503 | + logImp.logV(mLogInstancePtr, tag, "", "", Process.myTid(), Process.myPid(), Thread.currentThread().getId(), Looper.getMainLooper().getThread().getId(), log); | ||
504 | + } | ||
505 | + } | ||
506 | + | ||
507 | + | ||
508 | + public void printErrStackTrace(String tag, Throwable tr, final String format, final Object... obj) { | ||
509 | + if (logImp != null && getLogLevel() <= LEVEL_ERROR && mLogInstancePtr != 0) { | ||
510 | + String log = obj == null ? format : String.format(format, obj); | ||
511 | + if (log == null) { | ||
512 | + log = ""; | ||
513 | + } | ||
514 | + log += " " + android.util.Log.getStackTraceString(tr); | ||
515 | + logImp.logE(mLogInstancePtr, tag, "", "", Process.myTid(), Process.myPid(), Thread.currentThread().getId(), Looper.getMainLooper().getThread().getId(), log); | ||
516 | + } | ||
517 | + } | ||
518 | + | ||
519 | + | ||
520 | + public void appenderFlush() { | ||
521 | + if (logImp != null && mLogInstancePtr != 0) { | ||
522 | + logImp.appenderFlush(mLogInstancePtr, false); | ||
523 | + } | ||
524 | + } | ||
525 | + | ||
526 | + public void appenderFlushSync() { | ||
527 | + if (logImp != null && mLogInstancePtr != 0) { | ||
528 | + logImp.appenderFlush(mLogInstancePtr, true); | ||
529 | + } | ||
530 | + } | ||
531 | + | ||
532 | + public int getLogLevel() { | ||
533 | + if (logImp != null && mLogInstancePtr != 0) { | ||
534 | + return logImp.getLogLevel(mLogInstancePtr); | ||
535 | + } | ||
536 | + return LEVEL_NONE; | ||
537 | + } | ||
538 | + | ||
539 | + public void setConsoleLogOpen(boolean isOpen) { | ||
540 | + if (null != logImp && mLogInstancePtr != 0) { | ||
541 | + logImp.setConsoleLogOpen(mLogInstancePtr, isOpen); | ||
542 | + } | ||
543 | + } | ||
544 | + | ||
545 | + | ||
546 | + } | ||
547 | +} |
1 | +package com.tencent.mars.xlog; | ||
2 | + | ||
3 | +public class Xlog implements Log.LogImp { | ||
4 | + | ||
5 | + public static final int LEVEL_ALL = 0; | ||
6 | + public static final int LEVEL_VERBOSE = 0; | ||
7 | + public static final int LEVEL_DEBUG = 1; | ||
8 | + public static final int LEVEL_INFO = 2; | ||
9 | + public static final int LEVEL_WARNING = 3; | ||
10 | + public static final int LEVEL_ERROR = 4; | ||
11 | + public static final int LEVEL_FATAL = 5; | ||
12 | + public static final int LEVEL_NONE = 6; | ||
13 | + | ||
14 | + public static final int COMPRESS_LEVEL1 = 1; | ||
15 | + public static final int COMPRESS_LEVEL2 = 2; | ||
16 | + public static final int COMPRESS_LEVEL3 = 3; | ||
17 | + public static final int COMPRESS_LEVEL4 = 4; | ||
18 | + public static final int COMPRESS_LEVEL5 = 5; | ||
19 | + public static final int COMPRESS_LEVEL6 = 6; | ||
20 | + public static final int COMPRESS_LEVEL7 = 7; | ||
21 | + public static final int COMPRESS_LEVEL8 = 8; | ||
22 | + public static final int COMPRESS_LEVEL9 = 9; | ||
23 | + | ||
24 | + public static final int AppednerModeAsync = 0; | ||
25 | + public static final int AppednerModeSync = 1; | ||
26 | + | ||
27 | + public static final int ZLIB_MODE = 0; | ||
28 | + public static final int ZSTD_MODE = 1; | ||
29 | + | ||
30 | + static class XLoggerInfo { | ||
31 | + public int level; | ||
32 | + public String tag; | ||
33 | + public String filename; | ||
34 | + public String funcname; | ||
35 | + public int line; | ||
36 | + public long pid; | ||
37 | + public long tid; | ||
38 | + public long maintid; | ||
39 | + } | ||
40 | + | ||
41 | + public static class XLogConfig { | ||
42 | + public int level = LEVEL_INFO; | ||
43 | + public int mode = AppednerModeAsync; | ||
44 | + public String logdir; | ||
45 | + public String nameprefix; | ||
46 | + public String pubkey = ""; | ||
47 | + public int compressmode = ZLIB_MODE; | ||
48 | + public int compresslevel = 0; | ||
49 | + public String cachedir; | ||
50 | + public int cachedays = 0; | ||
51 | + } | ||
52 | + | ||
53 | + public void open(boolean isLoadLib, int level, int mode, String cacheDir, String logDir, String nameprefix, String pubkey) { | ||
54 | + if (isLoadLib) { | ||
55 | + System.loadLibrary("c++_shared"); | ||
56 | + System.loadLibrary("marsxlog"); | ||
57 | + } | ||
58 | + | ||
59 | + XLogConfig logConfig = new XLogConfig(); | ||
60 | + logConfig.level = level; | ||
61 | + logConfig.mode = mode; | ||
62 | + logConfig.logdir = logDir; | ||
63 | + logConfig.nameprefix = nameprefix; | ||
64 | + logConfig.pubkey = pubkey; | ||
65 | + logConfig.compressmode = ZLIB_MODE; | ||
66 | + logConfig.compresslevel = 0; | ||
67 | + logConfig.cachedir = cacheDir; | ||
68 | + logConfig.cachedays = 0; | ||
69 | + appenderOpen(logConfig); | ||
70 | + } | ||
71 | + | ||
72 | + private static String decryptTag(String tag) { | ||
73 | + return tag; | ||
74 | + } | ||
75 | + | ||
76 | + @Override | ||
77 | + public void logV(long logInstancePtr, String tag, String filename, String funcname, int line, int pid, long tid, long maintid, String log) { | ||
78 | + logWrite2(logInstancePtr, LEVEL_VERBOSE, decryptTag(tag), filename, funcname, line, pid, tid, maintid, log); | ||
79 | + } | ||
80 | + | ||
81 | + @Override | ||
82 | + public void logD(long logInstancePtr, String tag, String filename, String funcname, int line, int pid, long tid, long maintid, String log) { | ||
83 | + logWrite2(logInstancePtr, LEVEL_DEBUG, decryptTag(tag), filename, funcname, line, pid, tid, maintid, log); | ||
84 | + } | ||
85 | + | ||
86 | + @Override | ||
87 | + public void logI(long logInstancePtr, String tag, String filename, String funcname, int line, int pid, long tid, long maintid, String log) { | ||
88 | + logWrite2(logInstancePtr, LEVEL_INFO, decryptTag(tag), filename, funcname, line, pid, tid, maintid, log); | ||
89 | + } | ||
90 | + | ||
91 | + @Override | ||
92 | + public void logW(long logInstancePtr, String tag, String filename, String funcname, int line, int pid, long tid, long maintid, String log) { | ||
93 | + logWrite2(logInstancePtr, LEVEL_WARNING, decryptTag(tag), filename, funcname, line, pid, tid, maintid, log); | ||
94 | + } | ||
95 | + | ||
96 | + @Override | ||
97 | + public void logE(long logInstancePtr, String tag, String filename, String funcname, int line, int pid, long tid, long maintid, String log) { | ||
98 | + logWrite2(logInstancePtr, LEVEL_ERROR, decryptTag(tag), filename, funcname, line, pid, tid, maintid, log); | ||
99 | + } | ||
100 | + | ||
101 | + @Override | ||
102 | + public void logF(long logInstancePtr, String tag, String filename, String funcname, int line, int pid, long tid, long maintid, String log) { | ||
103 | + logWrite2(logInstancePtr, LEVEL_FATAL, decryptTag(tag), filename, funcname, line, pid, tid, maintid, log); | ||
104 | + } | ||
105 | + | ||
106 | + | ||
107 | + @Override | ||
108 | + public void appenderOpen(int level, int mode, String cacheDir, String logDir, String nameprefix, int cacheDays) { | ||
109 | + | ||
110 | + XLogConfig logConfig = new XLogConfig(); | ||
111 | + logConfig.level = level; | ||
112 | + logConfig.mode = mode; | ||
113 | + logConfig.logdir = logDir; | ||
114 | + logConfig.nameprefix = nameprefix; | ||
115 | + logConfig.compressmode = ZLIB_MODE; | ||
116 | + logConfig.pubkey = ""; | ||
117 | + logConfig.cachedir = cacheDir; | ||
118 | + logConfig.cachedays = cacheDays; | ||
119 | + | ||
120 | + appenderOpen(logConfig); | ||
121 | + } | ||
122 | + | ||
123 | + public static native void logWrite(XLoggerInfo logInfo, String log); | ||
124 | + | ||
125 | + public static void logWrite2(int level, String tag, String filename, String funcname, int line, int pid, long tid, long maintid, String log){ | ||
126 | + logWrite2(0, level, tag, filename ,funcname, line, pid, tid, maintid, log); | ||
127 | + } | ||
128 | + | ||
129 | + public static native void logWrite2(long logInstancePtr, int level, String tag, String filename, String funcname, int line, int pid, long tid, long maintid, String log); | ||
130 | + | ||
131 | + @Override | ||
132 | + public native int getLogLevel(long logInstancePtr); | ||
133 | + | ||
134 | + | ||
135 | + @Override | ||
136 | + public native void setAppenderMode(long logInstancePtr, int mode); | ||
137 | + | ||
138 | + @Override | ||
139 | + public long openLogInstance(int level, int mode, String cacheDir, String logDir, String nameprefix, int cacheDays) { | ||
140 | + XLogConfig logConfig = new XLogConfig(); | ||
141 | + logConfig.level = level; | ||
142 | + logConfig.mode = mode; | ||
143 | + logConfig.logdir = logDir; | ||
144 | + logConfig.nameprefix = nameprefix; | ||
145 | + logConfig.compressmode = ZLIB_MODE; | ||
146 | + logConfig.pubkey = ""; | ||
147 | + logConfig.cachedir = cacheDir; | ||
148 | + logConfig.cachedays = cacheDays; | ||
149 | + return newXlogInstance(logConfig); | ||
150 | + } | ||
151 | + | ||
152 | + @Override | ||
153 | + public native long getXlogInstance(String nameprefix); | ||
154 | + | ||
155 | + @Override | ||
156 | + public native void releaseXlogInstance(String nameprefix); | ||
157 | + | ||
158 | + public native long newXlogInstance(XLogConfig logConfig); | ||
159 | + | ||
160 | + @Override | ||
161 | + public native void setConsoleLogOpen(long logInstancePtr, boolean isOpen); //set whether the console prints log | ||
162 | + | ||
163 | + public native void appenderOpen(XLogConfig logConfig); | ||
164 | + | ||
165 | + @Override | ||
166 | + public native void appenderClose(); | ||
167 | + | ||
168 | + @Override | ||
169 | + public native void appenderFlush(long logInstancePtr, boolean isSync); | ||
170 | + | ||
171 | + @Override | ||
172 | + public native void setMaxFileSize(long logInstancePtr, long aliveSeconds); | ||
173 | + | ||
174 | + @Override | ||
175 | + public native void setMaxAliveTime(long logInstancePtr, long aliveSeconds); | ||
176 | + | ||
177 | +} |
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
1 | +package com.tencent.xlog.flutter | ||
2 | + | ||
3 | + | ||
4 | +import com.tencent.mars.xlog.Log | ||
5 | +import com.tencent.mars.xlog.Xlog | ||
6 | +import com.tencent.mars.xlog.Xlog.XLogConfig | ||
7 | +import io.flutter.embedding.engine.plugins.FlutterPlugin | ||
8 | +import io.flutter.plugin.common.MethodCall | ||
9 | +import io.flutter.plugin.common.MethodChannel | ||
10 | +import io.flutter.plugin.common.MethodChannel.MethodCallHandler | ||
11 | +import io.flutter.plugin.common.MethodChannel.Result | ||
12 | + | ||
13 | +/** FlutterXLogPlugin */ | ||
14 | +class FlutterXLogPlugin : FlutterPlugin, MethodCallHandler { | ||
15 | + private lateinit var channel: MethodChannel | ||
16 | + | ||
17 | + init { | ||
18 | + System.loadLibrary("c++_shared") | ||
19 | + System.loadLibrary("marsxlog") | ||
20 | + } | ||
21 | + | ||
22 | + private val xlog = Xlog() | ||
23 | + | ||
24 | + override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { | ||
25 | + channel = MethodChannel(flutterPluginBinding.binaryMessenger, "flutter_xlog") | ||
26 | + channel.setMethodCallHandler(this) | ||
27 | + } | ||
28 | + | ||
29 | + override fun onMethodCall(call: MethodCall, result: Result) { | ||
30 | + if (call.method == "open") { | ||
31 | + val level = call.argument<Int>("level") ?: Log.LEVEL_INFO | ||
32 | + val cacheDir = call.argument<String>("cacheDir") | ||
33 | + val logDir = call.argument<String>("logDir") | ||
34 | + val namePrefix = call.argument<String>("namePrefix") | ||
35 | + val cacheDays = call.argument<Int>("cacheDays") ?: 0 | ||
36 | + val pubKey = call.argument<String>("pubKey"); | ||
37 | + val consoleLogOpen = call.argument<Boolean>("consoleLogOpen") ?: false | ||
38 | + Log.setLogImp(xlog) | ||
39 | + Log.setLevel(level, false) | ||
40 | + Log.setConsoleLogOpen(consoleLogOpen) | ||
41 | + xlog.appenderOpen(XLogConfig().also { | ||
42 | + it.level = level | ||
43 | + it.cachedir = cacheDir | ||
44 | + it.logdir = logDir | ||
45 | + it.nameprefix = namePrefix | ||
46 | + it.cachedays = cacheDays | ||
47 | + it.pubkey = pubKey | ||
48 | + }) | ||
49 | + result.success(null) | ||
50 | + } else if (call.method == "flush") { | ||
51 | + xlog.appenderFlush(0, true) | ||
52 | + result.success(null) | ||
53 | + } else if (call.method == "close") { | ||
54 | + xlog.appenderClose() | ||
55 | + result.success(null) | ||
56 | + } else { | ||
57 | + result.notImplemented() | ||
58 | + } | ||
59 | + } | ||
60 | + | ||
61 | + override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { | ||
62 | + channel.setMethodCallHandler(null) | ||
63 | + } | ||
64 | +} |
example/.gitignore
0 → 100644
1 | +# Miscellaneous | ||
2 | +*.class | ||
3 | +*.log | ||
4 | +*.pyc | ||
5 | +*.swp | ||
6 | +.DS_Store | ||
7 | +.atom/ | ||
8 | +.buildlog/ | ||
9 | +.history | ||
10 | +.svn/ | ||
11 | +migrate_working_dir/ | ||
12 | + | ||
13 | +# IntelliJ related | ||
14 | +*.iml | ||
15 | +*.ipr | ||
16 | +*.iws | ||
17 | +.idea/ | ||
18 | + | ||
19 | +# The .vscode folder contains launch configuration and tasks you configure in | ||
20 | +# VS Code which you may wish to be included in version control, so this line | ||
21 | +# is commented out by default. | ||
22 | +#.vscode/ | ||
23 | + | ||
24 | +# Flutter/Dart/Pub related | ||
25 | +**/doc/api/ | ||
26 | +**/ios/Flutter/.last_build_id | ||
27 | +.dart_tool/ | ||
28 | +.flutter-plugins | ||
29 | +.flutter-plugins-dependencies | ||
30 | +.pub-cache/ | ||
31 | +.pub/ | ||
32 | +/build/ | ||
33 | + | ||
34 | +# Symbolication related | ||
35 | +app.*.symbols | ||
36 | + | ||
37 | +# Obfuscation related | ||
38 | +app.*.map.json | ||
39 | + | ||
40 | +# Android Studio will place build artifacts here | ||
41 | +/android/app/debug | ||
42 | +/android/app/profile | ||
43 | +/android/app/release |
example/README.md
0 → 100644
1 | +# flutter_xlog_example | ||
2 | + | ||
3 | +Demonstrates how to use the flutter_xlog plugin. | ||
4 | + | ||
5 | +## Getting Started | ||
6 | + | ||
7 | +This project is a starting point for a Flutter application. | ||
8 | + | ||
9 | +A few resources to get you started if this is your first Flutter project: | ||
10 | + | ||
11 | +- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) | ||
12 | +- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) | ||
13 | + | ||
14 | +For help getting started with Flutter development, view the | ||
15 | +[online documentation](https://docs.flutter.dev/), which offers tutorials, | ||
16 | +samples, guidance on mobile development, and a full API reference. |
example/analysis_options.yaml
0 → 100644
1 | +# This file configures the analyzer, which statically analyzes Dart code to | ||
2 | +# check for errors, warnings, and lints. | ||
3 | +# | ||
4 | +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled | ||
5 | +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be | ||
6 | +# invoked from the command line by running `flutter analyze`. | ||
7 | + | ||
8 | +# The following line activates a set of recommended lints for Flutter apps, | ||
9 | +# packages, and plugins designed to encourage good coding practices. | ||
10 | +include: package:flutter_lints/flutter.yaml | ||
11 | + | ||
12 | +linter: | ||
13 | + # The lint rules applied to this project can be customized in the | ||
14 | + # section below to disable rules from the `package:flutter_lints/flutter.yaml` | ||
15 | + # included above or to enable additional rules. A list of all available lints | ||
16 | + # and their documentation is published at https://dart.dev/lints. | ||
17 | + # | ||
18 | + # Instead of disabling a lint rule for the entire project in the | ||
19 | + # section below, it can also be suppressed for a single line of code | ||
20 | + # or a specific dart file by using the `// ignore: name_of_lint` and | ||
21 | + # `// ignore_for_file: name_of_lint` syntax on the line or in the file | ||
22 | + # producing the lint. | ||
23 | + rules: | ||
24 | + # avoid_print: false # Uncomment to disable the `avoid_print` rule | ||
25 | + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule | ||
26 | + | ||
27 | +# Additional information about this file can be found at | ||
28 | +# https://dart.dev/guides/language/analysis-options |
example/android/.gitignore
0 → 100644
1 | +gradle-wrapper.jar | ||
2 | +/.gradle | ||
3 | +/captures/ | ||
4 | +/gradlew | ||
5 | +/gradlew.bat | ||
6 | +/local.properties | ||
7 | +GeneratedPluginRegistrant.java | ||
8 | + | ||
9 | +# Remember to never publicly share your keystore. | ||
10 | +# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app | ||
11 | +key.properties | ||
12 | +**/*.keystore | ||
13 | +**/*.jks |
example/android/app/build.gradle
0 → 100644
1 | +plugins { | ||
2 | + id "com.android.application" | ||
3 | + id "kotlin-android" | ||
4 | + id "dev.flutter.flutter-gradle-plugin" | ||
5 | +} | ||
6 | + | ||
7 | +def localProperties = new Properties() | ||
8 | +def localPropertiesFile = rootProject.file('local.properties') | ||
9 | +if (localPropertiesFile.exists()) { | ||
10 | + localPropertiesFile.withReader('UTF-8') { reader -> | ||
11 | + localProperties.load(reader) | ||
12 | + } | ||
13 | +} | ||
14 | + | ||
15 | +def flutterVersionCode = localProperties.getProperty('flutter.versionCode') | ||
16 | +if (flutterVersionCode == null) { | ||
17 | + flutterVersionCode = '1' | ||
18 | +} | ||
19 | + | ||
20 | +def flutterVersionName = localProperties.getProperty('flutter.versionName') | ||
21 | +if (flutterVersionName == null) { | ||
22 | + flutterVersionName = '1.0' | ||
23 | +} | ||
24 | + | ||
25 | +android { | ||
26 | + namespace "com.tencent.xlog.flutter_xlog_example" | ||
27 | + compileSdkVersion flutter.compileSdkVersion | ||
28 | + ndkVersion flutter.ndkVersion | ||
29 | + | ||
30 | + compileOptions { | ||
31 | + sourceCompatibility JavaVersion.VERSION_1_8 | ||
32 | + targetCompatibility JavaVersion.VERSION_1_8 | ||
33 | + } | ||
34 | + | ||
35 | + kotlinOptions { | ||
36 | + jvmTarget = '1.8' | ||
37 | + } | ||
38 | + | ||
39 | + sourceSets { | ||
40 | + main.java.srcDirs += 'src/main/kotlin' | ||
41 | + main.jniLibs.srcDirs += 'src/main/jniLibs' | ||
42 | + } | ||
43 | + | ||
44 | + defaultConfig { | ||
45 | + // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). | ||
46 | + applicationId "com.tencent.xlog.flutter_xlog_example" | ||
47 | + // You can update the following values to match your application needs. | ||
48 | + // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. | ||
49 | + minSdkVersion flutter.minSdkVersion | ||
50 | + targetSdkVersion flutter.targetSdkVersion | ||
51 | + versionCode flutterVersionCode.toInteger() | ||
52 | + versionName flutterVersionName | ||
53 | + } | ||
54 | + | ||
55 | + packagingOptions { | ||
56 | + pickFirst 'jniLibs/armeabi-v7a/libc++_shared.so' | ||
57 | + pickFirst 'jniLibs/arm64-v8a/libc++_shared.so' | ||
58 | + } | ||
59 | + | ||
60 | + buildTypes { | ||
61 | + release { | ||
62 | + // TODO: Add your own signing config for the release build. | ||
63 | + // Signing with the debug keys for now, so `flutter run --release` works. | ||
64 | + signingConfig signingConfigs.debug | ||
65 | + } | ||
66 | + } | ||
67 | +} | ||
68 | + | ||
69 | +flutter { | ||
70 | + source '../..' | ||
71 | +} | ||
72 | + | ||
73 | +dependencies {} |
example/android/app/proguard-rules.pro
0 → 100644
1 | +<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
2 | + <!-- The INTERNET permission is required for development. Specifically, | ||
3 | + the Flutter tool needs it to communicate with the running application | ||
4 | + to allow setting breakpoints, to provide hot reload, etc. | ||
5 | + --> | ||
6 | + <uses-permission android:name="android.permission.INTERNET"/> | ||
7 | +</manifest> |
1 | +<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
2 | + <application | ||
3 | + android:label="flutter_xlog_example" | ||
4 | + android:name="${applicationName}" | ||
5 | + android:icon="@mipmap/ic_launcher"> | ||
6 | + <activity | ||
7 | + android:name=".MainActivity" | ||
8 | + android:exported="true" | ||
9 | + android:launchMode="singleTop" | ||
10 | + android:theme="@style/LaunchTheme" | ||
11 | + android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" | ||
12 | + android:hardwareAccelerated="true" | ||
13 | + android:windowSoftInputMode="adjustResize"> | ||
14 | + <!-- Specifies an Android theme to apply to this Activity as soon as | ||
15 | + the Android process has started. This theme is visible to the user | ||
16 | + while the Flutter UI initializes. After that, this theme continues | ||
17 | + to determine the Window background behind the Flutter UI. --> | ||
18 | + <meta-data | ||
19 | + android:name="io.flutter.embedding.android.NormalTheme" | ||
20 | + android:resource="@style/NormalTheme" | ||
21 | + /> | ||
22 | + <intent-filter> | ||
23 | + <action android:name="android.intent.action.MAIN"/> | ||
24 | + <category android:name="android.intent.category.LAUNCHER"/> | ||
25 | + </intent-filter> | ||
26 | + </activity> | ||
27 | + <!-- Don't delete the meta-data below. | ||
28 | + This is used by the Flutter tool to generate GeneratedPluginRegistrant.java --> | ||
29 | + <meta-data | ||
30 | + android:name="flutterEmbedding" | ||
31 | + android:value="2" /> | ||
32 | + </application> | ||
33 | +</manifest> |
No preview for this file type
No preview for this file type
1 | +<?xml version="1.0" encoding="utf-8"?> | ||
2 | +<!-- Modify this file to customize your launch splash screen --> | ||
3 | +<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | ||
4 | + <item android:drawable="?android:colorBackground" /> | ||
5 | + | ||
6 | + <!-- You can insert your own image assets here --> | ||
7 | + <!-- <item> | ||
8 | + <bitmap | ||
9 | + android:gravity="center" | ||
10 | + android:src="@mipmap/launch_image" /> | ||
11 | + </item> --> | ||
12 | +</layer-list> |
1 | +<?xml version="1.0" encoding="utf-8"?> | ||
2 | +<!-- Modify this file to customize your launch splash screen --> | ||
3 | +<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | ||
4 | + <item android:drawable="@android:color/white" /> | ||
5 | + | ||
6 | + <!-- You can insert your own image assets here --> | ||
7 | + <!-- <item> | ||
8 | + <bitmap | ||
9 | + android:gravity="center" | ||
10 | + android:src="@mipmap/launch_image" /> | ||
11 | + </item> --> | ||
12 | +</layer-list> |

544 Bytes

442 Bytes

721 Bytes

1.01 KB

1.41 KB
1 | +<?xml version="1.0" encoding="utf-8"?> | ||
2 | +<resources> | ||
3 | + <!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on --> | ||
4 | + <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar"> | ||
5 | + <!-- Show a splash screen on the activity. Automatically removed when | ||
6 | + the Flutter engine draws its first frame --> | ||
7 | + <item name="android:windowBackground">@drawable/launch_background</item> | ||
8 | + </style> | ||
9 | + <!-- Theme applied to the Android Window as soon as the process has started. | ||
10 | + This theme determines the color of the Android Window while your | ||
11 | + Flutter UI initializes, as well as behind your Flutter UI while its | ||
12 | + running. | ||
13 | + | ||
14 | + This Theme is only used starting with V2 of Flutter's Android embedding. --> | ||
15 | + <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar"> | ||
16 | + <item name="android:windowBackground">?android:colorBackground</item> | ||
17 | + </style> | ||
18 | +</resources> |
1 | +<?xml version="1.0" encoding="utf-8"?> | ||
2 | +<resources> | ||
3 | + <!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off --> | ||
4 | + <style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar"> | ||
5 | + <!-- Show a splash screen on the activity. Automatically removed when | ||
6 | + the Flutter engine draws its first frame --> | ||
7 | + <item name="android:windowBackground">@drawable/launch_background</item> | ||
8 | + </style> | ||
9 | + <!-- Theme applied to the Android Window as soon as the process has started. | ||
10 | + This theme determines the color of the Android Window while your | ||
11 | + Flutter UI initializes, as well as behind your Flutter UI while its | ||
12 | + running. | ||
13 | + | ||
14 | + This Theme is only used starting with V2 of Flutter's Android embedding. --> | ||
15 | + <style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar"> | ||
16 | + <item name="android:windowBackground">?android:colorBackground</item> | ||
17 | + </style> | ||
18 | +</resources> |
1 | +<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
2 | + <!-- The INTERNET permission is required for development. Specifically, | ||
3 | + the Flutter tool needs it to communicate with the running application | ||
4 | + to allow setting breakpoints, to provide hot reload, etc. | ||
5 | + --> | ||
6 | + <uses-permission android:name="android.permission.INTERNET"/> | ||
7 | +</manifest> |
example/android/build.gradle
0 → 100644
1 | +buildscript { | ||
2 | + ext.kotlin_version = '1.7.10' | ||
3 | + repositories { | ||
4 | + google() | ||
5 | + mavenCentral() | ||
6 | + } | ||
7 | + | ||
8 | + dependencies { | ||
9 | + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | ||
10 | + } | ||
11 | +} | ||
12 | + | ||
13 | +allprojects { | ||
14 | + repositories { | ||
15 | + google() | ||
16 | + mavenCentral() | ||
17 | + } | ||
18 | +} | ||
19 | + | ||
20 | +rootProject.buildDir = '../build' | ||
21 | +subprojects { | ||
22 | + project.buildDir = "${rootProject.buildDir}/${project.name}" | ||
23 | +} | ||
24 | +subprojects { | ||
25 | + project.evaluationDependsOn(':app') | ||
26 | +} | ||
27 | + | ||
28 | +tasks.register("clean", Delete) { | ||
29 | + delete rootProject.buildDir | ||
30 | +} |
example/android/gradle.properties
0 → 100644
example/android/settings.gradle
0 → 100644
1 | +pluginManagement { | ||
2 | + def flutterSdkPath = { | ||
3 | + def properties = new Properties() | ||
4 | + file("local.properties").withInputStream { properties.load(it) } | ||
5 | + def flutterSdkPath = properties.getProperty("flutter.sdk") | ||
6 | + assert flutterSdkPath != null, "flutter.sdk not set in local.properties" | ||
7 | + return flutterSdkPath | ||
8 | + } | ||
9 | + settings.ext.flutterSdkPath = flutterSdkPath() | ||
10 | + | ||
11 | + includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle") | ||
12 | + | ||
13 | + repositories { | ||
14 | + google() | ||
15 | + mavenCentral() | ||
16 | + gradlePluginPortal() | ||
17 | + } | ||
18 | + | ||
19 | + plugins { | ||
20 | + id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false | ||
21 | + } | ||
22 | +} | ||
23 | + | ||
24 | +plugins { | ||
25 | + id "dev.flutter.flutter-plugin-loader" version "1.0.0" | ||
26 | + id "com.android.application" version "7.3.0" apply false | ||
27 | +} | ||
28 | + | ||
29 | +include ":app" |
example/ios/.gitignore
0 → 100644
1 | +**/dgph | ||
2 | +*.mode1v3 | ||
3 | +*.mode2v3 | ||
4 | +*.moved-aside | ||
5 | +*.pbxuser | ||
6 | +*.perspectivev3 | ||
7 | +**/*sync/ | ||
8 | +.sconsign.dblite | ||
9 | +.tags* | ||
10 | +**/.vagrant/ | ||
11 | +**/DerivedData/ | ||
12 | +Icon? | ||
13 | +**/Pods/ | ||
14 | +**/.symlinks/ | ||
15 | +profile | ||
16 | +xcuserdata | ||
17 | +**/.generated/ | ||
18 | +Flutter/App.framework | ||
19 | +Flutter/Flutter.framework | ||
20 | +Flutter/Flutter.podspec | ||
21 | +Flutter/Generated.xcconfig | ||
22 | +Flutter/ephemeral/ | ||
23 | +Flutter/app.flx | ||
24 | +Flutter/app.zip | ||
25 | +Flutter/flutter_assets/ | ||
26 | +Flutter/flutter_export_environment.sh | ||
27 | +ServiceDefinitions.json | ||
28 | +Runner/GeneratedPluginRegistrant.* | ||
29 | + | ||
30 | +# Exceptions to above rules. | ||
31 | +!default.mode1v3 | ||
32 | +!default.mode2v3 | ||
33 | +!default.pbxuser | ||
34 | +!default.perspectivev3 |
example/ios/Flutter/AppFrameworkInfo.plist
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
3 | +<plist version="1.0"> | ||
4 | +<dict> | ||
5 | + <key>CFBundleDevelopmentRegion</key> | ||
6 | + <string>en</string> | ||
7 | + <key>CFBundleExecutable</key> | ||
8 | + <string>App</string> | ||
9 | + <key>CFBundleIdentifier</key> | ||
10 | + <string>io.flutter.flutter.app</string> | ||
11 | + <key>CFBundleInfoDictionaryVersion</key> | ||
12 | + <string>6.0</string> | ||
13 | + <key>CFBundleName</key> | ||
14 | + <string>App</string> | ||
15 | + <key>CFBundlePackageType</key> | ||
16 | + <string>FMWK</string> | ||
17 | + <key>CFBundleShortVersionString</key> | ||
18 | + <string>1.0</string> | ||
19 | + <key>CFBundleSignature</key> | ||
20 | + <string>????</string> | ||
21 | + <key>CFBundleVersion</key> | ||
22 | + <string>1.0</string> | ||
23 | + <key>MinimumOSVersion</key> | ||
24 | + <string>11.0</string> | ||
25 | +</dict> | ||
26 | +</plist> |
example/ios/Flutter/Debug.xcconfig
0 → 100644
example/ios/Flutter/Release.xcconfig
0 → 100644
example/ios/Podfile
0 → 100644
1 | +# Uncomment this line to define a global platform for your project | ||
2 | +# platform :ios, '11.0' | ||
3 | + | ||
4 | +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. | ||
5 | +ENV['COCOAPODS_DISABLE_STATS'] = 'true' | ||
6 | + | ||
7 | +project 'Runner', { | ||
8 | + 'Debug' => :debug, | ||
9 | + 'Profile' => :release, | ||
10 | + 'Release' => :release, | ||
11 | +} | ||
12 | + | ||
13 | +def flutter_root | ||
14 | + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) | ||
15 | + unless File.exist?(generated_xcode_build_settings_path) | ||
16 | + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" | ||
17 | + end | ||
18 | + | ||
19 | + File.foreach(generated_xcode_build_settings_path) do |line| | ||
20 | + matches = line.match(/FLUTTER_ROOT\=(.*)/) | ||
21 | + return matches[1].strip if matches | ||
22 | + end | ||
23 | + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" | ||
24 | +end | ||
25 | + | ||
26 | +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) | ||
27 | + | ||
28 | +flutter_ios_podfile_setup | ||
29 | + | ||
30 | +target 'Runner' do | ||
31 | + use_frameworks! | ||
32 | + use_modular_headers! | ||
33 | + | ||
34 | + flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) | ||
35 | + target 'RunnerTests' do | ||
36 | + inherit! :search_paths | ||
37 | + end | ||
38 | +end | ||
39 | + | ||
40 | +post_install do |installer| | ||
41 | + installer.pods_project.targets.each do |target| | ||
42 | + flutter_additional_ios_build_settings(target) | ||
43 | + end | ||
44 | +end |
example/ios/Podfile.lock
0 → 100644
1 | +PODS: | ||
2 | + - Flutter (1.0.0) | ||
3 | + - flutter_xlog (0.0.1): | ||
4 | + - Flutter | ||
5 | + - integration_test (0.0.1): | ||
6 | + - Flutter | ||
7 | + - path_provider_foundation (0.0.1): | ||
8 | + - Flutter | ||
9 | + - FlutterMacOS | ||
10 | + | ||
11 | +DEPENDENCIES: | ||
12 | + - Flutter (from `Flutter`) | ||
13 | + - flutter_xlog (from `.symlinks/plugins/flutter_xlog/ios`) | ||
14 | + - integration_test (from `.symlinks/plugins/integration_test/ios`) | ||
15 | + - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`) | ||
16 | + | ||
17 | +EXTERNAL SOURCES: | ||
18 | + Flutter: | ||
19 | + :path: Flutter | ||
20 | + flutter_xlog: | ||
21 | + :path: ".symlinks/plugins/flutter_xlog/ios" | ||
22 | + integration_test: | ||
23 | + :path: ".symlinks/plugins/integration_test/ios" | ||
24 | + path_provider_foundation: | ||
25 | + :path: ".symlinks/plugins/path_provider_foundation/darwin" | ||
26 | + | ||
27 | +SPEC CHECKSUMS: | ||
28 | + Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 | ||
29 | + flutter_xlog: b23b41d97f3e6b5fce8cdfb26ba915fbd8d45e97 | ||
30 | + integration_test: 13825b8a9334a850581300559b8839134b124670 | ||
31 | + path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943 | ||
32 | + | ||
33 | +PODFILE CHECKSUM: 70d9d25280d0dd177a5f637cdb0f0b0b12c6a189 | ||
34 | + | ||
35 | +COCOAPODS: 1.14.3 |
example/ios/Runner/AppDelegate.swift
0 → 100644
1 | +import UIKit | ||
2 | +import Flutter | ||
3 | + | ||
4 | +@UIApplicationMain | ||
5 | +@objc class AppDelegate: FlutterAppDelegate { | ||
6 | + override func application( | ||
7 | + _ application: UIApplication, | ||
8 | + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? | ||
9 | + ) -> Bool { | ||
10 | + GeneratedPluginRegistrant.register(with: self) | ||
11 | + return super.application(application, didFinishLaunchingWithOptions: launchOptions) | ||
12 | + } | ||
13 | +} |
1 | +{ | ||
2 | + "images" : [ | ||
3 | + { | ||
4 | + "size" : "20x20", | ||
5 | + "idiom" : "iphone", | ||
6 | + "filename" : "Icon-App-20x20@2x.png", | ||
7 | + "scale" : "2x" | ||
8 | + }, | ||
9 | + { | ||
10 | + "size" : "20x20", | ||
11 | + "idiom" : "iphone", | ||
12 | + "filename" : "Icon-App-20x20@3x.png", | ||
13 | + "scale" : "3x" | ||
14 | + }, | ||
15 | + { | ||
16 | + "size" : "29x29", | ||
17 | + "idiom" : "iphone", | ||
18 | + "filename" : "Icon-App-29x29@1x.png", | ||
19 | + "scale" : "1x" | ||
20 | + }, | ||
21 | + { | ||
22 | + "size" : "29x29", | ||
23 | + "idiom" : "iphone", | ||
24 | + "filename" : "Icon-App-29x29@2x.png", | ||
25 | + "scale" : "2x" | ||
26 | + }, | ||
27 | + { | ||
28 | + "size" : "29x29", | ||
29 | + "idiom" : "iphone", | ||
30 | + "filename" : "Icon-App-29x29@3x.png", | ||
31 | + "scale" : "3x" | ||
32 | + }, | ||
33 | + { | ||
34 | + "size" : "40x40", | ||
35 | + "idiom" : "iphone", | ||
36 | + "filename" : "Icon-App-40x40@2x.png", | ||
37 | + "scale" : "2x" | ||
38 | + }, | ||
39 | + { | ||
40 | + "size" : "40x40", | ||
41 | + "idiom" : "iphone", | ||
42 | + "filename" : "Icon-App-40x40@3x.png", | ||
43 | + "scale" : "3x" | ||
44 | + }, | ||
45 | + { | ||
46 | + "size" : "60x60", | ||
47 | + "idiom" : "iphone", | ||
48 | + "filename" : "Icon-App-60x60@2x.png", | ||
49 | + "scale" : "2x" | ||
50 | + }, | ||
51 | + { | ||
52 | + "size" : "60x60", | ||
53 | + "idiom" : "iphone", | ||
54 | + "filename" : "Icon-App-60x60@3x.png", | ||
55 | + "scale" : "3x" | ||
56 | + }, | ||
57 | + { | ||
58 | + "size" : "20x20", | ||
59 | + "idiom" : "ipad", | ||
60 | + "filename" : "Icon-App-20x20@1x.png", | ||
61 | + "scale" : "1x" | ||
62 | + }, | ||
63 | + { | ||
64 | + "size" : "20x20", | ||
65 | + "idiom" : "ipad", | ||
66 | + "filename" : "Icon-App-20x20@2x.png", | ||
67 | + "scale" : "2x" | ||
68 | + }, | ||
69 | + { | ||
70 | + "size" : "29x29", | ||
71 | + "idiom" : "ipad", | ||
72 | + "filename" : "Icon-App-29x29@1x.png", | ||
73 | + "scale" : "1x" | ||
74 | + }, | ||
75 | + { | ||
76 | + "size" : "29x29", | ||
77 | + "idiom" : "ipad", | ||
78 | + "filename" : "Icon-App-29x29@2x.png", | ||
79 | + "scale" : "2x" | ||
80 | + }, | ||
81 | + { | ||
82 | + "size" : "40x40", | ||
83 | + "idiom" : "ipad", | ||
84 | + "filename" : "Icon-App-40x40@1x.png", | ||
85 | + "scale" : "1x" | ||
86 | + }, | ||
87 | + { | ||
88 | + "size" : "40x40", | ||
89 | + "idiom" : "ipad", | ||
90 | + "filename" : "Icon-App-40x40@2x.png", | ||
91 | + "scale" : "2x" | ||
92 | + }, | ||
93 | + { | ||
94 | + "size" : "76x76", | ||
95 | + "idiom" : "ipad", | ||
96 | + "filename" : "Icon-App-76x76@1x.png", | ||
97 | + "scale" : "1x" | ||
98 | + }, | ||
99 | + { | ||
100 | + "size" : "76x76", | ||
101 | + "idiom" : "ipad", | ||
102 | + "filename" : "Icon-App-76x76@2x.png", | ||
103 | + "scale" : "2x" | ||
104 | + }, | ||
105 | + { | ||
106 | + "size" : "83.5x83.5", | ||
107 | + "idiom" : "ipad", | ||
108 | + "filename" : "Icon-App-83.5x83.5@2x.png", | ||
109 | + "scale" : "2x" | ||
110 | + }, | ||
111 | + { | ||
112 | + "size" : "1024x1024", | ||
113 | + "idiom" : "ios-marketing", | ||
114 | + "filename" : "Icon-App-1024x1024@1x.png", | ||
115 | + "scale" : "1x" | ||
116 | + } | ||
117 | + ], | ||
118 | + "info" : { | ||
119 | + "version" : 1, | ||
120 | + "author" : "xcode" | ||
121 | + } | ||
122 | +} |

295 Bytes

406 Bytes

450 Bytes

282 Bytes

462 Bytes

704 Bytes

406 Bytes

586 Bytes

862 Bytes

862 Bytes

1.63 KB

762 Bytes
1 | +{ | ||
2 | + "images" : [ | ||
3 | + { | ||
4 | + "idiom" : "universal", | ||
5 | + "filename" : "LaunchImage.png", | ||
6 | + "scale" : "1x" | ||
7 | + }, | ||
8 | + { | ||
9 | + "idiom" : "universal", | ||
10 | + "filename" : "LaunchImage@2x.png", | ||
11 | + "scale" : "2x" | ||
12 | + }, | ||
13 | + { | ||
14 | + "idiom" : "universal", | ||
15 | + "filename" : "LaunchImage@3x.png", | ||
16 | + "scale" : "3x" | ||
17 | + } | ||
18 | + ], | ||
19 | + "info" : { | ||
20 | + "version" : 1, | ||
21 | + "author" : "xcode" | ||
22 | + } | ||
23 | +} |

68 Bytes

68 Bytes

68 Bytes
1 | +# Launch Screen Assets | ||
2 | + | ||
3 | +You can customize the launch screen with your own desired assets by replacing the image files in this directory. | ||
4 | + | ||
5 | +You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images. |
1 | +<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
2 | +<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16G29" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" colorMatched="YES" initialViewController="01J-lp-oVM"> | ||
3 | + <dependencies> | ||
4 | + <deployment identifier="iOS"/> | ||
5 | + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/> | ||
6 | + </dependencies> | ||
7 | + <scenes> | ||
8 | + <!--View Controller--> | ||
9 | + <scene sceneID="EHf-IW-A2E"> | ||
10 | + <objects> | ||
11 | + <viewController id="01J-lp-oVM" sceneMemberID="viewController"> | ||
12 | + <layoutGuides> | ||
13 | + <viewControllerLayoutGuide type="top" id="Ydg-fD-yQy"/> | ||
14 | + <viewControllerLayoutGuide type="bottom" id="xbc-2k-c8Z"/> | ||
15 | + </layoutGuides> | ||
16 | + <view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3"> | ||
17 | + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
18 | + <subviews> | ||
19 | + <imageView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" image="LaunchImage" translatesAutoresizingMaskIntoConstraints="NO" id="YRO-k0-Ey4"> | ||
20 | + </imageView> | ||
21 | + </subviews> | ||
22 | + <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | ||
23 | + <constraints> | ||
24 | + <constraint firstItem="YRO-k0-Ey4" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="1a2-6s-vTC"/> | ||
25 | + <constraint firstItem="YRO-k0-Ey4" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="4X2-HB-R7a"/> | ||
26 | + </constraints> | ||
27 | + </view> | ||
28 | + </viewController> | ||
29 | + <placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/> | ||
30 | + </objects> | ||
31 | + <point key="canvasLocation" x="53" y="375"/> | ||
32 | + </scene> | ||
33 | + </scenes> | ||
34 | + <resources> | ||
35 | + <image name="LaunchImage" width="168" height="185"/> | ||
36 | + </resources> | ||
37 | +</document> |
1 | +<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
2 | +<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r"> | ||
3 | + <dependencies> | ||
4 | + <deployment identifier="iOS"/> | ||
5 | + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/> | ||
6 | + </dependencies> | ||
7 | + <scenes> | ||
8 | + <!--Flutter View Controller--> | ||
9 | + <scene sceneID="tne-QT-ifu"> | ||
10 | + <objects> | ||
11 | + <viewController id="BYZ-38-t0r" customClass="FlutterViewController" sceneMemberID="viewController"> | ||
12 | + <layoutGuides> | ||
13 | + <viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/> | ||
14 | + <viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/> | ||
15 | + </layoutGuides> | ||
16 | + <view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC"> | ||
17 | + <rect key="frame" x="0.0" y="0.0" width="600" height="600"/> | ||
18 | + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
19 | + <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> | ||
20 | + </view> | ||
21 | + </viewController> | ||
22 | + <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/> | ||
23 | + </objects> | ||
24 | + </scene> | ||
25 | + </scenes> | ||
26 | +</document> |
example/ios/Runner/Info.plist
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
3 | +<plist version="1.0"> | ||
4 | +<dict> | ||
5 | + <key>CFBundleDevelopmentRegion</key> | ||
6 | + <string>$(DEVELOPMENT_LANGUAGE)</string> | ||
7 | + <key>CFBundleDisplayName</key> | ||
8 | + <string>Flutter Xlog</string> | ||
9 | + <key>CFBundleExecutable</key> | ||
10 | + <string>$(EXECUTABLE_NAME)</string> | ||
11 | + <key>CFBundleIdentifier</key> | ||
12 | + <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
13 | + <key>CFBundleInfoDictionaryVersion</key> | ||
14 | + <string>6.0</string> | ||
15 | + <key>CFBundleName</key> | ||
16 | + <string>flutter_xlog_example</string> | ||
17 | + <key>CFBundlePackageType</key> | ||
18 | + <string>APPL</string> | ||
19 | + <key>CFBundleShortVersionString</key> | ||
20 | + <string>$(FLUTTER_BUILD_NAME)</string> | ||
21 | + <key>CFBundleSignature</key> | ||
22 | + <string>????</string> | ||
23 | + <key>CFBundleVersion</key> | ||
24 | + <string>$(FLUTTER_BUILD_NUMBER)</string> | ||
25 | + <key>LSRequiresIPhoneOS</key> | ||
26 | + <true/> | ||
27 | + <key>UILaunchStoryboardName</key> | ||
28 | + <string>LaunchScreen</string> | ||
29 | + <key>UIMainStoryboardFile</key> | ||
30 | + <string>Main</string> | ||
31 | + <key>UISupportedInterfaceOrientations</key> | ||
32 | + <array> | ||
33 | + <string>UIInterfaceOrientationPortrait</string> | ||
34 | + <string>UIInterfaceOrientationLandscapeLeft</string> | ||
35 | + <string>UIInterfaceOrientationLandscapeRight</string> | ||
36 | + </array> | ||
37 | + <key>UISupportedInterfaceOrientations~ipad</key> | ||
38 | + <array> | ||
39 | + <string>UIInterfaceOrientationPortrait</string> | ||
40 | + <string>UIInterfaceOrientationPortraitUpsideDown</string> | ||
41 | + <string>UIInterfaceOrientationLandscapeLeft</string> | ||
42 | + <string>UIInterfaceOrientationLandscapeRight</string> | ||
43 | + </array> | ||
44 | + <key>CADisableMinimumFrameDurationOnPhone</key> | ||
45 | + <true/> | ||
46 | + <key>UIApplicationSupportsIndirectInputEvents</key> | ||
47 | + <true/> | ||
48 | +</dict> | ||
49 | +</plist> |
example/ios/Runner/Runner-Bridging-Header.h
0 → 100644
1 | +#import "GeneratedPluginRegistrant.h" |
example/ios/RunnerTests/RunnerTests.swift
0 → 100644
1 | +import Flutter | ||
2 | +import UIKit | ||
3 | +import XCTest | ||
4 | + | ||
5 | +@testable import flutter_xlog | ||
6 | + | ||
7 | +// This demonstrates a simple unit test of the Swift portion of this plugin's implementation. | ||
8 | +// | ||
9 | +// See https://developer.apple.com/documentation/xctest for more information about using XCTest. | ||
10 | + | ||
11 | +class RunnerTests: XCTestCase { | ||
12 | + | ||
13 | + func testGetPlatformVersion() { | ||
14 | + let plugin = FlutterXlogPlugin() | ||
15 | + | ||
16 | + let call = FlutterMethodCall(methodName: "getPlatformVersion", arguments: []) | ||
17 | + | ||
18 | + let resultExpectation = expectation(description: "result block must be called.") | ||
19 | + plugin.handle(call) { result in | ||
20 | + XCTAssertEqual(result as! String, "iOS " + UIDevice.current.systemVersion) | ||
21 | + resultExpectation.fulfill() | ||
22 | + } | ||
23 | + waitForExpectations(timeout: 1) | ||
24 | + } | ||
25 | + | ||
26 | +} |
example/lib/main.dart
0 → 100644
1 | +import 'dart:io'; | ||
2 | + | ||
3 | +import 'package:flutter/foundation.dart'; | ||
4 | +import 'package:flutter/material.dart'; | ||
5 | +import 'package:flutter_xlog/flutter_xlog.dart'; | ||
6 | +import 'package:path_provider/path_provider.dart'; | ||
7 | + | ||
8 | +var cacheDir = ''; | ||
9 | +var logDir = ''; | ||
10 | + | ||
11 | +void main() async { | ||
12 | + WidgetsFlutterBinding.ensureInitialized(); | ||
13 | + cacheDir = (await getApplicationCacheDirectory()).path; | ||
14 | + logDir = ''; | ||
15 | + if (Platform.isAndroid) { | ||
16 | + logDir = (await getExternalCacheDirectories())?[0].path ?? cacheDir; | ||
17 | + } else if (Platform.isIOS) { | ||
18 | + logDir = (await getApplicationSupportDirectory()).path; | ||
19 | + } | ||
20 | + await XLog.open(XLogConfig(cacheDir: cacheDir, logDir: logDir, consoleLogOpen: true)); | ||
21 | + runApp(const MyApp()); | ||
22 | +} | ||
23 | + | ||
24 | +class MyApp extends StatefulWidget { | ||
25 | + const MyApp({super.key}); | ||
26 | + | ||
27 | + @override | ||
28 | + State<MyApp> createState() => _MyAppState(); | ||
29 | +} | ||
30 | + | ||
31 | +class _MyAppState extends State<MyApp> { | ||
32 | + | ||
33 | + @override | ||
34 | + Widget build(BuildContext context) { | ||
35 | + XLog.i("MyApp", "build _MyAppState"); | ||
36 | + compute((message) { | ||
37 | + XLog.i("MyApp", "$message in Isolate"); | ||
38 | + }, "compute in build"); | ||
39 | + return MaterialApp( | ||
40 | + home: Scaffold( | ||
41 | + appBar: AppBar( | ||
42 | + title: const Text('FlutterXLog example app'), | ||
43 | + ), | ||
44 | + body: Column ( | ||
45 | + children: [ | ||
46 | + Text('Cached XLog in $cacheDir \nWrite XLog to $logDir \n'), | ||
47 | + TextButton(onPressed: () { | ||
48 | + XLog.i("MyApp", "click"); | ||
49 | + XLog.close(); | ||
50 | + }, child: const Text('close XLog')) | ||
51 | + ] | ||
52 | + ), | ||
53 | + ), | ||
54 | + ); | ||
55 | + } | ||
56 | +} |
example/pubspec.lock
0 → 100644
1 | +# Generated by pub | ||
2 | +# See https://dart.dev/tools/pub/glossary#lockfile | ||
3 | +packages: | ||
4 | + async: | ||
5 | + dependency: transitive | ||
6 | + description: | ||
7 | + name: async | ||
8 | + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" | ||
9 | + url: "https://pub.flutter-io.cn" | ||
10 | + source: hosted | ||
11 | + version: "2.11.0" | ||
12 | + boolean_selector: | ||
13 | + dependency: transitive | ||
14 | + description: | ||
15 | + name: boolean_selector | ||
16 | + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" | ||
17 | + url: "https://pub.flutter-io.cn" | ||
18 | + source: hosted | ||
19 | + version: "2.1.1" | ||
20 | + characters: | ||
21 | + dependency: transitive | ||
22 | + description: | ||
23 | + name: characters | ||
24 | + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" | ||
25 | + url: "https://pub.flutter-io.cn" | ||
26 | + source: hosted | ||
27 | + version: "1.3.0" | ||
28 | + clock: | ||
29 | + dependency: transitive | ||
30 | + description: | ||
31 | + name: clock | ||
32 | + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf | ||
33 | + url: "https://pub.flutter-io.cn" | ||
34 | + source: hosted | ||
35 | + version: "1.1.1" | ||
36 | + collection: | ||
37 | + dependency: transitive | ||
38 | + description: | ||
39 | + name: collection | ||
40 | + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a | ||
41 | + url: "https://pub.flutter-io.cn" | ||
42 | + source: hosted | ||
43 | + version: "1.18.0" | ||
44 | + cupertino_icons: | ||
45 | + dependency: "direct main" | ||
46 | + description: | ||
47 | + name: cupertino_icons | ||
48 | + sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6 | ||
49 | + url: "https://pub.flutter-io.cn" | ||
50 | + source: hosted | ||
51 | + version: "1.0.8" | ||
52 | + fake_async: | ||
53 | + dependency: transitive | ||
54 | + description: | ||
55 | + name: fake_async | ||
56 | + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" | ||
57 | + url: "https://pub.flutter-io.cn" | ||
58 | + source: hosted | ||
59 | + version: "1.3.1" | ||
60 | + ffi: | ||
61 | + dependency: "direct main" | ||
62 | + description: | ||
63 | + name: ffi | ||
64 | + sha256: "16ed7b077ef01ad6170a3d0c57caa4a112a38d7a2ed5602e0aca9ca6f3d98da6" | ||
65 | + url: "https://pub.flutter-io.cn" | ||
66 | + source: hosted | ||
67 | + version: "2.1.3" | ||
68 | + file: | ||
69 | + dependency: transitive | ||
70 | + description: | ||
71 | + name: file | ||
72 | + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" | ||
73 | + url: "https://pub.flutter-io.cn" | ||
74 | + source: hosted | ||
75 | + version: "7.0.0" | ||
76 | + flutter: | ||
77 | + dependency: "direct main" | ||
78 | + description: flutter | ||
79 | + source: sdk | ||
80 | + version: "0.0.0" | ||
81 | + flutter_driver: | ||
82 | + dependency: transitive | ||
83 | + description: flutter | ||
84 | + source: sdk | ||
85 | + version: "0.0.0" | ||
86 | + flutter_lints: | ||
87 | + dependency: "direct dev" | ||
88 | + description: | ||
89 | + name: flutter_lints | ||
90 | + sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04 | ||
91 | + url: "https://pub.flutter-io.cn" | ||
92 | + source: hosted | ||
93 | + version: "2.0.3" | ||
94 | + flutter_test: | ||
95 | + dependency: "direct dev" | ||
96 | + description: flutter | ||
97 | + source: sdk | ||
98 | + version: "0.0.0" | ||
99 | + flutter_xlog: | ||
100 | + dependency: "direct main" | ||
101 | + description: | ||
102 | + path: ".." | ||
103 | + relative: true | ||
104 | + source: path | ||
105 | + version: "0.1.2" | ||
106 | + fuchsia_remote_debug_protocol: | ||
107 | + dependency: transitive | ||
108 | + description: flutter | ||
109 | + source: sdk | ||
110 | + version: "0.0.0" | ||
111 | + integration_test: | ||
112 | + dependency: "direct dev" | ||
113 | + description: flutter | ||
114 | + source: sdk | ||
115 | + version: "0.0.0" | ||
116 | + leak_tracker: | ||
117 | + dependency: transitive | ||
118 | + description: | ||
119 | + name: leak_tracker | ||
120 | + sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" | ||
121 | + url: "https://pub.flutter-io.cn" | ||
122 | + source: hosted | ||
123 | + version: "10.0.4" | ||
124 | + leak_tracker_flutter_testing: | ||
125 | + dependency: transitive | ||
126 | + description: | ||
127 | + name: leak_tracker_flutter_testing | ||
128 | + sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" | ||
129 | + url: "https://pub.flutter-io.cn" | ||
130 | + source: hosted | ||
131 | + version: "3.0.3" | ||
132 | + leak_tracker_testing: | ||
133 | + dependency: transitive | ||
134 | + description: | ||
135 | + name: leak_tracker_testing | ||
136 | + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" | ||
137 | + url: "https://pub.flutter-io.cn" | ||
138 | + source: hosted | ||
139 | + version: "3.0.1" | ||
140 | + lints: | ||
141 | + dependency: transitive | ||
142 | + description: | ||
143 | + name: lints | ||
144 | + sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452" | ||
145 | + url: "https://pub.flutter-io.cn" | ||
146 | + source: hosted | ||
147 | + version: "2.1.1" | ||
148 | + matcher: | ||
149 | + dependency: transitive | ||
150 | + description: | ||
151 | + name: matcher | ||
152 | + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb | ||
153 | + url: "https://pub.flutter-io.cn" | ||
154 | + source: hosted | ||
155 | + version: "0.12.16+1" | ||
156 | + material_color_utilities: | ||
157 | + dependency: transitive | ||
158 | + description: | ||
159 | + name: material_color_utilities | ||
160 | + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" | ||
161 | + url: "https://pub.flutter-io.cn" | ||
162 | + source: hosted | ||
163 | + version: "0.8.0" | ||
164 | + meta: | ||
165 | + dependency: transitive | ||
166 | + description: | ||
167 | + name: meta | ||
168 | + sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" | ||
169 | + url: "https://pub.flutter-io.cn" | ||
170 | + source: hosted | ||
171 | + version: "1.12.0" | ||
172 | + path: | ||
173 | + dependency: transitive | ||
174 | + description: | ||
175 | + name: path | ||
176 | + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" | ||
177 | + url: "https://pub.flutter-io.cn" | ||
178 | + source: hosted | ||
179 | + version: "1.9.0" | ||
180 | + path_provider: | ||
181 | + dependency: "direct main" | ||
182 | + description: | ||
183 | + name: path_provider | ||
184 | + sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd" | ||
185 | + url: "https://pub.flutter-io.cn" | ||
186 | + source: hosted | ||
187 | + version: "2.1.5" | ||
188 | + path_provider_android: | ||
189 | + dependency: transitive | ||
190 | + description: | ||
191 | + name: path_provider_android | ||
192 | + sha256: "6f01f8e37ec30b07bc424b4deabac37cacb1bc7e2e515ad74486039918a37eb7" | ||
193 | + url: "https://pub.flutter-io.cn" | ||
194 | + source: hosted | ||
195 | + version: "2.2.10" | ||
196 | + path_provider_foundation: | ||
197 | + dependency: transitive | ||
198 | + description: | ||
199 | + name: path_provider_foundation | ||
200 | + sha256: "4843174df4d288f5e29185bd6e72a6fbdf5a4a4602717eed565497429f179942" | ||
201 | + url: "https://pub.flutter-io.cn" | ||
202 | + source: hosted | ||
203 | + version: "2.4.1" | ||
204 | + path_provider_linux: | ||
205 | + dependency: transitive | ||
206 | + description: | ||
207 | + name: path_provider_linux | ||
208 | + sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279 | ||
209 | + url: "https://pub.flutter-io.cn" | ||
210 | + source: hosted | ||
211 | + version: "2.2.1" | ||
212 | + path_provider_platform_interface: | ||
213 | + dependency: transitive | ||
214 | + description: | ||
215 | + name: path_provider_platform_interface | ||
216 | + sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334" | ||
217 | + url: "https://pub.flutter-io.cn" | ||
218 | + source: hosted | ||
219 | + version: "2.1.2" | ||
220 | + path_provider_windows: | ||
221 | + dependency: transitive | ||
222 | + description: | ||
223 | + name: path_provider_windows | ||
224 | + sha256: bd6f00dbd873bfb70d0761682da2b3a2c2fccc2b9e84c495821639601d81afe7 | ||
225 | + url: "https://pub.flutter-io.cn" | ||
226 | + source: hosted | ||
227 | + version: "2.3.0" | ||
228 | + platform: | ||
229 | + dependency: transitive | ||
230 | + description: | ||
231 | + name: platform | ||
232 | + sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec" | ||
233 | + url: "https://pub.flutter-io.cn" | ||
234 | + source: hosted | ||
235 | + version: "3.1.4" | ||
236 | + plugin_platform_interface: | ||
237 | + dependency: transitive | ||
238 | + description: | ||
239 | + name: plugin_platform_interface | ||
240 | + sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02" | ||
241 | + url: "https://pub.flutter-io.cn" | ||
242 | + source: hosted | ||
243 | + version: "2.1.8" | ||
244 | + process: | ||
245 | + dependency: transitive | ||
246 | + description: | ||
247 | + name: process | ||
248 | + sha256: "21e54fd2faf1b5bdd5102afd25012184a6793927648ea81eea80552ac9405b32" | ||
249 | + url: "https://pub.flutter-io.cn" | ||
250 | + source: hosted | ||
251 | + version: "5.0.2" | ||
252 | + sky_engine: | ||
253 | + dependency: transitive | ||
254 | + description: flutter | ||
255 | + source: sdk | ||
256 | + version: "0.0.99" | ||
257 | + source_span: | ||
258 | + dependency: transitive | ||
259 | + description: | ||
260 | + name: source_span | ||
261 | + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" | ||
262 | + url: "https://pub.flutter-io.cn" | ||
263 | + source: hosted | ||
264 | + version: "1.10.0" | ||
265 | + stack_trace: | ||
266 | + dependency: transitive | ||
267 | + description: | ||
268 | + name: stack_trace | ||
269 | + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" | ||
270 | + url: "https://pub.flutter-io.cn" | ||
271 | + source: hosted | ||
272 | + version: "1.11.1" | ||
273 | + stream_channel: | ||
274 | + dependency: transitive | ||
275 | + description: | ||
276 | + name: stream_channel | ||
277 | + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 | ||
278 | + url: "https://pub.flutter-io.cn" | ||
279 | + source: hosted | ||
280 | + version: "2.1.2" | ||
281 | + string_scanner: | ||
282 | + dependency: transitive | ||
283 | + description: | ||
284 | + name: string_scanner | ||
285 | + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" | ||
286 | + url: "https://pub.flutter-io.cn" | ||
287 | + source: hosted | ||
288 | + version: "1.2.0" | ||
289 | + sync_http: | ||
290 | + dependency: transitive | ||
291 | + description: | ||
292 | + name: sync_http | ||
293 | + sha256: "7f0cd72eca000d2e026bcd6f990b81d0ca06022ef4e32fb257b30d3d1014a961" | ||
294 | + url: "https://pub.flutter-io.cn" | ||
295 | + source: hosted | ||
296 | + version: "0.3.1" | ||
297 | + term_glyph: | ||
298 | + dependency: transitive | ||
299 | + description: | ||
300 | + name: term_glyph | ||
301 | + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 | ||
302 | + url: "https://pub.flutter-io.cn" | ||
303 | + source: hosted | ||
304 | + version: "1.2.1" | ||
305 | + test_api: | ||
306 | + dependency: transitive | ||
307 | + description: | ||
308 | + name: test_api | ||
309 | + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" | ||
310 | + url: "https://pub.flutter-io.cn" | ||
311 | + source: hosted | ||
312 | + version: "0.7.0" | ||
313 | + vector_math: | ||
314 | + dependency: transitive | ||
315 | + description: | ||
316 | + name: vector_math | ||
317 | + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" | ||
318 | + url: "https://pub.flutter-io.cn" | ||
319 | + source: hosted | ||
320 | + version: "2.1.4" | ||
321 | + vm_service: | ||
322 | + dependency: transitive | ||
323 | + description: | ||
324 | + name: vm_service | ||
325 | + sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" | ||
326 | + url: "https://pub.flutter-io.cn" | ||
327 | + source: hosted | ||
328 | + version: "14.2.1" | ||
329 | + webdriver: | ||
330 | + dependency: transitive | ||
331 | + description: | ||
332 | + name: webdriver | ||
333 | + sha256: "003d7da9519e1e5f329422b36c4dcdf18d7d2978d1ba099ea4e45ba490ed845e" | ||
334 | + url: "https://pub.flutter-io.cn" | ||
335 | + source: hosted | ||
336 | + version: "3.0.3" | ||
337 | + xdg_directories: | ||
338 | + dependency: transitive | ||
339 | + description: | ||
340 | + name: xdg_directories | ||
341 | + sha256: "7a3f37b05d989967cdddcbb571f1ea834867ae2faa29725fd085180e0883aa15" | ||
342 | + url: "https://pub.flutter-io.cn" | ||
343 | + source: hosted | ||
344 | + version: "1.1.0" | ||
345 | +sdks: | ||
346 | + dart: ">=3.4.0 <4.0.0" | ||
347 | + flutter: ">=3.22.0" |
example/pubspec.yaml
0 → 100644
1 | +name: flutter_xlog_example | ||
2 | +description: "Demonstrates how to use the flutter_xlog plugin." | ||
3 | +# The following line prevents the package from being accidentally published to | ||
4 | +# pub.dev using `flutter pub publish`. This is preferred for private packages. | ||
5 | +publish_to: 'none' # Remove this line if you wish to publish to pub.dev | ||
6 | + | ||
7 | +environment: | ||
8 | + sdk: '>=3.2.1 <4.0.0' | ||
9 | + | ||
10 | +# Dependencies specify other packages that your package needs in order to work. | ||
11 | +# To automatically upgrade your package dependencies to the latest versions | ||
12 | +# consider running `flutter pub upgrade --major-versions`. Alternatively, | ||
13 | +# dependencies can be manually updated by changing the version numbers below to | ||
14 | +# the latest version available on pub.dev. To see which dependencies have newer | ||
15 | +# versions available, run `flutter pub outdated`. | ||
16 | +dependencies: | ||
17 | + flutter: | ||
18 | + sdk: flutter | ||
19 | + | ||
20 | + flutter_xlog: | ||
21 | + # When depending on this package from a real application you should use: | ||
22 | + # flutter_xlog: ^x.y.z | ||
23 | + # See https://dart.dev/tools/pub/dependencies#version-constraints | ||
24 | + # The example app is bundled with the plugin so we use a path dependency on | ||
25 | + # the parent directory to use the current plugin's version. | ||
26 | + path: ../ | ||
27 | + | ||
28 | + # The following adds the Cupertino Icons font to your application. | ||
29 | + # Use with the CupertinoIcons class for iOS style icons. | ||
30 | + cupertino_icons: ^1.0.2 | ||
31 | + path_provider: ^2.1.1 | ||
32 | + ffi: ^2.1.0 | ||
33 | + | ||
34 | +dev_dependencies: | ||
35 | + integration_test: | ||
36 | + sdk: flutter | ||
37 | + flutter_test: | ||
38 | + sdk: flutter | ||
39 | + | ||
40 | + # The "flutter_lints" package below contains a set of recommended lints to | ||
41 | + # encourage good coding practices. The lint set provided by the package is | ||
42 | + # activated in the `analysis_options.yaml` file located at the root of your | ||
43 | + # package. See that file for information about deactivating specific lint | ||
44 | + # rules and activating additional ones. | ||
45 | + flutter_lints: ^2.0.0 | ||
46 | + | ||
47 | +# For information on the generic Dart part of this file, see the | ||
48 | +# following page: https://dart.dev/tools/pub/pubspec | ||
49 | + | ||
50 | +# The following section is specific to Flutter packages. | ||
51 | +flutter: | ||
52 | + | ||
53 | + # The following line ensures that the Material Icons font is | ||
54 | + # included with your application, so that you can use the icons in | ||
55 | + # the material Icons class. | ||
56 | + uses-material-design: true | ||
57 | + | ||
58 | + # To add assets to your application, add an assets section, like this: | ||
59 | + # assets: | ||
60 | + # - images/a_dot_burr.jpeg | ||
61 | + # - images/a_dot_ham.jpeg | ||
62 | + | ||
63 | + # An image asset can refer to one or more resolution-specific "variants", see | ||
64 | + # https://flutter.dev/assets-and-images/#resolution-aware | ||
65 | + | ||
66 | + # For details regarding adding assets from package dependencies, see | ||
67 | + # https://flutter.dev/assets-and-images/#from-packages | ||
68 | + | ||
69 | + # To add custom fonts to your application, add a fonts section here, | ||
70 | + # in this "flutter" section. Each entry in this list should have a | ||
71 | + # "family" key with the font family name, and a "fonts" key with a | ||
72 | + # list giving the asset and other descriptors for the font. For | ||
73 | + # example: | ||
74 | + # fonts: | ||
75 | + # - family: Schyler | ||
76 | + # fonts: | ||
77 | + # - asset: fonts/Schyler-Regular.ttf | ||
78 | + # - asset: fonts/Schyler-Italic.ttf | ||
79 | + # style: italic | ||
80 | + # - family: Trajan Pro | ||
81 | + # fonts: | ||
82 | + # - asset: fonts/TrajanPro.ttf | ||
83 | + # - asset: fonts/TrajanPro_Bold.ttf | ||
84 | + # weight: 700 | ||
85 | + # | ||
86 | + # For details regarding fonts from package dependencies, | ||
87 | + # see https://flutter.dev/custom-fonts/#from-packages |
ios/.gitignore
0 → 100644
1 | +.idea/ | ||
2 | +.vagrant/ | ||
3 | +.sconsign.dblite | ||
4 | +.svn/ | ||
5 | + | ||
6 | +.DS_Store | ||
7 | +*.swp | ||
8 | +profile | ||
9 | + | ||
10 | +DerivedData/ | ||
11 | +build/ | ||
12 | +GeneratedPluginRegistrant.h | ||
13 | +GeneratedPluginRegistrant.m | ||
14 | + | ||
15 | +.generated/ | ||
16 | + | ||
17 | +*.pbxuser | ||
18 | +*.mode1v3 | ||
19 | +*.mode2v3 | ||
20 | +*.perspectivev3 | ||
21 | + | ||
22 | +!default.pbxuser | ||
23 | +!default.mode1v3 | ||
24 | +!default.mode2v3 | ||
25 | +!default.perspectivev3 | ||
26 | + | ||
27 | +xcuserdata | ||
28 | + | ||
29 | +*.moved-aside | ||
30 | + | ||
31 | +*.pyc | ||
32 | +*sync/ | ||
33 | +Icon? | ||
34 | +.tags* | ||
35 | + | ||
36 | +/Flutter/Generated.xcconfig | ||
37 | +/Flutter/ephemeral/ | ||
38 | +/Flutter/flutter_export_environment.sh |
ios/Assets/.gitkeep
0 → 100644
ios/Classes/FlutterXLogPlugin.swift
0 → 100644
1 | +import Flutter | ||
2 | +import UIKit | ||
3 | + | ||
4 | +public class FlutterXLogPlugin: NSObject, FlutterPlugin { | ||
5 | + | ||
6 | + var bridge = XLogBridge(); | ||
7 | + | ||
8 | + public static func register(with registrar: FlutterPluginRegistrar) { | ||
9 | + let channel = FlutterMethodChannel(name: "flutter_xlog", binaryMessenger: registrar.messenger()) | ||
10 | + let instance = FlutterXLogPlugin() | ||
11 | + registrar.addMethodCallDelegate(instance, channel: channel) | ||
12 | + } | ||
13 | + | ||
14 | + public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { | ||
15 | + switch call.method { | ||
16 | + case "open": | ||
17 | + let params = call.arguments as! [String:Any]; | ||
18 | + let level = params["level"] as! UInt; | ||
19 | + let cacheDir = params["cacheDir"] as! String; | ||
20 | + let logDir = params["logDir"] as! String; | ||
21 | + let namePrefix = params["namePrefix"] as! String; | ||
22 | + let cacheDays = params["cacheDays"] as! UInt; | ||
23 | + let consoleLogOpen = params["consoleLogOpen"] as! Bool; | ||
24 | + let pubKey = params["pubKey"] as! String; | ||
25 | + bridge.open(level, cacheDir: cacheDir, logDir: logDir, prefix: namePrefix, cacheDays: cacheDays, pubKey: pubKey, consoleLogOpen: consoleLogOpen); | ||
26 | + result(nil); | ||
27 | + case "flush": | ||
28 | + bridge.flush(); | ||
29 | + result(nil); | ||
30 | + case "close": | ||
31 | + bridge.close(); | ||
32 | + result(nil); | ||
33 | + default: | ||
34 | + result(FlutterMethodNotImplemented) | ||
35 | + } | ||
36 | + } | ||
37 | +} |
ios/Classes/xlog-swift-bridge.h
0 → 100644
1 | +#import <Foundation/Foundation.h> | ||
2 | + | ||
3 | +@interface XLogBridge: NSObject | ||
4 | + | ||
5 | +- (void)open: (NSUInteger)level cacheDir:(NSString*)cacheDir logDir:(NSString*)logDir prefix:(NSString*)prefix cacheDays:(NSUInteger)cacheDays pubKey:(NSString*)pubKey consoleLogOpen:(BOOL)consoleLogOpen; | ||
6 | + | ||
7 | +- (void)flush; | ||
8 | + | ||
9 | +- (void)close; | ||
10 | +@end |
ios/Classes/xlog-swift-bridge.mm
0 → 100644
1 | +#include <sys/xattr.h> | ||
2 | +#import <mars/xlog/xloggerbase.h> | ||
3 | +#import <mars/xlog/xlogger.h> | ||
4 | +#import <mars/xlog/appender.h> | ||
5 | +#import <mars/xlog/xlogger_interface.h> | ||
6 | +#import <xlog-swift-bridge.h> | ||
7 | + | ||
8 | +@implementation XLogBridge | ||
9 | +- (void)open:(NSUInteger)level cacheDir:(NSString*)cacheDir logDir:(NSString*)logDir prefix:(NSString*)prefix cacheDays:(NSUInteger)cacheDays pubKey:(NSString*)pubKey consoleLogOpen:(BOOL)consoleLogOpen { | ||
10 | + xlogger_SetLevel((TLogLevel)level); | ||
11 | + mars::xlog::appender_set_console_log(consoleLogOpen); | ||
12 | + mars::xlog::XLogConfig config; | ||
13 | + config.pub_key_ = [pubKey UTF8String]; | ||
14 | + config.mode_ = mars::xlog::kAppenderAsync; | ||
15 | + config.logdir_ = [logDir UTF8String]; | ||
16 | + config.nameprefix_ = [prefix UTF8String]; | ||
17 | + config.compress_mode_ = mars::xlog::kZlib; | ||
18 | + config.compress_level_ = 0; | ||
19 | + config.cachedir_ = [cacheDir UTF8String]; | ||
20 | + config.cache_days_ = cacheDays; | ||
21 | + mars::xlog::appender_open(config); | ||
22 | + //keep Dart_XloggerWrite | ||
23 | + Dart_XloggerWrite(0, 2, "FlutterXLog", 0, 0, 0, "Open Flutter XLog."); | ||
24 | +} | ||
25 | + | ||
26 | +- (void)flush { | ||
27 | + mars::xlog::appender_flush_sync(); | ||
28 | +} | ||
29 | + | ||
30 | +- (void)close { | ||
31 | + mars::xlog::appender_close(); | ||
32 | +} | ||
33 | + | ||
34 | +@end |
1 | +// Tencent is pleased to support the open source community by making Mars available. | ||
2 | +// Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. | ||
3 | + | ||
4 | +// Licensed under the MIT License (the "License"); you may not use this file except in | ||
5 | +// compliance with the License. You may obtain a copy of the License at | ||
6 | +// http://opensource.org/licenses/MIT | ||
7 | + | ||
8 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | ||
9 | +// is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
10 | +// or implied. See the License for the specific language governing permissions and limitations under | ||
11 | +// the License. | ||
12 | + | ||
13 | +// | ||
14 | +// ThreadOperationQueue.h | ||
15 | +// MicroMessenger | ||
16 | +// | ||
17 | +// Created by yerungui on 12-12-18. | ||
18 | +// | ||
19 | + | ||
20 | +#ifndef __MicroMessenger__ThreadOperationQueue__ | ||
21 | +#define __MicroMessenger__ThreadOperationQueue__ | ||
22 | + | ||
23 | +#import <Foundation/Foundation.h> | ||
24 | + | ||
25 | +@interface ThreadQueue : NSObject { | ||
26 | +} | ||
27 | + | ||
28 | ++ (BOOL)RunWithTarget:(id)target selector:(SEL)sel object:(id)arg; | ||
29 | +@end | ||
30 | + | ||
31 | +extern "C" BOOL RunWithTarget(void (*_funp)(void*), void* _arg); | ||
32 | +extern "C" BOOL RunWithTargetNoParam(void (*_fun)()); | ||
33 | + | ||
34 | +#endif /* defined(__MicroMessenger__ThreadOperationQueue__) */ |
1 | +// Tencent is pleased to support the open source community by making Mars available. | ||
2 | +// Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. | ||
3 | + | ||
4 | +// Licensed under the MIT License (the "License"); you may not use this file except in | ||
5 | +// compliance with the License. You may obtain a copy of the License at | ||
6 | +// http://opensource.org/licenses/MIT | ||
7 | + | ||
8 | +// Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
9 | +// distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
10 | +// either express or implied. See the License for the specific language governing permissions and | ||
11 | +// limitations under the License. | ||
12 | + | ||
13 | +#ifndef COMM_AUTOBUFFER_H_ | ||
14 | +#define COMM_AUTOBUFFER_H_ | ||
15 | + | ||
16 | +#include <string.h> | ||
17 | +#include <sys/types.h> | ||
18 | + | ||
19 | +class AutoBuffer { | ||
20 | + public: | ||
21 | + enum TSeek { | ||
22 | + ESeekStart, | ||
23 | + ESeekCur, | ||
24 | + ESeekEnd, | ||
25 | + }; | ||
26 | + | ||
27 | + public: | ||
28 | + explicit AutoBuffer(size_t _size = 128); | ||
29 | + explicit AutoBuffer(void* _pbuffer, size_t _len, size_t _size = 128); | ||
30 | + explicit AutoBuffer(const void* _pbuffer, size_t _len, size_t _size = 128); | ||
31 | + ~AutoBuffer(); | ||
32 | + | ||
33 | + void AllocWrite(size_t _readytowrite, bool _changelength = true); | ||
34 | + void AddCapacity(size_t _len); | ||
35 | + | ||
36 | + template <class T> | ||
37 | + void Write(const T& _val) { | ||
38 | + Write(&_val, sizeof(_val)); | ||
39 | + } | ||
40 | + | ||
41 | + template <class T> | ||
42 | + void Write(off_t& _pos, const T& _val) { | ||
43 | + Write(_pos, &_val, sizeof(_val)); | ||
44 | + } | ||
45 | + | ||
46 | + template <class T> | ||
47 | + void Write(const off_t& _pos, const T& _val) { | ||
48 | + Write(_pos, &_val, sizeof(_val)); | ||
49 | + } | ||
50 | + | ||
51 | + void Write(const char* const _val) { | ||
52 | + Write(_val, strlen(_val)); | ||
53 | + } | ||
54 | + | ||
55 | + void Write(off_t& _pos, const char* const _val) { | ||
56 | + Write(_pos, _val, strlen(_val)); | ||
57 | + } | ||
58 | + | ||
59 | + void Write(const off_t& _pos, const char* const _val) { | ||
60 | + Write(_pos, _val, strlen(_val)); | ||
61 | + } | ||
62 | + | ||
63 | + void Write(const AutoBuffer& _buffer); | ||
64 | + void Write(const void* _pbuffer, size_t _len); | ||
65 | + void Write(off_t& _pos, const AutoBuffer& _buffer); | ||
66 | + void Write(off_t& _pos, const void* _pbuffer, size_t _len); | ||
67 | + void Write(const off_t& _pos, const AutoBuffer& _buffer); | ||
68 | + void Write(const off_t& _pos, const void* _pbuffer, size_t _len); | ||
69 | + void Write(TSeek _seek, const void* _pbuffer, size_t _len); | ||
70 | + | ||
71 | + template <class T> | ||
72 | + size_t Read(T& _val) { | ||
73 | + return Read(&_val, sizeof(_val)); | ||
74 | + } | ||
75 | + | ||
76 | + template <class T> | ||
77 | + size_t Read(off_t& _pos, T& _val) const { | ||
78 | + return Read(_pos, &_val, sizeof(_val)); | ||
79 | + } | ||
80 | + | ||
81 | + template <class T> | ||
82 | + size_t Read(const off_t& _pos, T& _val) const { | ||
83 | + return Read(_pos, &_val, sizeof(_val)); | ||
84 | + } | ||
85 | + | ||
86 | + size_t Read(void* _pbuffer, size_t _len); | ||
87 | + size_t Read(AutoBuffer& _rhs, size_t _len); | ||
88 | + | ||
89 | + size_t Read(off_t& _pos, void* _pbuffer, size_t _len) const; | ||
90 | + size_t Read(off_t& _pos, AutoBuffer& _rhs, size_t _len) const; | ||
91 | + | ||
92 | + size_t Read(const off_t& _pos, void* _pbuffer, size_t _len) const; | ||
93 | + size_t Read(const off_t& _pos, AutoBuffer& _rhs, size_t _len) const; | ||
94 | + | ||
95 | + off_t Move(off_t _move_len); | ||
96 | + | ||
97 | + void Seek(off_t _offset, TSeek _eorigin); | ||
98 | + void Length(off_t _pos, size_t _lenght); | ||
99 | + | ||
100 | + void* Ptr(off_t _offset = 0); | ||
101 | + void* PosPtr(); | ||
102 | + const void* Ptr(off_t _offset = 0) const; | ||
103 | + const void* PosPtr() const; | ||
104 | + | ||
105 | + off_t Pos() const; | ||
106 | + size_t PosLength() const; | ||
107 | + size_t Length() const; | ||
108 | + size_t Capacity() const; | ||
109 | + | ||
110 | + void Attach(void* _pbuffer, size_t _len); | ||
111 | + void Attach(AutoBuffer& _rhs); | ||
112 | + void* Detach(size_t* _plen = NULL); | ||
113 | + | ||
114 | + void Reset(); | ||
115 | + | ||
116 | + private: | ||
117 | + void __FitSize(size_t _len); | ||
118 | + | ||
119 | + private: | ||
120 | + AutoBuffer(const AutoBuffer& _rhs); | ||
121 | + AutoBuffer& operator=(const AutoBuffer& _rhs); | ||
122 | + | ||
123 | + private: | ||
124 | + unsigned char* parray_; | ||
125 | + off_t pos_; | ||
126 | + size_t length_; | ||
127 | + size_t capacity_; | ||
128 | + size_t malloc_unitsize_; | ||
129 | +}; | ||
130 | + | ||
131 | +extern const AutoBuffer KNullAtuoBuffer; | ||
132 | + | ||
133 | +template <class S> | ||
134 | +class copy_wrapper_helper; | ||
135 | + | ||
136 | +template <> | ||
137 | +class copy_wrapper_helper<AutoBuffer> { | ||
138 | + public: | ||
139 | + static void copy_constructor(AutoBuffer& _lhs, AutoBuffer& _rhs) { | ||
140 | + _lhs.Attach(_rhs); | ||
141 | + } | ||
142 | + | ||
143 | + static void copy_constructor(AutoBuffer& _lhs, const AutoBuffer& _rhs) { | ||
144 | + _lhs.Attach(const_cast<AutoBuffer&>(_rhs)); | ||
145 | + } | ||
146 | + | ||
147 | + static void destructor(AutoBuffer& _delobj) { | ||
148 | + } | ||
149 | +}; | ||
150 | + | ||
151 | +#endif // COMM_AUTOBUFFER_H_ |
1 | + | ||
2 | +// Tencent is pleased to support the open source community by making Mars available. | ||
3 | +// Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. | ||
4 | + | ||
5 | +// Licensed under the MIT License (the "License"); you may not use this file except in | ||
6 | +// compliance with the License. You may obtain a copy of the License at | ||
7 | +// http://opensource.org/licenses/MIT | ||
8 | + | ||
9 | +// Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
10 | +// distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
11 | +// either express or implied. See the License for the specific language governing permissions and | ||
12 | +// limitations under the License. | ||
13 | + | ||
14 | +// | ||
15 | +// comm_data.h | ||
16 | +// comm | ||
17 | +// | ||
18 | +// Created by garry on 2017/2/17. | ||
19 | +// | ||
20 | + | ||
21 | +#ifndef comm_data_h | ||
22 | +#define comm_data_h | ||
23 | + | ||
24 | +#include <stdint.h> | ||
25 | + | ||
26 | +#include <string> | ||
27 | + | ||
28 | +namespace mars { | ||
29 | +namespace comm { | ||
30 | + | ||
31 | +enum ProxyType { | ||
32 | + kProxyNone = 0, | ||
33 | + kProxyHttpTunel, | ||
34 | + kProxySocks5, | ||
35 | + kProxyHttp, | ||
36 | +}; | ||
37 | + | ||
38 | +class ProxyInfo { | ||
39 | + public: | ||
40 | + ProxyInfo() : ProxyInfo(kProxyNone, "", "", 0, "", "") { | ||
41 | + } | ||
42 | + ProxyInfo(ProxyType _type, | ||
43 | + const std::string& _host, | ||
44 | + const std::string& _ip, | ||
45 | + uint16_t _port, | ||
46 | + const std::string& _username, | ||
47 | + const std::string& _password) | ||
48 | + : type(_type), host(_host), ip(_ip), port(_port), username(_username), password(_password) { | ||
49 | + } | ||
50 | + | ||
51 | + bool operator==(const ProxyInfo& _rh) { | ||
52 | + if (type != _rh.type) { | ||
53 | + return false; | ||
54 | + } | ||
55 | + if (kProxyNone == type) { | ||
56 | + return true; | ||
57 | + } | ||
58 | + return host == _rh.host && ip == _rh.ip && port == _rh.port && username == _rh.username | ||
59 | + && password == _rh.password; | ||
60 | + } | ||
61 | + | ||
62 | + bool IsValid() const { | ||
63 | + return kProxyNone == type || ((!ip.empty() || !host.empty()) && port > 0); | ||
64 | + } | ||
65 | + bool IsAddressValid() const { | ||
66 | + return type != kProxyNone && ((!ip.empty() || !host.empty()) && port > 0); | ||
67 | + } | ||
68 | + | ||
69 | + public: | ||
70 | + ProxyType type; | ||
71 | + std::string host; | ||
72 | + std::string ip; | ||
73 | + uint16_t port; | ||
74 | + std::string username; | ||
75 | + std::string password; | ||
76 | +}; | ||
77 | + | ||
78 | +// | ||
79 | +enum class BizType{CGI = 0, CDN, COUNT}; | ||
80 | +enum class ProtoType{TCP = 0, QUIC, COUNT}; | ||
81 | + | ||
82 | +struct ConnRecord{ | ||
83 | + BizType biz = BizType::CGI; | ||
84 | + ProtoType proto = ProtoType::TCP; | ||
85 | + bool succeed = false; //.是否连接成功. | ||
86 | + uint64_t begin_timestamp_ms = 0; | ||
87 | + unsigned cost_ms = 0; | ||
88 | +}; | ||
89 | +inline bool operator<(const ConnRecord& lhs, const ConnRecord& rhs){ | ||
90 | + return lhs.begin_timestamp_ms < rhs.begin_timestamp_ms; | ||
91 | +} | ||
92 | + | ||
93 | +} // namespace comm | ||
94 | +} // namespace mars | ||
95 | + | ||
96 | +#endif /* comm_data_h */ |
1 | +// Tencent is pleased to support the open source community by making Mars available. | ||
2 | +// Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. | ||
3 | + | ||
4 | +// Licensed under the MIT License (the "License"); you may not use this file except in | ||
5 | +// compliance with the License. You may obtain a copy of the License at | ||
6 | +// http://opensource.org/licenses/MIT | ||
7 | + | ||
8 | +// Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
9 | +// distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
10 | +// either express or implied. See the License for the specific language governing permissions and | ||
11 | +// limitations under the License. | ||
12 | + | ||
13 | +//============================================================================ | ||
14 | +// Name : has_member.h | ||
15 | +// Author : | ||
16 | +// Version : | ||
17 | +// Copyright : Your copyright notice | ||
18 | +// Description : Hello World in C++, Ansi-style | ||
19 | +//============================================================================ | ||
20 | + | ||
21 | +#ifndef COMM_HAS_MEMBER_H_ | ||
22 | +#define COMM_HAS_MEMBER_H_ | ||
23 | + | ||
24 | +template <bool TYPE> | ||
25 | +struct bool_type {}; | ||
26 | + | ||
27 | +#define DEFINE_HAS_MEMBER_WITH_TYPE(member_name, member_type) \ | ||
28 | + template <typename T> \ | ||
29 | + class has_##member_name { \ | ||
30 | + private: \ | ||
31 | + struct yes_type { \ | ||
32 | + char x[1]; \ | ||
33 | + }; \ | ||
34 | + struct no_type { \ | ||
35 | + char x[2]; \ | ||
36 | + }; \ | ||
37 | + template <member_type(T::*)> \ | ||
38 | + struct tester; \ | ||
39 | + template <typename U> \ | ||
40 | + static yes_type test(tester<&U::member_name>*); \ | ||
41 | + template <typename U> \ | ||
42 | + static no_type test(...); \ | ||
43 | + \ | ||
44 | + public: \ | ||
45 | + static const bool value = (sizeof(test<T>(0)) == sizeof(yes_type)); \ | ||
46 | + }; | ||
47 | + | ||
48 | +#define DEFINE_HAS_MEMBER(member_name) \ | ||
49 | + template <typename T> \ | ||
50 | + class has_##member_name { \ | ||
51 | + private: \ | ||
52 | + struct yes_type { \ | ||
53 | + char x[1]; \ | ||
54 | + }; \ | ||
55 | + struct no_type { \ | ||
56 | + char x[2]; \ | ||
57 | + }; \ | ||
58 | + template <int> \ | ||
59 | + struct tester; \ | ||
60 | + template <typename U> \ | ||
61 | + static yes_type test(tester<sizeof(&U::member_name)>*); \ | ||
62 | + template <typename U> \ | ||
63 | + static no_type test(...); \ | ||
64 | + \ | ||
65 | + public: \ | ||
66 | + static const bool value = (sizeof(test<T>(0)) == sizeof(yes_type)); \ | ||
67 | + }; | ||
68 | + | ||
69 | +#endif |
1 | +// Tencent is pleased to support the open source community by making Mars available. | ||
2 | +// Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. | ||
3 | + | ||
4 | +// Licensed under the MIT License (the "License"); you may not use this file except in | ||
5 | +// compliance with the License. You may obtain a copy of the License at | ||
6 | +// http://opensource.org/licenses/MIT | ||
7 | + | ||
8 | +// Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
9 | +// distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
10 | +// either express or implied. See the License for the specific language governing permissions and | ||
11 | +// limitations under the License. | ||
12 | + | ||
13 | +/* | ||
14 | + * HttpRequest.h | ||
15 | + * | ||
16 | + * Created on: 2013-12-5 | ||
17 | + * Author: yerungui | ||
18 | + */ | ||
19 | + | ||
20 | +#ifndef HTTP_H_ | ||
21 | +#define HTTP_H_ | ||
22 | + | ||
23 | +#include <list> | ||
24 | +#include <map> | ||
25 | +#include <string> | ||
26 | + | ||
27 | +#include "autobuffer.h" | ||
28 | + | ||
29 | +namespace http { | ||
30 | + | ||
31 | +struct less { | ||
32 | + bool operator()(const std::string& __x, const std::string& __y) const; | ||
33 | +}; | ||
34 | + | ||
35 | +enum THttpVersion { | ||
36 | + kVersion_0_9, | ||
37 | + kVersion_1_0, | ||
38 | + kVersion_1_1, | ||
39 | + kVersion_2_0, | ||
40 | + kVersion_Unknow, | ||
41 | +}; | ||
42 | + | ||
43 | +const char* const kHttpVersionString[] = { | ||
44 | + "HTTP/0.9", | ||
45 | + "HTTP/1.0", | ||
46 | + "HTTP/1.1", | ||
47 | + "HTTP/2", | ||
48 | + "version_unknown", | ||
49 | +}; | ||
50 | + | ||
51 | +enum TCsMode { | ||
52 | + kRequest, | ||
53 | + kRespond, | ||
54 | +}; | ||
55 | + | ||
56 | +class RequestLine { | ||
57 | + public: | ||
58 | + enum THttpMethod { | ||
59 | + kUnknown = 0, | ||
60 | + kGet, | ||
61 | + kPost, | ||
62 | + kOptions, | ||
63 | + kHead, | ||
64 | + kPut, | ||
65 | + kDelete, | ||
66 | + kTrace, | ||
67 | + kConnect, | ||
68 | + kMax, | ||
69 | + }; | ||
70 | + | ||
71 | + static const char* const kHttpMethodString[kMax]; | ||
72 | + | ||
73 | + public: | ||
74 | + RequestLine(); | ||
75 | + RequestLine(THttpMethod _httpMethod, const char* _url, THttpVersion _httpVersion); | ||
76 | + // RequestLine(const RequestLine&); | ||
77 | + // RequestLine& operator=(const RequestLine&); | ||
78 | + | ||
79 | + public: | ||
80 | + void Method(THttpMethod _method); | ||
81 | + THttpMethod Method() const; | ||
82 | + | ||
83 | + void Version(THttpVersion _version); | ||
84 | + THttpVersion Version() const; | ||
85 | + | ||
86 | + void Url(const std::string& _url); | ||
87 | + std::string Url() const; | ||
88 | + | ||
89 | + std::string ToString() const; | ||
90 | + bool FromString(const std::string& _requestline); | ||
91 | + | ||
92 | + private: | ||
93 | + THttpMethod http_method_; | ||
94 | + std::string req_url_; | ||
95 | + THttpVersion http_version_; | ||
96 | +}; | ||
97 | + | ||
98 | +class StatusLine { | ||
99 | + public: | ||
100 | + StatusLine(); | ||
101 | + StatusLine(THttpVersion _httpversion, int _statuscode, const std::string& _reasonphrase); | ||
102 | + // StatusLine(const StatusLine&); | ||
103 | + // StatusLine& operator=(const StatusLine&); | ||
104 | + | ||
105 | + public: | ||
106 | + void Version(THttpVersion _version); | ||
107 | + THttpVersion Version() const; | ||
108 | + | ||
109 | + void StatusCode(int _statuscode); | ||
110 | + int StatusCode() const; | ||
111 | + | ||
112 | + void ReasonPhrase(const std::string& _reasonphrase); | ||
113 | + std::string ReasonPhrase() const; | ||
114 | + | ||
115 | + std::string ToString() const; | ||
116 | + bool FromString(const std::string& _statusline); | ||
117 | + | ||
118 | + private: | ||
119 | + THttpVersion http_version_; | ||
120 | + int statuscode_; | ||
121 | + std::string reason_phrase_; | ||
122 | +}; | ||
123 | + | ||
124 | +class HeaderFields { | ||
125 | + public: | ||
126 | + // HeaderFields(const HeaderFields&); | ||
127 | + // HeaderFields& operator=(const HeaderFields&); | ||
128 | + | ||
129 | + public: | ||
130 | + static std::pair<const std::string, std::string> MakeContentLength(uint64_t _len); | ||
131 | + static std::pair<const std::string, std::string> MakeTransferEncodingChunked(); | ||
132 | + static std::pair<const std::string, std::string> MakeConnectionClose(); | ||
133 | + static std::pair<const std::string, std::string> MakeConnectionKeepalive(); | ||
134 | + static std::pair<const std::string, std::string> MakeAcceptAll(); | ||
135 | + static std::pair<const std::string, std::string> MakeAcceptEncodingDefalte(); | ||
136 | + static std::pair<const std::string, std::string> MakeAcceptEncodingGzip(); | ||
137 | + static std::pair<const std::string, std::string> MakeCacheControlNoCache(); | ||
138 | + static std::pair<const std::string, std::string> MakeContentTypeOctetStream(); | ||
139 | + | ||
140 | + static const char* const KStringHost; | ||
141 | + static const char* const KStringAccept; | ||
142 | + static const char* const KStringUserAgent; | ||
143 | + static const char* const KStringCacheControl; | ||
144 | + static const char* const KStringConnection; | ||
145 | + static const char* const kStringProxyConnection; | ||
146 | + static const char* const kStringProxyAuthorization; | ||
147 | + static const char* const KStringContentType; | ||
148 | + static const char* const KStringContentLength; | ||
149 | + static const char* const KStringTransferEncoding; | ||
150 | + static const char* const kStringContentEncoding; | ||
151 | + static const char* const KStringAcceptEncoding; | ||
152 | + static const char* const KStringContentRange; | ||
153 | + static const char* const KStringMicroMessenger; | ||
154 | + static const char* const KStringRange; | ||
155 | + static const char* const KStringLocation; | ||
156 | + static const char* const KStringReferer; | ||
157 | + static const char* const kStringServer; | ||
158 | + static const char* const KStringKeepalive; | ||
159 | + | ||
160 | + void HeaderFiled(const char* _name, const char* _value); | ||
161 | + void HeaderFiled(const std::pair<const std::string, std::string>& _headerfield); | ||
162 | + void InsertOrUpdate(const std::pair<const std::string, std::string>& _headerfield); | ||
163 | + void Manipulate(const std::pair<const std::string, std::string>& _headerfield); | ||
164 | + const char* HeaderField(const char* _key) const; | ||
165 | + void CopyFrom(const HeaderFields& rhs); | ||
166 | + std::map<const std::string, std::string, less>& GetHeaders() { | ||
167 | + return headers_; | ||
168 | + } | ||
169 | + std::list<std::pair<const std::string, const std::string>> GetAsList() const; | ||
170 | + | ||
171 | + bool IsTransferEncodingChunked() const; | ||
172 | + bool IsConnectionClose() const; | ||
173 | + bool IsConnectionKeepAlive() const; | ||
174 | + uint64_t ContentLength() const; | ||
175 | + uint32_t KeepAliveTimeout() const; | ||
176 | + | ||
177 | + bool Range(long& _start, long& _end) const; | ||
178 | + bool ContentRange(uint64_t* start, uint64_t* end, uint64_t* total) const; | ||
179 | + static bool ContentRange(const std::string& line, uint64_t* start, uint64_t* end, uint64_t* total); | ||
180 | + | ||
181 | + const std::string ToString() const; | ||
182 | + | ||
183 | + private: | ||
184 | + std::map<const std::string, std::string, less> headers_; | ||
185 | +}; | ||
186 | + | ||
187 | +class IBlockBodyProvider { | ||
188 | + public: | ||
189 | + virtual ~IBlockBodyProvider() { | ||
190 | + } | ||
191 | + | ||
192 | + virtual bool Data(AutoBuffer& _body) = 0; | ||
193 | + virtual bool FillData(AutoBuffer& _body) = 0; | ||
194 | + virtual size_t Length() const = 0; | ||
195 | +}; | ||
196 | + | ||
197 | +class BufferBodyProvider : public IBlockBodyProvider { | ||
198 | + public: | ||
199 | + bool Data(AutoBuffer& _body) { | ||
200 | + if (!_body.Ptr()) | ||
201 | + return false; | ||
202 | + | ||
203 | + buffer_.Write(_body.Ptr(), _body.Length()); | ||
204 | + _body.Reset(); | ||
205 | + return true; | ||
206 | + } | ||
207 | + bool FillData(AutoBuffer& _body) { | ||
208 | + if (!buffer_.Ptr()) | ||
209 | + return false; | ||
210 | + | ||
211 | + _body.Write(buffer_.Ptr(), buffer_.Length()); | ||
212 | + buffer_.Reset(); | ||
213 | + return true; | ||
214 | + } | ||
215 | + size_t Length() const { | ||
216 | + return buffer_.Length(); | ||
217 | + } | ||
218 | + AutoBuffer& Buffer() { | ||
219 | + return buffer_; | ||
220 | + } | ||
221 | + | ||
222 | + private: | ||
223 | + AutoBuffer buffer_; | ||
224 | +}; | ||
225 | + | ||
226 | +class IStreamBodyProvider { | ||
227 | + public: | ||
228 | + virtual ~IStreamBodyProvider() { | ||
229 | + } | ||
230 | + | ||
231 | + virtual bool HaveData() const = 0; | ||
232 | + virtual bool Data(AutoBuffer& _body) = 0; | ||
233 | + | ||
234 | + virtual bool Eof() const = 0; | ||
235 | + const char* EofData(); | ||
236 | + | ||
237 | + protected: | ||
238 | + static void AppendHeader(AutoBuffer& _body, size_t _length); | ||
239 | + static void AppendTail(AutoBuffer& _body); | ||
240 | +}; | ||
241 | + | ||
242 | +class Builder { | ||
243 | + public: | ||
244 | + Builder(TCsMode _csmode); | ||
245 | + ~Builder(); | ||
246 | + | ||
247 | + private: | ||
248 | + Builder(const Builder&); | ||
249 | + Builder& operator=(const Builder&); | ||
250 | + | ||
251 | + public: | ||
252 | + RequestLine& Request(); | ||
253 | + StatusLine& Status(); | ||
254 | + const RequestLine& Request() const; | ||
255 | + const StatusLine& Status() const; | ||
256 | + | ||
257 | + HeaderFields& Fields(); | ||
258 | + const HeaderFields& Fields() const; | ||
259 | + | ||
260 | + void BlockBody(IBlockBodyProvider* _body, bool _manage); | ||
261 | + void StreamBody(IStreamBodyProvider* _body, bool _manage); | ||
262 | + IBlockBodyProvider* BlockBody(); | ||
263 | + IStreamBodyProvider* StreamBody(); | ||
264 | + const IBlockBodyProvider* BlockBody() const; | ||
265 | + const IStreamBodyProvider* StreamBody() const; | ||
266 | + | ||
267 | + bool HeaderToBuffer(AutoBuffer& _header); | ||
268 | + bool HttpToBuffer(AutoBuffer& _http); | ||
269 | + | ||
270 | + private: | ||
271 | + TCsMode csmode_; | ||
272 | + | ||
273 | + StatusLine statusline_; | ||
274 | + RequestLine requestline_; | ||
275 | + | ||
276 | + HeaderFields headfields_; | ||
277 | + | ||
278 | + IBlockBodyProvider* blockbody_; | ||
279 | + IStreamBodyProvider* streambody_; | ||
280 | + bool is_manage_body_; | ||
281 | +}; | ||
282 | + | ||
283 | +class BodyReceiver { | ||
284 | + public: | ||
285 | + BodyReceiver() : total_length_(0) { | ||
286 | + } | ||
287 | + virtual ~BodyReceiver() { | ||
288 | + } | ||
289 | + | ||
290 | + virtual void AppendData(const void* _body, size_t _length) { | ||
291 | + total_length_ += _length; | ||
292 | + } | ||
293 | + virtual void EndData() { | ||
294 | + } | ||
295 | + size_t Length() const { | ||
296 | + return total_length_; | ||
297 | + } | ||
298 | + | ||
299 | + private: | ||
300 | + size_t total_length_; | ||
301 | +}; | ||
302 | + | ||
303 | +class MemoryBodyReceiver : public BodyReceiver { | ||
304 | + public: | ||
305 | + MemoryBodyReceiver(AutoBuffer& _buf) : body_(_buf) { | ||
306 | + } | ||
307 | + virtual void AppendData(const void* _body, size_t _length) { | ||
308 | + BodyReceiver::AppendData(_body, _length); | ||
309 | + body_.Write(_body, _length); | ||
310 | + } | ||
311 | + virtual void EndData() { | ||
312 | + } | ||
313 | + | ||
314 | + private: | ||
315 | + AutoBuffer& body_; | ||
316 | +}; | ||
317 | + | ||
318 | +class Parser { | ||
319 | + public: | ||
320 | + enum TRecvStatus { | ||
321 | + kStart, | ||
322 | + kFirstLine, | ||
323 | + kFirstLineError, | ||
324 | + kHeaderFields, | ||
325 | + kHeaderFieldsError, | ||
326 | + kBody, | ||
327 | + kBodyError, | ||
328 | + kEnd, | ||
329 | + }; | ||
330 | + | ||
331 | + public: | ||
332 | + Parser(BodyReceiver* _body = new BodyReceiver(), bool _manage = true); | ||
333 | + ~Parser(); | ||
334 | + | ||
335 | + private: | ||
336 | + Parser(const Parser&); | ||
337 | + Parser& operator=(const Parser&); | ||
338 | + | ||
339 | + public: | ||
340 | + TRecvStatus Recv(const void* _buffer, | ||
341 | + size_t _length, | ||
342 | + size_t* consumed_bytes = nullptr, | ||
343 | + bool only_parse_header = false); | ||
344 | + TRecvStatus Recv(AutoBuffer& _recv_buffer); | ||
345 | + TRecvStatus RecvStatus() const; | ||
346 | + | ||
347 | + TCsMode CsMode() const; | ||
348 | + bool FirstLineReady() const; | ||
349 | + const RequestLine& Request() const; | ||
350 | + const StatusLine& Status() const; | ||
351 | + const AutoBuffer& HeaderBuffer() const; | ||
352 | + | ||
353 | + bool FieldsReady() const; | ||
354 | + HeaderFields& Fields(); | ||
355 | + const HeaderFields& Fields() const; | ||
356 | + size_t FirstLineLength() const; | ||
357 | + size_t HeaderLength() const; | ||
358 | + | ||
359 | + bool BodyReady() const; | ||
360 | + bool BodyRecving() const; | ||
361 | + BodyReceiver& Body(); | ||
362 | + const BodyReceiver& Body() const; | ||
363 | + | ||
364 | + bool Error() const; | ||
365 | + bool Success() const; | ||
366 | + | ||
367 | + private: | ||
368 | + TRecvStatus recvstatus_; | ||
369 | + AutoBuffer recvbuf_; | ||
370 | + AutoBuffer headerbuf_; | ||
371 | + bool response_header_ready_; | ||
372 | + TCsMode csmode_; | ||
373 | + | ||
374 | + StatusLine statusline_; | ||
375 | + RequestLine requestline_; | ||
376 | + | ||
377 | + HeaderFields headfields_; | ||
378 | + | ||
379 | + BodyReceiver* bodyreceiver_; | ||
380 | + bool is_manage_body_; | ||
381 | + size_t firstlinelength_; | ||
382 | + size_t headerlength_; | ||
383 | +}; | ||
384 | + | ||
385 | +// void testChunk(); | ||
386 | + | ||
387 | +} /* namespace http */ | ||
388 | +#endif /* HTTPREQUEST_H_ */ |
1 | +// Tencent is pleased to support the open source community by making Mars available. | ||
2 | +// Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. | ||
3 | + | ||
4 | +// Licensed under the MIT License (the "License"); you may not use this file except in | ||
5 | +// compliance with the License. You may obtain a copy of the License at | ||
6 | +// http://opensource.org/licenses/MIT | ||
7 | + | ||
8 | +// Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
9 | +// distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
10 | +// either express or implied. See the License for the specific language governing permissions and | ||
11 | +// limitations under the License. | ||
12 | + | ||
13 | +// | ||
14 | +// IPv6_only.hpp | ||
15 | +// comm | ||
16 | +// | ||
17 | +// Created by yerungui on 16/1/14. | ||
18 | +// | ||
19 | + | ||
20 | +#ifndef __ip_type__ | ||
21 | +#define __ip_type__ | ||
22 | + | ||
23 | +#ifdef __cplusplus | ||
24 | +extern "C" { | ||
25 | +#endif | ||
26 | + | ||
27 | +enum TLocalIPStack { | ||
28 | + ELocalIPStack_None = 0, | ||
29 | + ELocalIPStack_IPv4 = 1, | ||
30 | + ELocalIPStack_IPv6 = 2, | ||
31 | + ELocalIPStack_Dual = 3, | ||
32 | +}; | ||
33 | + | ||
34 | +const char* const TLocalIPStackStr[] = { | ||
35 | + "ELocalIPStack_None", | ||
36 | + "ELocalIPStack_IPv4", | ||
37 | + "ELocalIPStack_IPv6", | ||
38 | + "ELocalIPStack_Dual", | ||
39 | +}; | ||
40 | + | ||
41 | +TLocalIPStack local_ipstack_detect(); | ||
42 | + | ||
43 | +#ifdef __cplusplus | ||
44 | +} | ||
45 | +#endif | ||
46 | + | ||
47 | +#include <string> | ||
48 | +TLocalIPStack local_ipstack_detect_log(std::string& _log); | ||
49 | + | ||
50 | +#endif /* __ip_type__ */ |
1 | +// Tencent is pleased to support the open source community by making Mars available. | ||
2 | +// Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. | ||
3 | + | ||
4 | +// Licensed under the MIT License (the "License"); you may not use this file except in | ||
5 | +// compliance with the License. You may obtain a copy of the License at | ||
6 | +// http://opensource.org/licenses/MIT | ||
7 | + | ||
8 | +// Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
9 | +// distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
10 | +// either express or implied. See the License for the specific language governing permissions and | ||
11 | +// limitations under the License. | ||
12 | + | ||
13 | +/* | ||
14 | + * nat64_prefix_util.h | ||
15 | + * | ||
16 | + * Created on: 2016年6月22日 | ||
17 | + * Author: wutianqiang | ||
18 | + */ | ||
19 | + | ||
20 | +#ifndef SOCKET_NAT64_PREFIX_UTIL_H_ | ||
21 | +#define SOCKET_NAT64_PREFIX_UTIL_H_ | ||
22 | + | ||
23 | +/* | ||
24 | + * WARNING:All functions below may be blocked when called first time, please don't use these functions in main thread. | ||
25 | + * if current network is not ipv6-only, these fuction all will return false | ||
26 | + * */ | ||
27 | +#include <string> | ||
28 | + | ||
29 | +#ifdef __APPLE__ | ||
30 | +#ifndef s6_addr16 | ||
31 | +#define s6_addr16 __u6_addr.__u6_addr16 | ||
32 | +#endif | ||
33 | + | ||
34 | +#ifndef s6_addr32 | ||
35 | +#define s6_addr32 __u6_addr.__u6_addr32 | ||
36 | +#endif | ||
37 | +#endif | ||
38 | +/* | ||
39 | + * param: _nat64_prefix, return the nat64 prefix, using a string | ||
40 | + * return: if return false, then _nat64_prfix is empty string. | ||
41 | + * */ | ||
42 | +bool GetNetworkNat64Prefix(std::string& _nat64_prefix); | ||
43 | + | ||
44 | +/* | ||
45 | + * param: _nat64_prefix_in6, return the nat64 prefix, using struct in6_addr. | ||
46 | + * _nat64_prefix_in6.s6_addr32[0~2](12 Bytes) contain the nat64 prefix | ||
47 | + * return: if return false, _nat64_prefix_in6 will not change. | ||
48 | + * */ | ||
49 | +bool GetNetworkNat64Prefix(struct in6_addr& _nat64_prefix_in6); | ||
50 | + | ||
51 | +/* | ||
52 | + * param: _v4_ip:the input v4 ip, _nat64_v6_ip the output v6 ip, which embeded _v4_ip with format RFC6052 | ||
53 | + * return: if return false(MAY BE INVALID _v4_ip), _nat64_v6_ip will not change. | ||
54 | + * */ | ||
55 | +bool ConvertV4toNat64V6(const std::string& _v4_ip, std::string& _nat64_v6_ip); | ||
56 | + | ||
57 | +/* | ||
58 | + * param: _v4_addr input v4 addr, _v6_addr the output v6 addr, which embeded _v4_addr with format RFC6052 | ||
59 | + * return: if return false, _v6_addr will not change. | ||
60 | + * */ | ||
61 | +bool ConvertV4toNat64V6(const struct in_addr& _v4_addr, struct in6_addr& _v6_addr); | ||
62 | +#endif /* SOCKET_NAT64_PREFIX_UTIL_H_ */ |
1 | +// Tencent is pleased to support the open source community by making Mars available. | ||
2 | +// Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. | ||
3 | + | ||
4 | +// Licensed under the MIT License (the "License"); you may not use this file except in | ||
5 | +// compliance with the License. You may obtain a copy of the License at | ||
6 | +// http://opensource.org/licenses/MIT | ||
7 | + | ||
8 | +// Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
9 | +// distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
10 | +// either express or implied. See the License for the specific language governing permissions and | ||
11 | +// limitations under the License. | ||
12 | + | ||
13 | +// | ||
14 | +// prjdef.h | ||
15 | +// comm | ||
16 | +// | ||
17 | +// Created by yerungui on 16/4/26. | ||
18 | +// Copyright © 2016年 Tencent. All rights reserved. | ||
19 | +// | ||
20 | + | ||
21 | +#ifndef prjdef_h | ||
22 | +#define prjdef_h | ||
23 | + | ||
24 | +#ifdef _WIN32 | ||
25 | +#include "windows/projdef.h" | ||
26 | +#endif | ||
27 | + | ||
28 | +#endif /* prjdef_h */ |
1 | +// Tencent is pleased to support the open source community by making Mars available. | ||
2 | +// Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. | ||
3 | + | ||
4 | +// Licensed under the MIT License (the "License"); you may not use this file except in | ||
5 | +// compliance with the License. You may obtain a copy of the License at | ||
6 | +// http://opensource.org/licenses/MIT | ||
7 | + | ||
8 | +// Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
9 | +// distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
10 | +// either express or implied. See the License for the specific language governing permissions and | ||
11 | +// limitations under the License. | ||
12 | + | ||
13 | +// | ||
14 | +// scope_autoreleasepool.h | ||
15 | +// MicroMessenger | ||
16 | +// | ||
17 | +// Created by yerungui on 12-11-30. | ||
18 | +// | ||
19 | + | ||
20 | +#ifndef __MicroMessenger__scope_autoreleasepool__ | ||
21 | +#define __MicroMessenger__scope_autoreleasepool__ | ||
22 | + | ||
23 | +class Scope_AutoReleasePool { | ||
24 | + public: | ||
25 | + Scope_AutoReleasePool(); | ||
26 | + ~Scope_AutoReleasePool(); | ||
27 | + | ||
28 | + private: | ||
29 | + Scope_AutoReleasePool(const Scope_AutoReleasePool&); | ||
30 | + Scope_AutoReleasePool& operator=(const Scope_AutoReleasePool&); | ||
31 | + | ||
32 | + private: | ||
33 | + id m_pool; | ||
34 | +}; | ||
35 | + | ||
36 | +#define SCOPE_POOL() Scope_AutoReleasePool __pool__##__LINE__ | ||
37 | + | ||
38 | +#endif /* defined(__MicroMessenger__scope_autoreleasepool__) */ |
1 | +// Tencent is pleased to support the open source community by making Mars available. | ||
2 | +// Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. | ||
3 | + | ||
4 | +// Licensed under the MIT License (the "License"); you may not use this file except in | ||
5 | +// compliance with the License. You may obtain a copy of the License at | ||
6 | +// http://opensource.org/licenses/MIT | ||
7 | + | ||
8 | +// Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
9 | +// distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
10 | +// either express or implied. See the License for the specific language governing permissions and | ||
11 | +// limitations under the License. | ||
12 | + | ||
13 | +/* | ||
14 | + Author : yerungui | ||
15 | + Created on : 2016-04-14 | ||
16 | + */ | ||
17 | + | ||
18 | +#ifndef STRING_CAST_H_ | ||
19 | +#define STRING_CAST_H_ | ||
20 | + | ||
21 | +#include <stdint.h> | ||
22 | +#include <stdio.h> | ||
23 | +#include <stdlib.h> | ||
24 | + | ||
25 | +#ifndef _WIN32 | ||
26 | +#define __STDC_FORMAT_MACROS | ||
27 | +#include <strings.h> | ||
28 | +#else | ||
29 | +#include "projdef.h" | ||
30 | +#endif | ||
31 | +#include <inttypes.h> | ||
32 | +#include <string.h> | ||
33 | + | ||
34 | +#include <limits> | ||
35 | +#include <string> | ||
36 | + | ||
37 | +#include "strutil.h" | ||
38 | + | ||
39 | +template <typename T> | ||
40 | +char* string_cast_itoa(const T& value, char* result, uint8_t base = 10, bool upper_case = true) { | ||
41 | + if (!(2 <= base && base <= 36)) { | ||
42 | +#if defined(_WIN32) | ||
43 | + strcpy_s(result, strlen(result), "itoa err"); | ||
44 | +#else | ||
45 | + strcpy(result, "itoa err"); | ||
46 | +#endif | ||
47 | + return result; | ||
48 | + } | ||
49 | + | ||
50 | + char *ptr_right = result, *ptr_left = result; | ||
51 | + T tmp_value = value; | ||
52 | + const char* num_mapping; | ||
53 | + | ||
54 | + if (upper_case) | ||
55 | + num_mapping = "ZYXWVUTSRQPONMLKJIHGFEDCBA9876543210123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
56 | + else | ||
57 | + num_mapping = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"; | ||
58 | + | ||
59 | + do { | ||
60 | + T quotient = tmp_value / base; | ||
61 | + *(ptr_right++) = num_mapping[35 + tmp_value - quotient * base]; | ||
62 | + tmp_value = quotient; | ||
63 | + } while (tmp_value); | ||
64 | + | ||
65 | +#ifdef __GNUC__ | ||
66 | +#pragma GCC diagnostic push | ||
67 | +#pragma GCC diagnostic ignored "-Wtype-limits" | ||
68 | +#endif | ||
69 | + if (value < 0) | ||
70 | + *(ptr_right++) = '-'; | ||
71 | +#ifdef __GNUC__ | ||
72 | +#pragma GCC diagnostic pop | ||
73 | +#endif | ||
74 | + | ||
75 | + *(ptr_right--) = '\0'; | ||
76 | + | ||
77 | + while (ptr_left < ptr_right) { | ||
78 | + char tmp_char = *ptr_right; | ||
79 | + *(ptr_right--) = *ptr_left; | ||
80 | + *(ptr_left++) = tmp_char; | ||
81 | + } | ||
82 | + return result; | ||
83 | +} | ||
84 | + | ||
85 | +#define string_cast_hex(value) string_cast(value, 16) | ||
86 | +#define string_cast_oct(value) string_cast(value, 8) | ||
87 | + | ||
88 | +class string_cast { | ||
89 | + public: | ||
90 | + string_cast(char _value) : value_(NULL) { | ||
91 | + value_cache_[0] = _value; | ||
92 | + value_cache_[1] = '\0'; | ||
93 | + value_ = value_cache_; | ||
94 | + } | ||
95 | + | ||
96 | + string_cast(int _value, uint8_t base = 10) : value_(NULL) { | ||
97 | + string_cast_itoa(_value, value_cache_, base); | ||
98 | + value_ = value_cache_; | ||
99 | + } | ||
100 | + string_cast(long _value, uint8_t base = 10) : value_(NULL) { | ||
101 | + string_cast_itoa(_value, value_cache_, base); | ||
102 | + value_ = value_cache_; | ||
103 | + } | ||
104 | + string_cast(long long _value, uint8_t base = 10) : value_(NULL) { | ||
105 | + string_cast_itoa(_value, value_cache_, base); | ||
106 | + value_ = value_cache_; | ||
107 | + } | ||
108 | + | ||
109 | + string_cast(unsigned int _value, uint8_t base = 10) : value_(NULL) { | ||
110 | + string_cast_itoa(_value, value_cache_, base); | ||
111 | + value_ = value_cache_; | ||
112 | + } | ||
113 | + string_cast(unsigned long _value, uint8_t base = 10) : value_(NULL) { | ||
114 | + string_cast_itoa(_value, value_cache_, base); | ||
115 | + value_ = value_cache_; | ||
116 | + } | ||
117 | + string_cast(unsigned long long _value, uint8_t base = 10) : value_(NULL) { | ||
118 | + string_cast_itoa(_value, value_cache_, base); | ||
119 | + value_ = value_cache_; | ||
120 | + } | ||
121 | + | ||
122 | + string_cast(float _value) : value_(NULL) { | ||
123 | + snprintf(value_cache_, sizeof(value_cache_), "%.2f", _value); | ||
124 | + value_ = value_cache_; | ||
125 | + } | ||
126 | + string_cast(double _value) : value_(NULL) { | ||
127 | + snprintf(value_cache_, sizeof(value_cache_), "%.2f", _value); | ||
128 | + value_ = value_cache_; | ||
129 | + } | ||
130 | + string_cast(long double _value) : value_(NULL) { | ||
131 | + snprintf(value_cache_, sizeof(value_cache_), "%.2Lf", _value); | ||
132 | + value_ = value_cache_; | ||
133 | + } | ||
134 | + | ||
135 | + string_cast(bool _value) : value_(NULL) { | ||
136 | + if (_value) | ||
137 | + value_ = "true"; | ||
138 | + else | ||
139 | + value_ = "false"; | ||
140 | + value_cache_[0] = '\0'; | ||
141 | + } | ||
142 | + string_cast(const void* _value) : value_(NULL) { | ||
143 | + value_cache_[0] = '0'; | ||
144 | + value_cache_[1] = 'x'; | ||
145 | + string_cast_itoa((uintptr_t)_value, value_cache_ + 2, 16); | ||
146 | + value_ = value_cache_; | ||
147 | + } | ||
148 | + | ||
149 | + string_cast(const char* _value) : value_(NULL) { | ||
150 | + value_ = (const char*)_value; | ||
151 | + value_cache_[0] = '\0'; | ||
152 | + } | ||
153 | + string_cast(const std::string& _value) : value_(NULL) { | ||
154 | + value_ = _value.c_str(); | ||
155 | + value_cache_[0] = '\0'; | ||
156 | + } | ||
157 | + | ||
158 | + const char* str() const { | ||
159 | + return value_; | ||
160 | + } | ||
161 | + operator const char*() const { | ||
162 | + return value_; | ||
163 | + } | ||
164 | + | ||
165 | + private: | ||
166 | + string_cast(const string_cast&); | ||
167 | + string_cast& operator=(const string_cast&); | ||
168 | + | ||
169 | + private: | ||
170 | + const char* value_; | ||
171 | + char value_cache_[65]; | ||
172 | +}; | ||
173 | + | ||
174 | +namespace detail { | ||
175 | + | ||
176 | +template <typename T, int base = 0> | ||
177 | +class __signed_number_cast { | ||
178 | + public: | ||
179 | + __signed_number_cast(const char* _str) : value_(0), vaild_(false) { | ||
180 | + if (_str == NULL) | ||
181 | + return; | ||
182 | + | ||
183 | + char* end = NULL; | ||
184 | + | ||
185 | + vaild_ = true; | ||
186 | + value_ = strtoimax(_str, &end, base); | ||
187 | + | ||
188 | + if (_str == end) { | ||
189 | + vaild_ = false; | ||
190 | + return; | ||
191 | + } | ||
192 | + | ||
193 | + if (value_ < (std::numeric_limits<T>::min)()) { | ||
194 | + value_ = (std::numeric_limits<T>::min)(); | ||
195 | + vaild_ = false; | ||
196 | + return; | ||
197 | + } | ||
198 | + if ((std::numeric_limits<T>::max)() < value_) { | ||
199 | + value_ = (std::numeric_limits<T>::max)(); | ||
200 | + vaild_ = false; | ||
201 | + return; | ||
202 | + } | ||
203 | + } | ||
204 | + | ||
205 | + operator T() const { | ||
206 | + return static_cast<T>(value_); | ||
207 | + } | ||
208 | + bool valid() const { | ||
209 | + return vaild_; | ||
210 | + } | ||
211 | + | ||
212 | + private: | ||
213 | + intmax_t value_; | ||
214 | + bool vaild_; | ||
215 | +}; | ||
216 | + | ||
217 | +template <typename T, int base = 0> | ||
218 | +class __unsigned_number_cast { | ||
219 | + public: | ||
220 | + __unsigned_number_cast(const char* _str) : value_(0), vaild_(false) { | ||
221 | + if (_str == NULL) | ||
222 | + return; | ||
223 | + | ||
224 | + char* end = NULL; | ||
225 | + | ||
226 | + vaild_ = true; | ||
227 | + value_ = strtoumax(_str, &end, base); | ||
228 | + | ||
229 | + if (_str == end) { | ||
230 | + vaild_ = false; | ||
231 | + return; | ||
232 | + } | ||
233 | + if (value_ < (std::numeric_limits<T>::min)()) { | ||
234 | + value_ = (std::numeric_limits<T>::min)(); | ||
235 | + vaild_ = false; | ||
236 | + return; | ||
237 | + } | ||
238 | + if ((std::numeric_limits<T>::max)() < value_) { | ||
239 | + value_ = (std::numeric_limits<T>::max)(); | ||
240 | + vaild_ = false; | ||
241 | + return; | ||
242 | + } | ||
243 | + } | ||
244 | + | ||
245 | + operator T() const { | ||
246 | + return static_cast<T>(value_); | ||
247 | + } | ||
248 | + bool valid() const { | ||
249 | + return vaild_; | ||
250 | + } | ||
251 | + | ||
252 | + private: | ||
253 | + uintmax_t value_; | ||
254 | + bool vaild_; | ||
255 | +}; | ||
256 | + | ||
257 | +template <typename T> | ||
258 | +class __float_number_cast { | ||
259 | + public: | ||
260 | + __float_number_cast(const char* _str) : value_(0), vaild_(false) { | ||
261 | + if (_str == NULL) | ||
262 | + return; | ||
263 | + | ||
264 | + char* end = NULL; | ||
265 | + | ||
266 | + vaild_ = true; | ||
267 | + value_ = strtod(_str, &end); | ||
268 | + | ||
269 | + if (_str == end) { | ||
270 | + vaild_ = false; | ||
271 | + } | ||
272 | + } | ||
273 | + | ||
274 | + operator T() const { | ||
275 | + return static_cast<T>(value_); | ||
276 | + } | ||
277 | + bool valid() const { | ||
278 | + return vaild_; | ||
279 | + } | ||
280 | + | ||
281 | + private: | ||
282 | + double value_; | ||
283 | + bool vaild_; | ||
284 | +}; | ||
285 | +} // namespace detail | ||
286 | + | ||
287 | +template <typename T> | ||
288 | +class number_cast {}; | ||
289 | + | ||
290 | +template <> | ||
291 | +class number_cast<int8_t> : public detail::__signed_number_cast<int8_t> { | ||
292 | + public: | ||
293 | + number_cast(const char* _str) : __signed_number_cast(_str){}; | ||
294 | +}; | ||
295 | +template <> | ||
296 | +class number_cast<int16_t> : public detail::__signed_number_cast<int16_t> { | ||
297 | + public: | ||
298 | + number_cast(const char* _str) : __signed_number_cast(_str){}; | ||
299 | +}; | ||
300 | +template <> | ||
301 | +class number_cast<int32_t> : public detail::__signed_number_cast<int32_t> { | ||
302 | + public: | ||
303 | + number_cast(const char* _str) : __signed_number_cast(_str){}; | ||
304 | +}; | ||
305 | +template <> | ||
306 | +class number_cast<long> : public detail::__signed_number_cast<long> { | ||
307 | + public: | ||
308 | + number_cast(const char* _str) : __signed_number_cast(_str){}; | ||
309 | +}; | ||
310 | +template <> | ||
311 | +class number_cast<long long> : public detail::__signed_number_cast<long long> { | ||
312 | + public: | ||
313 | + number_cast(const char* _str) : __signed_number_cast(_str){}; | ||
314 | +}; | ||
315 | + | ||
316 | +template <> | ||
317 | +class number_cast<uint8_t> : public detail::__unsigned_number_cast<uint8_t> { | ||
318 | + public: | ||
319 | + number_cast(const char* _str) : __unsigned_number_cast(_str){}; | ||
320 | +}; | ||
321 | +template <> | ||
322 | +class number_cast<uint16_t> : public detail::__unsigned_number_cast<uint16_t> { | ||
323 | + public: | ||
324 | + number_cast(const char* _str) : __unsigned_number_cast(_str){}; | ||
325 | +}; | ||
326 | +template <> | ||
327 | +class number_cast<uint32_t> : public detail::__unsigned_number_cast<uint32_t> { | ||
328 | + public: | ||
329 | + number_cast(const char* _str) : __unsigned_number_cast(_str){}; | ||
330 | +}; | ||
331 | +template <> | ||
332 | +class number_cast<unsigned long> : public detail::__unsigned_number_cast<unsigned long> { | ||
333 | + public: | ||
334 | + number_cast(const char* _str) : __unsigned_number_cast(_str){}; | ||
335 | +}; | ||
336 | +template <> | ||
337 | +class number_cast<unsigned long long> : public detail::__unsigned_number_cast<unsigned long long> { | ||
338 | + public: | ||
339 | + number_cast(const char* _str) : __unsigned_number_cast(_str){}; | ||
340 | +}; | ||
341 | + | ||
342 | +template <> | ||
343 | +class number_cast<float> : public detail::__float_number_cast<float> { | ||
344 | + public: | ||
345 | + number_cast(const char* _str) : __float_number_cast(_str){}; | ||
346 | +}; | ||
347 | +template <> | ||
348 | +class number_cast<double> : public detail::__float_number_cast<double> { | ||
349 | + public: | ||
350 | + number_cast(const char* _str) : __float_number_cast(_str){}; | ||
351 | +}; | ||
352 | + | ||
353 | +template <> | ||
354 | +class number_cast<const char*> { | ||
355 | + public: | ||
356 | + number_cast(const char* _str) : value_(NULL), vaild_(false) { | ||
357 | + if (_str == NULL) | ||
358 | + return; | ||
359 | + | ||
360 | + value_ = _str; | ||
361 | + vaild_ = true; | ||
362 | + } | ||
363 | + | ||
364 | + operator const char*() const { | ||
365 | + return value_; | ||
366 | + } | ||
367 | + bool valid() const { | ||
368 | + return vaild_; | ||
369 | + } | ||
370 | + | ||
371 | + private: | ||
372 | + const char* value_; | ||
373 | + bool vaild_; | ||
374 | +}; | ||
375 | + | ||
376 | +template <> | ||
377 | +class number_cast<bool> { | ||
378 | + public: | ||
379 | + number_cast(const char* _str) : value_(false), vaild_(false) { | ||
380 | + if (_str == NULL) | ||
381 | + return; | ||
382 | + | ||
383 | + std::vector<std::string> vec_split; | ||
384 | + strutil::SplitToken(_str, strutil::default_delimiters<std::string>::value(), vec_split); | ||
385 | + | ||
386 | + if (vec_split.empty()) { | ||
387 | + return; | ||
388 | + } | ||
389 | + if (vec_split[0] == "1" || 0 == strcasecmp("true", vec_split[0].c_str())) { | ||
390 | + vaild_ = true; | ||
391 | + value_ = true; | ||
392 | + } | ||
393 | + if (vec_split[0] == "0" || 0 == strcasecmp("false", vec_split[0].c_str())) { | ||
394 | + vaild_ = true; | ||
395 | + value_ = false; | ||
396 | + } | ||
397 | + } | ||
398 | + | ||
399 | + operator bool() const { | ||
400 | + return value_; | ||
401 | + } | ||
402 | + bool valid() const { | ||
403 | + return vaild_; | ||
404 | + } | ||
405 | + | ||
406 | + private: | ||
407 | + bool value_; | ||
408 | + bool vaild_; | ||
409 | +}; | ||
410 | + | ||
411 | +#endif /* STRING_CAST_H_ */ |
1 | +// Tencent is pleased to support the open source community by making Mars available. | ||
2 | +// Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. | ||
3 | + | ||
4 | +// Licensed under the MIT License (the "License"); you may not use this file except in | ||
5 | +// compliance with the License. You may obtain a copy of the License at | ||
6 | +// http://opensource.org/licenses/MIT | ||
7 | + | ||
8 | +// Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
9 | +// distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
10 | +// either express or implied. See the License for the specific language governing permissions and | ||
11 | +// limitations under the License. | ||
12 | + | ||
13 | +//////////////////////////////////////////////////////////////////////////////// | ||
14 | +// @(#) strutil.h | ||
15 | +// Utilities for string | ||
16 | +// defined in namespace strutil | ||
17 | +// Support for Symbian | ||
18 | +// yerungui | ||
19 | +//////////////////////////////////////////////////////////////////////////////// | ||
20 | + | ||
21 | +#ifndef COMM_STRUTIL_H_ | ||
22 | +#define COMM_STRUTIL_H_ | ||
23 | + | ||
24 | +#include <string> | ||
25 | +#include <vector> | ||
26 | + | ||
27 | +// declaration | ||
28 | +namespace strutil { | ||
29 | +/////////////////////// string ///////////////////////////// | ||
30 | +std::string& URLEncode(const std::string& url, std::string& encodeUrl); | ||
31 | + | ||
32 | +std::string& TrimLeft(std::string& str); | ||
33 | +std::string& TrimRight(std::string& str); | ||
34 | +std::string& Trim(std::string& str); | ||
35 | + | ||
36 | +std::string& ToLower(std::string& str); | ||
37 | +std::string& ToUpper(std::string& str); | ||
38 | + | ||
39 | +bool StartsWith(const std::string& str, const std::string& substr); | ||
40 | +bool EndsWith(const std::string& str, const std::string& substr); | ||
41 | + | ||
42 | +std::vector<std::string>& SplitToken(const std::string& str, | ||
43 | + const std::string& delimiters, | ||
44 | + std::vector<std::string>& ss); | ||
45 | + | ||
46 | +// T1 is iterator, T2 is string or wstring | ||
47 | +template <typename T1, typename T2> | ||
48 | +bool MergeToken(const T1& begin, const T1& end, const T2& delimiter, T2& result); | ||
49 | +/////////////////////// wstring ///////////////////////////// | ||
50 | +std::wstring& TrimLeft(std::wstring& str); | ||
51 | +std::wstring& TrimRight(std::wstring& str); | ||
52 | +std::wstring& Trim(std::wstring& str); | ||
53 | + | ||
54 | +bool StartsWith(const std::wstring& str, const std::wstring& substr); | ||
55 | +bool EndsWith(const std::wstring& str, const std::wstring& substr); | ||
56 | + | ||
57 | +std::wstring& ToLower(std::wstring& str); | ||
58 | +std::wstring& ToUpper(std::wstring& str); | ||
59 | + | ||
60 | +#ifdef WIN32 | ||
61 | +std::wstring String2WString(const std::string& _src, unsigned int _cp); | ||
62 | +std::wstring UTF8String2Wstring(const std::string& _src); | ||
63 | +#endif | ||
64 | +std::vector<std::wstring>& SplitToken(const std::wstring& str, | ||
65 | + const std::wstring& delimiters, | ||
66 | + std::vector<std::wstring>& ss); | ||
67 | + | ||
68 | +// Tokenizer class | ||
69 | +template <class T> | ||
70 | +struct default_delimiters {}; | ||
71 | +template <> | ||
72 | +struct default_delimiters<std::string> { | ||
73 | + static const char* value() { | ||
74 | + return " \t\n\r;:,.?"; | ||
75 | + } | ||
76 | +}; | ||
77 | +template <> | ||
78 | +struct default_delimiters<std::wstring> { | ||
79 | + static const wchar_t* value() { | ||
80 | + return L" \t\n\r;:,.?"; | ||
81 | + } | ||
82 | +}; | ||
83 | + | ||
84 | +template <class T> | ||
85 | +class Tokenizer { | ||
86 | + public: | ||
87 | + Tokenizer(const T& str, const T& delimiters = default_delimiters<T>::value()) | ||
88 | + : offset_(0), string_(str), delimiters_(delimiters) { | ||
89 | + } | ||
90 | + | ||
91 | + void Reset() { | ||
92 | + offset_ = 0; | ||
93 | + } | ||
94 | + const T GetToken() const { | ||
95 | + return token_; | ||
96 | + } | ||
97 | + bool NextToken() { | ||
98 | + return NextToken(delimiters_); | ||
99 | + } | ||
100 | + bool NextToken(const T& delimiters) { | ||
101 | + // find the start charater of the next token. | ||
102 | + typename T::size_type i = string_.find_first_not_of(delimiters, offset_); | ||
103 | + | ||
104 | + if (i == T::npos) { | ||
105 | + offset_ = string_.length(); | ||
106 | + return false; | ||
107 | + } | ||
108 | + | ||
109 | + // find the end of the token. | ||
110 | + typename T::size_type j = string_.find_first_of(delimiters, i); | ||
111 | + | ||
112 | + if (j == T::npos) { | ||
113 | + token_ = string_.substr(i, string_.length() - i); | ||
114 | + offset_ = string_.length(); | ||
115 | + return true; | ||
116 | + } | ||
117 | + | ||
118 | + // to intercept the token and save current position | ||
119 | + token_ = string_.substr(i, j - i); | ||
120 | + offset_ = j; | ||
121 | + return true; | ||
122 | + } | ||
123 | + | ||
124 | + private: | ||
125 | + Tokenizer(const Tokenizer&); | ||
126 | + Tokenizer& operator=(const Tokenizer&); | ||
127 | + | ||
128 | + protected: | ||
129 | + typename T::size_type offset_; | ||
130 | + | ||
131 | + const T string_; | ||
132 | + T token_; | ||
133 | + T delimiters_; | ||
134 | +}; | ||
135 | + | ||
136 | +template <typename T1, typename T2> | ||
137 | +bool MergeToken(const T1& begin, const T1& end, const T2& delimiter, T2& result) { | ||
138 | + if (begin == end) { | ||
139 | + return false; | ||
140 | + } | ||
141 | + | ||
142 | + if (delimiter.empty()) { | ||
143 | + return false; | ||
144 | + } | ||
145 | + | ||
146 | + result.clear(); | ||
147 | + | ||
148 | + for (T1 iter = begin; iter != end; ++iter) { | ||
149 | + result += *iter; | ||
150 | + | ||
151 | + if (iter + 1 != end) { | ||
152 | + result += delimiter; | ||
153 | + } | ||
154 | + } | ||
155 | + | ||
156 | + return true; | ||
157 | +} | ||
158 | + | ||
159 | +std::string Hex2Str(const char* _str, unsigned int _len); | ||
160 | +std::string Str2Hex(const char* _str, unsigned int _len); | ||
161 | + | ||
162 | +std::string ReplaceChar(const char* const input_str, char be_replaced = '@', char replace_with = '.'); | ||
163 | + | ||
164 | +std::string GetFileNameFromPath(const char* _path); | ||
165 | + | ||
166 | +// find substring (case insensitive) | ||
167 | +size_t ci_find_substr(const std::string& str, const std::string& sub, size_t pos); | ||
168 | +std::string BufferMD5(const void* buffer, size_t size); | ||
169 | +std::string MD5DigestToBase16(const uint8_t digest[16]); | ||
170 | +std::string DigestToBase16(const uint8_t* digest, size_t length); | ||
171 | +} // namespace strutil | ||
172 | + | ||
173 | +#endif // COMM_STRUTIL_H_ |
1 | +// Tencent is pleased to support the open source community by making Mars available. | ||
2 | +// Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. | ||
3 | + | ||
4 | +// Licensed under the MIT License (the "License"); you may not use this file except in | ||
5 | +// compliance with the License. You may obtain a copy of the License at | ||
6 | +// http://opensource.org/licenses/MIT | ||
7 | + | ||
8 | +// Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
9 | +// distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
10 | +// either express or implied. See the License for the specific language governing permissions and | ||
11 | +// limitations under the License. | ||
12 | + | ||
13 | +/* | ||
14 | + * utils.h | ||
15 | + * | ||
16 | + * Created on: 2012-7-18 | ||
17 | + * Author: yerungui | ||
18 | + */ | ||
19 | + | ||
20 | +#ifndef COMM_UTILS_H_ | ||
21 | +#define COMM_UTILS_H_ | ||
22 | + | ||
23 | +#include <stdint.h> | ||
24 | +#include <stdio.h> | ||
25 | +#ifdef __cplusplus | ||
26 | +extern "C" { | ||
27 | +#endif | ||
28 | + | ||
29 | +uint64_t gettickcount(); // ms | ||
30 | +int64_t gettickspan(uint64_t _old_tick); // ms | ||
31 | +uint64_t timeMs(); | ||
32 | + | ||
33 | +uint64_t clock_app_monotonic(); // ms | ||
34 | + | ||
35 | +#ifdef __cplusplus | ||
36 | +} | ||
37 | +#endif | ||
38 | + | ||
39 | +#endif /* COMM_UTILS_H_ */ |
1 | +// Tencent is pleased to support the open source community by making Mars available. | ||
2 | +// Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. | ||
3 | + | ||
4 | +// Licensed under the MIT License (the "License"); you may not use this file except in | ||
5 | +// compliance with the License. You may obtain a copy of the License at | ||
6 | +// http://opensource.org/licenses/MIT | ||
7 | + | ||
8 | +// Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
9 | +// distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
10 | +// either express or implied. See the License for the specific language governing permissions and | ||
11 | +// limitations under the License. | ||
12 | + | ||
13 | +/* | ||
14 | + * appender.h | ||
15 | + * | ||
16 | + * Created on: 2013-3-7 | ||
17 | + * Author: yerungui | ||
18 | + */ | ||
19 | + | ||
20 | +#ifndef APPENDER_H_ | ||
21 | +#define APPENDER_H_ | ||
22 | + | ||
23 | +#include <stdint.h> | ||
24 | + | ||
25 | +#include <string> | ||
26 | +#include <vector> | ||
27 | + | ||
28 | +namespace mars { | ||
29 | +namespace xlog { | ||
30 | + | ||
31 | +enum TAppenderMode { | ||
32 | + kAppenderAsync, | ||
33 | + kAppenderSync, | ||
34 | +}; | ||
35 | + | ||
36 | +enum TCompressMode { | ||
37 | + kZlib, | ||
38 | + kZstd, | ||
39 | +}; | ||
40 | + | ||
41 | +enum TFileIOAction { | ||
42 | + kActionNone = 0, | ||
43 | + kActionSuccess = 1, | ||
44 | + kActionUnnecessary = 2, | ||
45 | + kActionOpenFailed = 3, | ||
46 | + kActionReadFailed = 4, | ||
47 | + kActionWriteFailed = 5, | ||
48 | + kActionCloseFailed = 6, | ||
49 | + kActionRemoveFailed = 7, | ||
50 | +}; | ||
51 | + | ||
52 | +struct XLogConfig { | ||
53 | + TAppenderMode mode_ = kAppenderAsync; | ||
54 | + std::string logdir_; | ||
55 | + std::string nameprefix_; | ||
56 | + std::string pub_key_; | ||
57 | + TCompressMode compress_mode_ = kZlib; | ||
58 | + int compress_level_ = 6; | ||
59 | + std::string cachedir_; | ||
60 | + int cache_days_ = 0; | ||
61 | +}; | ||
62 | + | ||
63 | +#ifdef __APPLE__ | ||
64 | +enum TConsoleFun { | ||
65 | + kConsolePrintf, | ||
66 | + kConsoleNSLog, | ||
67 | +}; | ||
68 | +#endif | ||
69 | + | ||
70 | +void appender_open(const XLogConfig& _config); | ||
71 | + | ||
72 | +void appender_flush(); | ||
73 | +void appender_flush_sync(); | ||
74 | +void appender_close(); | ||
75 | +void appender_setmode(TAppenderMode _mode); | ||
76 | +bool appender_getfilepath_from_timespan(int _timespan, const char* _prefix, std::vector<std::string>& _filepath_vec); | ||
77 | +bool appender_make_logfile_name(int _timespan, const char* _prefix, std::vector<std::string>& _filepath_vec); | ||
78 | +bool appender_get_current_log_path(char* _log_path, unsigned int _len); | ||
79 | +bool appender_get_current_log_cache_path(char* _logPath, unsigned int _len); | ||
80 | +void appender_set_console_log(bool _is_open); | ||
81 | + | ||
82 | +#ifdef __APPLE__ | ||
83 | +void appender_set_console_fun(TConsoleFun _fun); | ||
84 | +#endif | ||
85 | +/* | ||
86 | + * By default, all logs will write to one file everyday. You can split logs to multi-file by changing max_file_size. | ||
87 | + * | ||
88 | + * @param _max_byte_size Max byte size of single log file, default is 0, meaning do not split. | ||
89 | + */ | ||
90 | +void appender_set_max_file_size(uint64_t _max_byte_size); | ||
91 | + | ||
92 | +/* | ||
93 | + * By default, all logs lives 10 days at most. | ||
94 | + * | ||
95 | + * @param _max_time Max alive duration of a single log file in seconds, default is 10 days | ||
96 | + */ | ||
97 | +void appender_set_max_alive_duration(long _max_time); | ||
98 | + | ||
99 | +void appender_oneshot_flush(const XLogConfig& _config, TFileIOAction* _result); | ||
100 | + | ||
101 | +} // namespace xlog | ||
102 | +} // namespace mars | ||
103 | + | ||
104 | +#endif /* APPENDER_H_ */ |
-
Please register or login to post a comment