UniPRT SDK v2.0.0.0
 
载入中...
搜索中...
未找到
JsonComm.h
1//
2// JsonMng.h
3// TSCPrinters SDK
4//
5// Created by Realbuber on 2024/4/3.
6//
7
8#ifndef JsonMng_h
9#define JsonMng_h
10
11
12#endif /* JsonMng_h */
13
14
15#import <Foundation/Foundation.h>
16#import <UniPRT/JsonStringTokenizer.h>
17#import <UniPRT/JsonStringBuilder.h>
18#import <UniPRT/ImpChannel.h>
19#import <UniPRT/CancellationToken.h>
20#import <UniPRT/TcpComm.h>
21
23
29
30
31@interface JsonComm : NSObject {
32 BOOL disposed;
33 NSLock *_listenerMutex;
34 NSMutableDictionary *_SolicitedListenerTable;
35 NSMutableArray *_msgListeners_Solicited;
36 CancellationToken *_cancellationTokenSource;
37 JsonStringTokenizer *_jsonStringTokenizer;
38 NSThread *_asyncJsonMsgTransceiverThread;
39
40 BOOL _Connected;
41 NSMutableArray *_msgListeners_AllMsgs;
42 NSMutableArray *_msgListeners_Unsolicited;
43 NSMutableString *_jsonReceived;
44 NSLock *_semaphoreListeners;
45
46 // id _commToPtr; /**< Pointer to the communication instance (commented out). */
47 NSInteger _iCommTyp;
48}
49
54typedef NS_ENUM(NSInteger, CommType) {
55 USB_COMM,
56 BT_COMM,
57 TCP_COMM,
58 BLE_COMM
59};
60
61@property (strong, nonatomic) id commToPtr;
62@property (assign, nonatomic) CommType commType;
63@property (assign, nonatomic) BOOL m_ThIsRunning;
64@property (nonatomic, strong) NSMutableArray *msgListeners_Solicited;
65@property (nonatomic, strong) NSMutableArray *msgListeners_Unsolicited;
66@property (nonatomic, strong) NSMutableArray *msgListeners_AllMsgs;
67@property (nonatomic, strong) NSMutableDictionary<NSString *, ImpChannel *> *solicitedListenerTable;
68@property (nonatomic, strong) ImpChannel *msgOut;
69@property (nonatomic, strong) ImpChannel *MonitorMsgOut;
70@property (nonatomic, strong) ImpChannel *MsgsFromPtr;
71@property (nonatomic, assign) BOOL usingDataPort;
72@property (nonatomic, strong) NSString *solicitedUnsolicitedMsg;
73@property (nonatomic, assign) NSInteger iMsgCount;
74
79typedef NS_ENUM(NSInteger, ChannelType) {
80 SOLICITED_MSGS_ONLY,
81 UNSOLICITED_MSGS_ONLY,
82 ALL_MSGS
83};
84
88- (void)dispose;
89
95- (void)disposeWithFlag:(BOOL)disposing;
96
102- (void)listenerChannelDisconnect:(ImpChannel *)chnlToRemove;
103
107- (void)start;
108
112- (void)stop;
113
117- (void)stopEx;
118
122- (void)jsonMsgTransceiverTask;
123
130- (NSString *)solicitedChnlKey:(ImpChannel *)chnlToLookFor;
131
139- (instancetype)initWithComm:(id)commToPtr commType:(NSInteger)commType;
140
149- (ImpChannel *)listenerChannelGetNewWithCapacity:(NSInteger)capacity
150 channelType:(ChannelType)channelType
151 solicitedMsgId:(NSString *)solicitedMsgId;
152
158- (void)send:(NSString *)mgmtMsgToSend;
159
165- (ImpChannel *)getImpChannel;
166
172- (TcpComm *)getPtrComm;
173
181- (NSString *)sendAndWaitForResponse:(NSString *)mgmtMsg timeout:(int)respTimeoutMs;
182
183@end
184
一个用于 TCP 通信的类,继承自 AComm 并符合 NSStreamDelegate 协议。
定义 TcpComm.h:101