ScanApiHelper.mm 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970
  1. //
  2. // ScanApiHelper.m
  3. // ScannerSettings
  4. //
  5. // Created by Eric Glaenzer on 7/29/11.
  6. // Copyright 2011 Socket Mobile, Inc. All rights reserved.
  7. //
  8. //#define TEST_SCAN 1
  9. #import "ScanApiHelper.h"
  10. #ifdef TEST_SCAN
  11. #import "AppDelegate.h"
  12. #endif
  13. /**
  14. * CommandContext
  15. *
  16. * This class holds the various parameter for a particular
  17. * property. It will be stored in the Context member of a property
  18. * to get it back upon property completion.
  19. */
  20. @implementation CommandContext
  21. -(id)initWithParam:(BOOL)getOperation
  22. ScanObj:(ISktScanObject*)scanObj
  23. ScanDevice:(ISktScanDevice*)scanDevice
  24. Device:(DeviceInfo*)device
  25. Target:(id)target
  26. Response:(SEL)response{
  27. self=[super init];
  28. if(self!=nil){
  29. _getOperation=getOperation;
  30. _scanObj=scanObj;
  31. _device=scanDevice;
  32. _deviceInfo=device;
  33. _target=target;
  34. _response=response;
  35. status=statusReady;
  36. [[_scanObj Property]setContext:self];// set the property context to this CommandContext instance
  37. }
  38. return self;
  39. }
  40. #if __has_feature(objc_arc)
  41. -(void)dealloc{
  42. [SktClassFactory releaseScanObject:_scanObj];
  43. }
  44. #else
  45. -(void)dealloc{
  46. [SktClassFactory releaseScanObject:_scanObj];
  47. _scanObj=nil;
  48. [super dealloc];
  49. }
  50. #endif
  51. @synthesize retry;
  52. @synthesize status;
  53. -(ISktScanDevice*)getScanDevice{
  54. return _device;
  55. }
  56. -(ISktScanObject*)getScanObject{
  57. return _scanObj;
  58. }
  59. // remove the warning about potential memory leak
  60. // in the _response selector because the compiler
  61. // doesn't know in ARC mode if it needs to apply
  62. // a retain or release.
  63. #pragma clang diagnostic push
  64. #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
  65. -(SKTRESULT)doCallback:(ISktScanObject*)scanObj{
  66. SKTRESULT result=ESKT_NOERROR;
  67. if((_response!=nil)&&(_target!=nil)){
  68. [_target performSelector:_response withObject:scanObj];
  69. }
  70. else{
  71. result=[[scanObj Msg]Result];
  72. }
  73. status=statusCompleted;
  74. return result;
  75. }
  76. #pragma clang diagnostic push
  77. -(SKTRESULT)doCommand{
  78. SKTRESULT result=ESKT_NOERROR;
  79. if(_device==nil)
  80. result=ESKT_INVALIDHANDLE;
  81. if(SKTSUCCESS(result)){
  82. if(_getOperation==true){
  83. result=[_device getProperty:_scanObj];
  84. }
  85. else{
  86. result=[_device setProperty:_scanObj];
  87. }
  88. retry++;
  89. // waiting for a complete event
  90. status=statusNotCompleted;
  91. }
  92. return result;
  93. }
  94. @end
  95. @implementation ScanApiHelper
  96. -(id)init{
  97. static ScanApiHelper* sharedScanApiHelper=nil;
  98. self=[super init];
  99. if(self!=nil){
  100. sharedScanApiHelper=self;
  101. _commandContextsLock=[[NSObject alloc]init];
  102. _deviceInfoList=[[NSMutableDictionary alloc]init];
  103. _scanApiOpen=FALSE;
  104. _scanApiTerminated=TRUE;// by default ScanApi is not started
  105. _delegateStack=[[NSMutableArray alloc]init];
  106. }
  107. return self;
  108. }
  109. #if __has_feature(objc_arc)
  110. -(void)dealloc{
  111. if(_scanApi!=nil){
  112. [_scanApi close];
  113. [SktClassFactory releaseScanApiInstance:_scanApi];
  114. _scanApi=nil;
  115. }
  116. _noDeviceText=nil;
  117. [_commandContexts removeAllObjects];
  118. _commandContexts=nil;
  119. _commandContextsLock=nil;
  120. _deviceInfoList=nil;
  121. _delegateStack=nil;
  122. }
  123. #else
  124. -(void)dealloc{
  125. if(_scanApi!=nil){
  126. [_scanApi close];
  127. [SktClassFactory releaseScanApiInstance:_scanApi];
  128. _scanApi=nil;
  129. }
  130. [_noDeviceText release];
  131. _noDeviceText=nil;
  132. [_commandContexts removeAllObjects];
  133. [_commandContexts release];
  134. _commandContexts=nil;
  135. [_commandContextsLock release];
  136. _commandContextsLock=nil;
  137. [_deviceInfoList release];
  138. _deviceInfoList=nil;
  139. [_delegateStack release];
  140. _delegateStack=nil;
  141. [super dealloc];
  142. }
  143. #endif
  144. +(ScanApiHelper*)sharedScanApiHelper{
  145. static ScanApiHelper* scanApiHelper=nil;
  146. if(scanApiHelper==nil){
  147. scanApiHelper=[[ScanApiHelper alloc]init];
  148. }
  149. return scanApiHelper;
  150. }
  151. -(void)pushDelegate:(id<ScanApiHelperDelegate>)delegate{
  152. if(_delegate != delegate){
  153. if(_delegate!=nil){
  154. [_delegateStack addObject:_delegate];
  155. }
  156. _delegate=delegate;
  157. [self generateDeviceArrivals];
  158. }
  159. }
  160. -(void)popDelegate:(id<ScanApiHelperDelegate>)delegate{
  161. if(_delegate ==delegate){
  162. if(_delegateStack.count>0){
  163. id<ScanApiHelperDelegate> newDelegate=[_delegateStack objectAtIndex:_delegateStack.count-1];
  164. [_delegateStack removeLastObject];
  165. _delegate = newDelegate;
  166. // generate a device Arrival for each scanner we've already receive
  167. // so that the new view can be aware of the connected scanners
  168. [self generateDeviceArrivals];
  169. }
  170. else{
  171. _delegate=nil;
  172. }
  173. }
  174. }
  175. /**
  176. * register for notifications in order to receive notifications such as
  177. * "Device Arrival", "Device Removal", "Decoded Data"...etc...
  178. * @param delegate
  179. */
  180. -(void)setDelegate:(id<ScanApiHelperDelegate>)delegate{
  181. _delegate=delegate;
  182. }
  183. /**
  184. * specifying a name to display when no device is connected
  185. * will add a no device connected item in the list with
  186. * the name specified, otherwise if there is no device connected
  187. * the list will be empty.
  188. */
  189. -(void)setNoDeviceText:(NSString*) noDeviceText{
  190. #if __has_feature(objc_arc)
  191. #else
  192. [_noDeviceText release];
  193. [noDeviceText retain];
  194. #endif
  195. _noDeviceText=noDeviceText;
  196. }
  197. /**
  198. * get the list of devices. If there is no device
  199. * connected and a text has been specified for
  200. * when there is no device then the list will
  201. * contain one item which is the no device in the
  202. * list
  203. * @return
  204. */
  205. -(NSDictionary*) getDevicesList{
  206. return _deviceInfoList;
  207. }
  208. /**
  209. * get a DeviceInfo object from a ScanObject received by ScanAPI.
  210. *
  211. * If no DeviceInfo matches, this method returns nil
  212. * @param scanObj, ScanObject received by ScanAPI that contains the
  213. * device information.
  214. *
  215. * @return a device info instance or nil if no device info in the list
  216. * matches to the ScanObj device information.
  217. */
  218. -(DeviceInfo*) getDeviceInfoFromScanObject:(ISktScanObject*)scanObj{
  219. ISktScanDevice* scanDevice=[[scanObj Msg]hDevice];
  220. // retrieve the DeviceInfo object from the list
  221. DeviceInfo* deviceInfo=[_deviceInfoList valueForKey:[NSString stringWithFormat:@"%@",scanDevice]];
  222. return deviceInfo;
  223. }
  224. /**
  225. * check if there is a device connected
  226. * @return
  227. */
  228. -(BOOL) isDeviceConnected{
  229. BOOL isConnected=FALSE;
  230. if(_deviceInfoList!=nil){
  231. if([_deviceInfoList count]>0){
  232. if(_noDeviceText!=nil){
  233. isConnected=![[_deviceInfoList allValues]containsObject:_noDeviceText];// check if there is a no device text item in the list
  234. }
  235. else
  236. isConnected=TRUE;// there is at least one device connected when no device text is not used
  237. }
  238. }
  239. return isConnected;
  240. }
  241. /**
  242. * flag to know if ScanAPI is open
  243. * @return
  244. */
  245. -(BOOL)isScanApiOpen{
  246. return _scanApiOpen;
  247. }
  248. /**
  249. * open ScanAPI and initialize ScanAPI
  250. * The result of opening ScanAPI is returned in the callback
  251. * onScanApiInitializeComplete
  252. */
  253. -(void)open{
  254. // make sure the devices list is empty
  255. [_deviceInfoList removeAllObjects];
  256. // if there is a text to display when no device
  257. // is connected then add it now in the list
  258. if(_noDeviceText!=nil)
  259. [_deviceInfoList setObject:_noDeviceText forKey:_noDeviceText];
  260. [SktClassFactory releaseScanObject:_scanObjectReceived];
  261. _scanObjectReceived=[SktClassFactory createScanObject];
  262. // Start ScanAPI initialization into a thread
  263. // as sometimes this could be a lengthy operation
  264. #if __has_feature(objc_arc)
  265. NSThread* scanApiInitThread=[[NSThread alloc]initWithTarget:self selector:@selector(initializeScanAPIThread:) object:nil];
  266. #else
  267. NSThread* scanApiInitThread=[[[NSThread alloc]initWithTarget:self selector:@selector(initializeScanAPIThread:) object:nil]
  268. autorelease];
  269. #endif
  270. [scanApiInitThread start];
  271. _scanApiOpen=TRUE;
  272. }
  273. /**
  274. * close ScanAPI. The callback onScanApiTerminated
  275. * is invoked as soon as ScanAPI is completely closed.
  276. * If a device is connected, a device removal will be received
  277. * during the process of closing ScanAPI.
  278. */
  279. -(void)close{
  280. [self postScanApiAbort:nil Response:nil];
  281. _scanApiOpen=FALSE;
  282. }
  283. /**
  284. * remove the pending commands for a specific device
  285. * or all the pending commands if null is passed as
  286. * iDevice parameter
  287. * @param iDevice reference to the device for which
  288. * the commands must be removed from the list or <b>null</b>
  289. * if all the commands must be removed.
  290. */
  291. -(void)removeCommand:(DeviceInfo*)deviceInfo{
  292. ISktScanDevice* iDevice=[deviceInfo getSktScanDevice];
  293. CommandContext* commandContext=nil;
  294. int index=0;
  295. @synchronized(_commandContextsLock){
  296. while(index<[_commandContexts count]){
  297. commandContext=[_commandContexts objectAtIndex:index];
  298. if([commandContext getScanDevice]==iDevice){
  299. [_commandContexts removeObjectAtIndex:index];
  300. commandContext=nil;
  301. index=0;
  302. }
  303. else
  304. index++;
  305. }
  306. }
  307. }
  308. /**
  309. * postGetScanAPIVersion
  310. * retrieve the ScanAPI Version
  311. */
  312. -(void)postGetScanApiVersion:(id)target Response:(SEL)response{
  313. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  314. [[scanObj Property]setID:kSktScanPropIdVersion];
  315. [[scanObj Property]setType:kSktScanPropTypeNone];
  316. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  317. ScanObj:scanObj
  318. ScanDevice:_scanApi
  319. Device:nil
  320. Target:target
  321. Response:response];
  322. [self addCommand:command];
  323. #if __has_feature(objc_arc)
  324. #else
  325. [command release];
  326. #endif
  327. }
  328. /**
  329. * postSetConfirmationMode
  330. * Configures ScanAPI so that scanned data must be confirmed by this application before the
  331. * scanner can be triggered again.
  332. */
  333. -(void)postSetConfirmationMode:(unsigned char)mode Target:(id)target Response:(SEL)response{
  334. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  335. [[scanObj Property]setID:kSktScanPropIdDataConfirmationMode];
  336. [[scanObj Property]setType:kSktScanPropTypeByte];
  337. [[scanObj Property]setByte:mode];
  338. CommandContext* command=[[CommandContext alloc]initWithParam:FALSE
  339. ScanObj:scanObj
  340. ScanDevice:_scanApi
  341. Device:nil
  342. Target:target
  343. Response:response];
  344. [self addCommand:command];
  345. #if __has_feature(objc_arc)
  346. #else
  347. [command release];
  348. #endif
  349. }
  350. /**
  351. * postScanApiAbort
  352. *
  353. * Request ScanAPI to shutdown. If there is some devices connected
  354. * we will receive Remove event for each of them, and once all the
  355. * outstanding devices are closed, then ScanAPI will send a
  356. * Terminate event upon which we can close this application.
  357. * If the ScanAPI Abort command failed, then the callback will
  358. * close ScanAPI
  359. */
  360. -(void)postScanApiAbort:(id)target Response:(SEL)response{
  361. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  362. [[scanObj Property]setID:kSktScanPropIdAbort];
  363. [[scanObj Property]setType:kSktScanPropTypeNone];
  364. CommandContext* command=[[CommandContext alloc]initWithParam:FALSE
  365. ScanObj:scanObj
  366. ScanDevice:_scanApi
  367. Device:nil
  368. Target:target
  369. Response:response];
  370. [self addCommand:command];
  371. #if __has_feature(objc_arc)
  372. #else
  373. [command release];
  374. #endif
  375. }
  376. /**
  377. * postSetDataConfirmation
  378. * acknowledge the decoded data<p>
  379. * This is only required if the scanner Confirmation Mode is set to kSktScanDataConfirmationModeApp
  380. */
  381. -(void)postSetDataConfirmation:(DeviceInfo*)deviceInfo Target:(id)target Response:(SEL)response{
  382. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  383. [[scanObj Property]setID:kSktScanPropIdDataConfirmationDevice];
  384. [[scanObj Property]setType:kSktScanPropTypeUlong];
  385. [[scanObj Property]setUlong:SKTDATACONFIRMATION(0, kSktScanDataConfirmationRumbleNone,
  386. kSktScanDataConfirmationBeepGood,
  387. kSktScanDataConfirmationLedGreen)];
  388. CommandContext* command=[[CommandContext alloc]initWithParam:FALSE
  389. ScanObj:scanObj
  390. ScanDevice:[deviceInfo getSktScanDevice]
  391. Device:deviceInfo
  392. Target:target
  393. Response:response];
  394. [self addCommand:command];
  395. #if __has_feature(objc_arc)
  396. #else
  397. [command release];
  398. #endif
  399. }
  400. /**
  401. * postSetSoftScanStatus
  402. * enable or disable the softscan feature.
  403. */
  404. -(void)postSetSoftScanStatus:(unsigned char)action Target:(id)target Response:(SEL)response{
  405. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  406. [[scanObj Property]setID:kSktScanPropIdSoftScanStatus];
  407. [[scanObj Property]setType:kSktScanPropTypeByte];
  408. [[scanObj Property]setByte:action];
  409. CommandContext* command=[[CommandContext alloc]initWithParam:FALSE
  410. ScanObj:scanObj
  411. ScanDevice:_scanApi
  412. Device:nil
  413. Target:target
  414. Response:response];
  415. [self addCommand:command];
  416. #if __has_feature(objc_arc)
  417. #else
  418. [command release];
  419. #endif
  420. }
  421. /**
  422. * postGetSoftScanStatus
  423. * Retrieve the status of the softscan feature.
  424. */
  425. -(void)postGetSoftScanStatus:(id)target Response:(SEL)response{
  426. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  427. [[scanObj Property]setID:kSktScanPropIdSoftScanStatus];
  428. [[scanObj Property]setType:kSktScanPropTypeNone];
  429. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  430. ScanObj:scanObj
  431. ScanDevice:_scanApi
  432. Device:nil
  433. Target:target
  434. Response:response];
  435. [self addCommand:command];
  436. #if __has_feature(objc_arc)
  437. #else
  438. [command release];
  439. #endif
  440. }
  441. /**
  442. * postGetBtAddress
  443. * Creates a SktScanObject and initializes it to perform a request for the
  444. * Bluetooth address in the scanner.
  445. */
  446. -(void)postGetBtAddress:(DeviceInfo*)deviceInfo Target:(id)target Response:(SEL)response{
  447. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  448. [[scanObj Property]setID:kSktScanPropIdBluetoothAddressDevice];
  449. [[scanObj Property]setType:kSktScanPropTypeNone];
  450. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  451. ScanObj:scanObj
  452. ScanDevice:[deviceInfo getSktScanDevice]
  453. Device:deviceInfo
  454. Target:target
  455. Response:response];
  456. [self addCommand:command];
  457. #if __has_feature(objc_arc)
  458. #else
  459. [command release];
  460. #endif
  461. }
  462. /**
  463. * postGetDeviceType
  464. * Creates a SktScanObject and initializes it to perform a request for the
  465. * device type of the scanner.
  466. */
  467. -(void)postGetDeviceType:(DeviceInfo*)deviceInfo Target:(id)target Response:(SEL)response{
  468. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  469. [[scanObj Property]setID:kSktScanPropIdDeviceType];
  470. [[scanObj Property]setType:kSktScanPropTypeNone];
  471. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  472. ScanObj:scanObj
  473. ScanDevice:[deviceInfo getSktScanDevice]
  474. Device:deviceInfo
  475. Target:target
  476. Response:response];
  477. [self addCommand:command];
  478. #if __has_feature(objc_arc)
  479. #else
  480. [command release];
  481. #endif
  482. }
  483. /**
  484. * postGetFirmwareVersion
  485. * Creates a SktScanObject and initializes it to perform a request for the
  486. * firmware revision in the scanner.
  487. */
  488. -(void)postGetFirmwareVersion:(DeviceInfo*)deviceInfo Target:target Response:(SEL)response{
  489. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  490. [[scanObj Property]setID:kSktScanPropIdVersionDevice];
  491. [[scanObj Property]setType:kSktScanPropTypeNone];
  492. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  493. ScanObj:scanObj
  494. ScanDevice:[deviceInfo getSktScanDevice]
  495. Device:deviceInfo
  496. Target:target
  497. Response:response];
  498. [self addCommand:command];
  499. #if __has_feature(objc_arc)
  500. #else
  501. [command release];
  502. #endif
  503. }
  504. /**
  505. * postGetBattery
  506. * Creates a SktScanObject and initializes it to perform a request for the
  507. * battery level in the scanner.
  508. */
  509. -(void)postGetBattery:(DeviceInfo*)deviceInfo Target:(id)target Response:(SEL)response{
  510. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  511. [[scanObj Property]setID:kSktScanPropIdBatteryLevelDevice];
  512. [[scanObj Property]setType:kSktScanPropTypeNone];
  513. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  514. ScanObj:scanObj
  515. ScanDevice:[deviceInfo getSktScanDevice]
  516. Device:deviceInfo
  517. Target:target
  518. Response:response];
  519. [self addCommand:command];
  520. #if __has_feature(objc_arc)
  521. #else
  522. [command release];
  523. #endif
  524. }
  525. /**
  526. * postGetStandConfig
  527. * Creates a SktScanObject and initializes it to perform a request for the
  528. * stand config of the scanner.
  529. */
  530. -(void)postGetStandConfig:(DeviceInfo*)deviceInfo Target:(id)target Response:(SEL)response{
  531. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  532. [[scanObj Property]setID:kSktScanPropIdStandConfigDevice];
  533. [[scanObj Property]setType:kSktScanPropTypeNone];
  534. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  535. ScanObj:scanObj
  536. ScanDevice:[deviceInfo getSktScanDevice]
  537. Device:deviceInfo
  538. Target:target
  539. Response:response];
  540. [self addCommand:command];
  541. #if __has_feature(objc_arc)
  542. #else
  543. [command release];
  544. #endif
  545. }
  546. /**
  547. * postSetStandConfig
  548. * Creates a SktScanObject and initializes it to perform a request for changing the
  549. * stand config of the scanner.
  550. */
  551. -(void)postSetStandConfig:(DeviceInfo*)deviceInfo StandConfig:(long) standConfig Target:(id)target Response:(SEL)response{
  552. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  553. [[scanObj Property]setID:kSktScanPropIdStandConfigDevice];
  554. [[scanObj Property]setType:kSktScanPropTypeUlong];
  555. [[scanObj Property]setUlong:standConfig];
  556. CommandContext* command=[[CommandContext alloc]initWithParam:FALSE
  557. ScanObj:scanObj
  558. ScanDevice:[deviceInfo getSktScanDevice]
  559. Device:deviceInfo
  560. Target:target
  561. Response:response];
  562. [self addCommand:command];
  563. #if __has_feature(objc_arc)
  564. #else
  565. [command release];
  566. #endif
  567. }
  568. /**
  569. * postGetDecodeAction
  570. *
  571. * Creates a SktScanObject and initializes it to perform a request for the
  572. * Decode Action in the scanner.
  573. *
  574. */
  575. -(void)postGetDecodeAction:(DeviceInfo*)deviceInfo Target:(id)target Response:(SEL)response{
  576. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  577. [[scanObj Property]setID:kSktScanPropIdLocalDecodeActionDevice];
  578. [[scanObj Property]setType:kSktScanPropTypeNone];
  579. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  580. ScanObj:scanObj
  581. ScanDevice:[deviceInfo getSktScanDevice]
  582. Device:deviceInfo
  583. Target:target
  584. Response:response];
  585. [self addCommand:command];
  586. #if __has_feature(objc_arc)
  587. #else
  588. [command release];
  589. #endif
  590. }
  591. /**
  592. * postSetDecodeAction
  593. *
  594. * Configure the local decode action of the device
  595. *
  596. * @param deviceInfo
  597. * @param decodeAction
  598. */
  599. -(void)postSetDecodeAction:(DeviceInfo*)deviceInfo DecodeAction:(int)decodeAction Target:(id)target Response:(SEL)response{
  600. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  601. [[scanObj Property]setID:kSktScanPropIdLocalDecodeActionDevice];
  602. [[scanObj Property]setType:kSktScanPropTypeByte];
  603. [[scanObj Property]setByte:decodeAction];
  604. CommandContext* command=[[CommandContext alloc]initWithParam:FALSE
  605. ScanObj:scanObj
  606. ScanDevice:[deviceInfo getSktScanDevice]
  607. Device:deviceInfo
  608. Target:target
  609. Response:response];
  610. [self addCommand:command];
  611. #if __has_feature(objc_arc)
  612. #else
  613. [command release];
  614. #endif
  615. }
  616. /**
  617. * postGetCapabilitiesDevice
  618. *
  619. * Creates a SktScanObject and initializes it to perform a request for the
  620. * Capabilities Device in the scanner.
  621. */
  622. -(void)postGetCapabilitiesDevice:(DeviceInfo*)deviceInfo Target:(id)target Response:(SEL)response{
  623. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  624. [[scanObj Property]setID:kSktScanPropIdCapabilitiesDevice];
  625. [[scanObj Property]setType:kSktScanPropTypeByte];
  626. [[scanObj Property]setByte:kSktScanCapabilityLocalFunctions];// ask for the capabilities of the scanner
  627. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  628. ScanObj:scanObj
  629. ScanDevice:[deviceInfo getSktScanDevice]
  630. Device:deviceInfo
  631. Target:target
  632. Response:response];
  633. [self addCommand:command];
  634. #if __has_feature(objc_arc)
  635. #else
  636. [command release];
  637. #endif
  638. }
  639. /**
  640. * postGetPostambleDevice
  641. *
  642. * Creates a SktScanObject and initializes it to perform a request for the
  643. * Postamble Device in the scanner.
  644. *
  645. */
  646. -(void)postGetPostambleDevice:(DeviceInfo*)deviceInfo Target:(id)target Response:(SEL)response{
  647. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  648. [[scanObj Property]setID:kSktScanPropIdPostambleDevice];
  649. [[scanObj Property]setType:kSktScanPropTypeNone];
  650. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  651. ScanObj:scanObj
  652. ScanDevice:[deviceInfo getSktScanDevice]
  653. Device:deviceInfo
  654. Target:target
  655. Response:response];
  656. [self addCommand:command];
  657. #if __has_feature(objc_arc)
  658. #else
  659. [command release];
  660. #endif
  661. }
  662. /**
  663. * postSetPostamble
  664. *
  665. * Configure the postamble of the device
  666. * @param deviceInfo
  667. * @param postamble
  668. */
  669. -(void)postSetPostambleDevice:(DeviceInfo*)deviceInfo Postamble:(NSString*)postamble Target:(id)target Response:(SEL)response{
  670. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  671. [[scanObj Property]setID:kSktScanPropIdPostambleDevice];
  672. [[scanObj Property]setType:kSktScanPropTypeString];
  673. [[scanObj Property]setString:postamble];
  674. CommandContext* command=[[CommandContext alloc]initWithParam:FALSE
  675. ScanObj:scanObj
  676. ScanDevice:[deviceInfo getSktScanDevice]
  677. Device:deviceInfo
  678. Target:target
  679. Response:response];
  680. [self addCommand:command];
  681. #if __has_feature(objc_arc)
  682. #else
  683. [command release];
  684. #endif
  685. }
  686. /**
  687. * postGetSymbologyInfo
  688. *
  689. * Creates a SktScanObject and initializes it to perform a request for the
  690. * Symbology Info in the scanner.
  691. *
  692. */
  693. -(void)postGetSymbologyInfo:(DeviceInfo*)deviceInfo SymbologyId:(int)symbologyId Target:(id)target Response:(SEL)response{
  694. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  695. [[scanObj Property]setID:kSktScanPropIdSymbologyDevice];
  696. [[scanObj Property]setType:kSktScanPropTypeSymbology];
  697. [[[scanObj Property]Symbology]setID:(enum ESktScanSymbologyID)symbologyId];
  698. [[[scanObj Property]Symbology]setFlags:kSktScanSymbologyFlagStatus];
  699. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  700. ScanObj:scanObj
  701. ScanDevice:[deviceInfo getSktScanDevice]
  702. Device:deviceInfo
  703. Target:target
  704. Response:response];
  705. [self addCommand:command];
  706. #if __has_feature(objc_arc)
  707. #else
  708. [command release];
  709. #endif
  710. }
  711. /**
  712. * postSetSymbologyInfo
  713. * Constructs a request object for setting the Symbology Info in the scanner
  714. *
  715. */
  716. -(void)postSetSymbologyInfo:(DeviceInfo*)deviceInfo SymbologyId:(int)symbologyId Status:(BOOL)status Target:(id)target Response:(SEL)response{
  717. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  718. [[scanObj Property]setID:kSktScanPropIdSymbologyDevice];
  719. [[scanObj Property]setType:kSktScanPropTypeSymbology];
  720. [[[scanObj Property]Symbology]setID:(enum ESktScanSymbologyID)symbologyId];
  721. [[[scanObj Property]Symbology]setFlags:kSktScanSymbologyFlagStatus];
  722. if(status==TRUE)
  723. [[[scanObj Property]Symbology]setStatus:kSktScanSymbologyStatusEnable];
  724. else
  725. [[[scanObj Property]Symbology]setStatus:kSktScanSymbologyStatusDisable];
  726. CommandContext* command=[[CommandContext alloc]initWithParam:FALSE
  727. ScanObj:scanObj
  728. ScanDevice:[deviceInfo getSktScanDevice]
  729. Device:deviceInfo
  730. Target:target
  731. Response:response];
  732. [self addCommand:command];
  733. #if __has_feature(objc_arc)
  734. #else
  735. [command release];
  736. #endif
  737. }
  738. /**
  739. * postGetFriendlyName
  740. *
  741. * Creates a SktScanObject and initializes it to perform a request for the
  742. * friendly name in the scanner.
  743. *
  744. */
  745. -(void)postGetFriendlyName:(DeviceInfo*)deviceInfo Target:(id)target Response:(SEL)response{
  746. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  747. [[scanObj Property]setID:kSktScanPropIdFriendlyNameDevice];
  748. [[scanObj Property]setType:kSktScanPropTypeNone];
  749. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  750. ScanObj:scanObj
  751. ScanDevice:[deviceInfo getSktScanDevice]
  752. Device:deviceInfo
  753. Target:target
  754. Response:response];
  755. [self addCommand:command];
  756. #if __has_feature(objc_arc)
  757. #else
  758. [command release];
  759. #endif
  760. }
  761. /**
  762. * postSetFriendlyName
  763. * Constructs a request object for setting the Friendly Name in the scanner
  764. *
  765. */
  766. -(void)postSetFriendlyName:(DeviceInfo*)deviceInfo FriendlyName:(NSString*)friendlyName Target:(id)target Response:(SEL)response{
  767. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  768. [[scanObj Property]setID:kSktScanPropIdFriendlyNameDevice];
  769. [[scanObj Property]setType:kSktScanPropTypeString];
  770. [[scanObj Property]setString:friendlyName];
  771. CommandContext* command=[[CommandContext alloc]initWithParam:FALSE
  772. ScanObj:scanObj
  773. ScanDevice:[deviceInfo getSktScanDevice]
  774. Device:deviceInfo
  775. Target:target
  776. Response:response];
  777. [self addCommand:command];
  778. #if __has_feature(objc_arc)
  779. #else
  780. [command release];
  781. #endif
  782. }
  783. /**
  784. * postSetOverlayView
  785. *
  786. * Configure the Overlay view of softscan
  787. *
  788. * @param deviceInfo
  789. * @param decodeAction
  790. */
  791. -(void)postSetOverlayView:(DeviceInfo*)deviceInfo OverlayView:(id)overlayview Target:(id)target Response:(SEL)response{
  792. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  793. [[scanObj Property]setID:kSktScanPropIdOverlayViewDevice];
  794. [[scanObj Property]setType:kSktScanPropTypeObject];
  795. [[scanObj Property]setObject:overlayview];
  796. CommandContext* command=[[CommandContext alloc]initWithParam:FALSE
  797. ScanObj:scanObj
  798. ScanDevice:[deviceInfo getSktScanDevice]
  799. Device:deviceInfo
  800. Target:target
  801. Response:response];
  802. [self addCommand:command];
  803. #if __has_feature(objc_arc)
  804. #else
  805. [command release];
  806. #endif
  807. }
  808. /**
  809. * postSetTriggerDevice
  810. *
  811. * start scanning
  812. *
  813. * @param deviceInfo
  814. * @param decodeAction
  815. */
  816. -(void)postSetTriggerDevice:(DeviceInfo*)deviceInfo Action:(unsigned char)action Target:(id)target Response:(SEL)response{
  817. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  818. [[scanObj Property]setID:kSktScanPropIdTriggerDevice];
  819. [[scanObj Property]setType:kSktScanPropTypeByte];
  820. [[scanObj Property]setByte:action];
  821. CommandContext* command=[[CommandContext alloc]initWithParam:FALSE
  822. ScanObj:scanObj
  823. ScanDevice:[deviceInfo getSktScanDevice]
  824. Device:deviceInfo
  825. Target:target
  826. Response:response];
  827. [self addCommand:command];
  828. #if __has_feature(objc_arc)
  829. #else
  830. [command release];
  831. #endif
  832. }
  833. //#ifdef SCANAPI_HELPER_DATAEDITING
  834. /**
  835. * postGetDataEditingProfiles
  836. *
  837. * Get the list of Data Editing profiles
  838. *
  839. */
  840. -(void)postGetDataEditingProfiles:(id)target Response:(SEL)response{
  841. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  842. [[scanObj Property]setID:kSktScanPropIdDataEditingProfile];
  843. [[scanObj Property]setType:kSktScanPropTypeNone];
  844. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  845. ScanObj:scanObj
  846. ScanDevice:_scanApi
  847. Device:nil
  848. Target:target
  849. Response:response];
  850. [self addCommand:command];
  851. #if __has_feature(objc_arc)
  852. #else
  853. [command release];
  854. #endif
  855. }
  856. /**
  857. * postSetDataEditingProfiles
  858. *
  859. * Set the list of Data Editing profiles
  860. * This will add or remove profiles in function of
  861. * the current profiles list
  862. * @param profiles: semi colon separated list of the new profiles
  863. */
  864. -(void)postSetDataEditingProfiles:(NSString*)profiles Target:(id)target Response:(SEL)response{
  865. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  866. [[scanObj Property]setID:kSktScanPropIdDataEditingProfile];
  867. [[scanObj Property]setType:kSktScanPropTypeString];
  868. [[scanObj Property]setString:profiles];
  869. CommandContext* command=[[CommandContext alloc]initWithParam:FALSE
  870. ScanObj:scanObj
  871. ScanDevice:_scanApi
  872. Device:nil
  873. Target:target
  874. Response:response];
  875. [self addCommand:command];
  876. #if __has_feature(objc_arc)
  877. #else
  878. [command release];
  879. #endif
  880. }
  881. /**
  882. * postGetDataEditingCurrentProfile
  883. *
  884. * Get the Data Editing current profile
  885. *
  886. */
  887. -(void)postGetDataEditingCurrentProfile:(id)target Response:(SEL)response{
  888. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  889. [[scanObj Property]setID:kSktScanPropIdDataEditingCurrentProfile];
  890. [[scanObj Property]setType:kSktScanPropTypeNone];
  891. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  892. ScanObj:scanObj
  893. ScanDevice:_scanApi
  894. Device:nil
  895. Target:target
  896. Response:response];
  897. [self addCommand:command];
  898. #if __has_feature(objc_arc)
  899. #else
  900. [command release];
  901. #endif
  902. }
  903. /**
  904. * postSetDataEditingCurrentProfile
  905. *
  906. * Set the Data Editing current profile
  907. *
  908. * @param profile: new current profile selected
  909. */
  910. -(void)postSetDataEditingCurrentProfile:(NSString*)profile Target:(id)target Response:(SEL)response{
  911. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  912. [[scanObj Property]setID:kSktScanPropIdDataEditingCurrentProfile];
  913. [[scanObj Property]setType:kSktScanPropTypeString];
  914. [[scanObj Property]setString:profile];
  915. CommandContext* command=[[CommandContext alloc]initWithParam:FALSE
  916. ScanObj:scanObj
  917. ScanDevice:_scanApi
  918. Device:nil
  919. Target:target
  920. Response:response];
  921. [self addCommand:command];
  922. #if __has_feature(objc_arc)
  923. #else
  924. [command release];
  925. #endif
  926. }
  927. /**
  928. * postGetDataEditingTriggerSymbology
  929. *
  930. * Get the Data Editing profile Trigger symbology list the
  931. * decoded data must come from
  932. *
  933. * @param profile to retrieve the trigger symbology list from
  934. */
  935. -(void)postGetDataEditingTriggerSymbology:(NSString*)profile Target:(id)target Response:(SEL)response{
  936. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  937. [[scanObj Property]setID:kSktScanPropIdDataEditingTriggerSymbologies];
  938. [[scanObj Property]setType:kSktScanPropTypeString];
  939. [[scanObj Property]setString:profile];
  940. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  941. ScanObj:scanObj
  942. ScanDevice:_scanApi
  943. Device:nil
  944. Target:target
  945. Response:response];
  946. [self addCommand:command];
  947. #if __has_feature(objc_arc)
  948. #else
  949. [command release];
  950. #endif
  951. }
  952. /**
  953. * postSetDataEditingTriggerSymbology
  954. *
  955. * Set the Data Editing profile Trigger symbology list
  956. *
  957. * @param profile to set the trigger symbology list to
  958. */
  959. -(void)postSetDataEditingTriggerSymbology:(NSString*)profileAndSymbology Target:(id)target Response:(SEL)response{
  960. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  961. [[scanObj Property]setID:kSktScanPropIdDataEditingTriggerSymbologies];
  962. [[scanObj Property]setType:kSktScanPropTypeString];
  963. [[scanObj Property]setString:profileAndSymbology];
  964. CommandContext* command=[[CommandContext alloc]initWithParam:FALSE
  965. ScanObj:scanObj
  966. ScanDevice:_scanApi
  967. Device:nil
  968. Target:target
  969. Response:response];
  970. [self addCommand:command];
  971. #if __has_feature(objc_arc)
  972. #else
  973. [command release];
  974. #endif
  975. }
  976. /**
  977. * postGetDataEditingTriggerMinLength
  978. *
  979. * Get the Data Editing profile Trigger Minimum Length for the decoded Data
  980. *
  981. * @param profile to get the trigger minimum length
  982. */
  983. -(void)postGetDataEditingTriggerMinLength:(NSString*)profile Target:(id)target Response:(SEL)response{
  984. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  985. [[scanObj Property]setID:kSktScanPropIdDataEditingTriggerMinLength];
  986. [[scanObj Property]setType:kSktScanPropTypeString];
  987. [[scanObj Property]setString:profile];
  988. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  989. ScanObj:scanObj
  990. ScanDevice:_scanApi
  991. Device:nil
  992. Target:target
  993. Response:response];
  994. [self addCommand:command];
  995. #if __has_feature(objc_arc)
  996. #else
  997. [command release];
  998. #endif
  999. }
  1000. /**
  1001. * postSetDataEditingTriggerMinLength
  1002. *
  1003. * Set the Data Editing profile Trigger Minimum Length for the decoded Data
  1004. *
  1005. * @param profileAndLength contains the profile and the minimum length in decimal
  1006. */
  1007. -(void)postSetDataEditingTriggerMinLength:(NSString*)profileAndLength Target:(id)target Response:(SEL)response{
  1008. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  1009. [[scanObj Property]setID:kSktScanPropIdDataEditingTriggerMinLength];
  1010. [[scanObj Property]setType:kSktScanPropTypeString];
  1011. [[scanObj Property]setString:profileAndLength];
  1012. CommandContext* command=[[CommandContext alloc]initWithParam:FALSE
  1013. ScanObj:scanObj
  1014. ScanDevice:_scanApi
  1015. Device:nil
  1016. Target:target
  1017. Response:response];
  1018. [self addCommand:command];
  1019. #if __has_feature(objc_arc)
  1020. #else
  1021. [command release];
  1022. #endif
  1023. }
  1024. /**
  1025. * postGetDataEditingTriggerMaxLength
  1026. *
  1027. * Get the Data Editing profile Trigger Maximum Length for the decoded Data
  1028. *
  1029. * @param profile to get the trigger maximum length
  1030. */
  1031. -(void)postGetDataEditingTriggerMaxLength:(NSString*)profile Target:(id)target Response:(SEL)response{
  1032. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  1033. [[scanObj Property]setID:kSktScanPropIdDataEditingTriggerMaxLength];
  1034. [[scanObj Property]setType:kSktScanPropTypeString];
  1035. [[scanObj Property]setString:profile];
  1036. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  1037. ScanObj:scanObj
  1038. ScanDevice:_scanApi
  1039. Device:nil
  1040. Target:target
  1041. Response:response];
  1042. [self addCommand:command];
  1043. #if __has_feature(objc_arc)
  1044. #else
  1045. [command release];
  1046. #endif
  1047. }
  1048. /**
  1049. * postSetDataEditingTriggerMaxLength
  1050. *
  1051. * Set the Data Editing profile Trigger Maximum Length for the decoded Data
  1052. *
  1053. * @param profileAndLength contains the profile and the maximum length in decimal
  1054. */
  1055. -(void)postSetDataEditingTriggerMaxLength:(NSString*)profileAndLength Target:(id)target Response:(SEL)response{
  1056. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  1057. [[scanObj Property]setID:kSktScanPropIdDataEditingTriggerMaxLength];
  1058. [[scanObj Property]setType:kSktScanPropTypeString];
  1059. [[scanObj Property]setString:profileAndLength];
  1060. CommandContext* command=[[CommandContext alloc]initWithParam:FALSE
  1061. ScanObj:scanObj
  1062. ScanDevice:_scanApi
  1063. Device:nil
  1064. Target:target
  1065. Response:response];
  1066. [self addCommand:command];
  1067. #if __has_feature(objc_arc)
  1068. #else
  1069. [command release];
  1070. #endif
  1071. }
  1072. /**
  1073. * postGetDataEditingTriggerStartsBy
  1074. *
  1075. * Get the Data Editing profile Trigger Starts by string for the decoded Data
  1076. *
  1077. * @param profile to retrieve the trigger Starts by
  1078. */
  1079. -(void)postGetDataEditingTriggerStartsBy:(NSString*)profile Target:(id)target Response:(SEL)response{
  1080. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  1081. [[scanObj Property]setID:kSktScanPropIdDataEditingTriggerStartsBy];
  1082. [[scanObj Property]setType:kSktScanPropTypeString];
  1083. [[scanObj Property]setString:profile];
  1084. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  1085. ScanObj:scanObj
  1086. ScanDevice:_scanApi
  1087. Device:nil
  1088. Target:target
  1089. Response:response];
  1090. [self addCommand:command];
  1091. #if __has_feature(objc_arc)
  1092. #else
  1093. [command release];
  1094. #endif
  1095. }
  1096. /**
  1097. * postSetDataEditingTriggerStartsBy
  1098. *
  1099. * Set the Data Editing profile Trigger Starts by string for the decoded Data
  1100. *
  1101. * @param profileAndString contains the profile and Starts by string
  1102. */
  1103. -(void)postSetDataEditingTriggerStartsBy:(NSString*)profileAndString Target:(id)target Response:(SEL)response{
  1104. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  1105. [[scanObj Property]setID:kSktScanPropIdDataEditingTriggerStartsBy];
  1106. [[scanObj Property]setType:kSktScanPropTypeString];
  1107. [[scanObj Property]setString:profileAndString];
  1108. CommandContext* command=[[CommandContext alloc]initWithParam:FALSE
  1109. ScanObj:scanObj
  1110. ScanDevice:_scanApi
  1111. Device:nil
  1112. Target:target
  1113. Response:response];
  1114. [self addCommand:command];
  1115. #if __has_feature(objc_arc)
  1116. #else
  1117. [command release];
  1118. #endif
  1119. }
  1120. /**
  1121. * postGetDataEditingTriggerEndsWith
  1122. *
  1123. * Get the Data Editing profile Trigger Ends with string for the decoded Data
  1124. *
  1125. * @param profile to retrieve the trigger Ends with
  1126. */
  1127. -(void)postGetDataEditingTriggerEndsWith:(NSString*)profile Target:(id)target Response:(SEL)response{
  1128. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  1129. [[scanObj Property]setID:kSktScanPropIdDataEditingTriggerEndsWith];
  1130. [[scanObj Property]setType:kSktScanPropTypeString];
  1131. [[scanObj Property]setString:profile];
  1132. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  1133. ScanObj:scanObj
  1134. ScanDevice:_scanApi
  1135. Device:nil
  1136. Target:target
  1137. Response:response];
  1138. [self addCommand:command];
  1139. #if __has_feature(objc_arc)
  1140. #else
  1141. [command release];
  1142. #endif
  1143. }
  1144. /**
  1145. * postSetDataEditingTriggerEndsWith
  1146. *
  1147. * Set the Data Editing profile Trigger Ends with string for the decoded Data
  1148. *
  1149. * @param profileAndString contains the profile and the Ends With string
  1150. */
  1151. -(void)postSetDataEditingTriggerEndsWith:(NSString*)profileAndString Target:(id)target Response:(SEL)response{
  1152. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  1153. [[scanObj Property]setID:kSktScanPropIdDataEditingTriggerEndsWith];
  1154. [[scanObj Property]setType:kSktScanPropTypeString];
  1155. [[scanObj Property]setString:profileAndString];
  1156. CommandContext* command=[[CommandContext alloc]initWithParam:FALSE
  1157. ScanObj:scanObj
  1158. ScanDevice:_scanApi
  1159. Device:nil
  1160. Target:target
  1161. Response:response];
  1162. [self addCommand:command];
  1163. #if __has_feature(objc_arc)
  1164. #else
  1165. [command release];
  1166. #endif
  1167. }
  1168. /**
  1169. * postGetDataEditingTriggerContains
  1170. *
  1171. * Get the Data Editing profile Trigger Contains a string for the decoded Data
  1172. *
  1173. * @param profile to retrieve the trigger Contains string
  1174. */
  1175. -(void)postGetDataEditingTriggerContains:(NSString*)profile Target:(id)target Response:(SEL)response{
  1176. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  1177. [[scanObj Property]setID:kSktScanPropIdDataEditingTriggerContains];
  1178. [[scanObj Property]setType:kSktScanPropTypeString];
  1179. [[scanObj Property]setString:profile];
  1180. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  1181. ScanObj:scanObj
  1182. ScanDevice:_scanApi
  1183. Device:nil
  1184. Target:target
  1185. Response:response];
  1186. [self addCommand:command];
  1187. #if __has_feature(objc_arc)
  1188. #else
  1189. [command release];
  1190. #endif
  1191. }
  1192. /**
  1193. * postSetDataEditingTriggerContains
  1194. *
  1195. * Set the Data Editing profile Trigger Contains a string for the decoded Data
  1196. *
  1197. * @param profileAndString contains the profile and the Contains string
  1198. */
  1199. -(void)postSetDataEditingTriggerContains:(NSString*)profileAndString Target:(id)target Response:(SEL)response{
  1200. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  1201. [[scanObj Property]setID:kSktScanPropIdDataEditingTriggerContains];
  1202. [[scanObj Property]setType:kSktScanPropTypeString];
  1203. [[scanObj Property]setString:profileAndString];
  1204. CommandContext* command=[[CommandContext alloc]initWithParam:FALSE
  1205. ScanObj:scanObj
  1206. ScanDevice:_scanApi
  1207. Device:nil
  1208. Target:target
  1209. Response:response];
  1210. [self addCommand:command];
  1211. #if __has_feature(objc_arc)
  1212. #else
  1213. [command release];
  1214. #endif
  1215. }
  1216. /**
  1217. * postGetDataEditingOperations
  1218. *
  1219. * Get the Data Editing profile Operations applied to the decoded Data
  1220. *
  1221. * @param profile to retrieve the operations from
  1222. */
  1223. -(void)postGetDataEditingOperations:(NSString*)profile Target:(id)target Response:(SEL)response{
  1224. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  1225. [[scanObj Property]setID:kSktScanPropIdDataEditingOperation];
  1226. [[scanObj Property]setType:kSktScanPropTypeString];
  1227. [[scanObj Property]setString:profile];
  1228. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  1229. ScanObj:scanObj
  1230. ScanDevice:_scanApi
  1231. Device:nil
  1232. Target:target
  1233. Response:response];
  1234. [self addCommand:command];
  1235. #if __has_feature(objc_arc)
  1236. #else
  1237. [command release];
  1238. #endif
  1239. }
  1240. /**
  1241. * postSetDataEditingOperations
  1242. *
  1243. * Set the Data Editing profile Operations applied to the decoded Data
  1244. *
  1245. * @param profileAndOperation contains the profile and the operation to set to
  1246. */
  1247. -(void)postSetDataEditingOperations:(NSString*)profileAndOperations Target:(id)target Response:(SEL)response{
  1248. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  1249. [[scanObj Property]setID:kSktScanPropIdDataEditingOperation];
  1250. [[scanObj Property]setType:kSktScanPropTypeString];
  1251. [[scanObj Property]setString:profileAndOperations];
  1252. CommandContext* command=[[CommandContext alloc]initWithParam:FALSE
  1253. ScanObj:scanObj
  1254. ScanDevice:_scanApi
  1255. Device:nil
  1256. Target:target
  1257. Response:response];
  1258. [self addCommand:command];
  1259. #if __has_feature(objc_arc)
  1260. #else
  1261. [command release];
  1262. #endif
  1263. }
  1264. /**
  1265. * postGetDataEditingExport
  1266. *
  1267. * Export the Data Editing profile
  1268. *
  1269. * @param profile to export
  1270. */
  1271. -(void)postGetDataEditingExport:(NSString*)profile Target:(id)target Response:(SEL)response{
  1272. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  1273. [[scanObj Property]setID:kSktScanPropIdDataEditingImportExport];
  1274. [[scanObj Property]setType:kSktScanPropTypeString];
  1275. [[scanObj Property]setString:profile];
  1276. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  1277. ScanObj:scanObj
  1278. ScanDevice:_scanApi
  1279. Device:nil
  1280. Target:target
  1281. Response:response];
  1282. [self addCommand:command];
  1283. #if __has_feature(objc_arc)
  1284. #else
  1285. [command release];
  1286. #endif
  1287. }
  1288. /**
  1289. * postSetDataEditingImport
  1290. *
  1291. * Import the Data Editing profile
  1292. *
  1293. * @param profile to Import from
  1294. */
  1295. -(void)postSetDataEditingImport:(NSString*)profile Target:(id)target Response:(SEL)response{
  1296. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  1297. [[scanObj Property]setID:kSktScanPropIdDataEditingImportExport];
  1298. [[scanObj Property]setType:kSktScanPropTypeString];
  1299. [[scanObj Property]setString:profile];
  1300. CommandContext* command=[[CommandContext alloc]initWithParam:FALSE
  1301. ScanObj:scanObj
  1302. ScanDevice:_scanApi
  1303. Device:nil
  1304. Target:target
  1305. Response:response];
  1306. [self addCommand:command];
  1307. #if __has_feature(objc_arc)
  1308. #else
  1309. [command release];
  1310. #endif
  1311. }
  1312. /**
  1313. * postGetDeviceSpecific
  1314. *
  1315. * post a command specific to a certain type of scanner
  1316. * The command is usually a series of bytes that are understandable only
  1317. * by one particular type of scanner therefore the type of scanner must be
  1318. * checked prior calling this method
  1319. *
  1320. * @param deviceInfo to send the command to
  1321. * @param pCommand pointer to the bytes to send to the device
  1322. * @param length of the command in bytes
  1323. * @param target main object receiving the response
  1324. * @param response selector invoked when the response is received
  1325. */
  1326. -(void)postGetDeviceSpecific:(DeviceInfo*)deviceInfo Command:(unsigned char*)pCommand Length:(int) length Target:(id)target Response:(SEL) response{
  1327. ISktScanObject*scanObj=[SktClassFactory createScanObject];
  1328. [[scanObj Property]setID:kSktScanPropIdDeviceSpecific];
  1329. [[scanObj Property]setType:kSktScanPropTypeArray];
  1330. [[scanObj Property]setArray:pCommand Length:length];
  1331. CommandContext* command=[[CommandContext alloc]initWithParam:TRUE
  1332. ScanObj:scanObj
  1333. ScanDevice:[deviceInfo getSktScanDevice]
  1334. Device:deviceInfo
  1335. Target:target
  1336. Response:response];
  1337. [self addCommand:command];
  1338. #if __has_feature(objc_arc)
  1339. #else
  1340. [command release];
  1341. #endif
  1342. }
  1343. //#endif // SCANAPI_HELPER_DATAEDITING
  1344. /**
  1345. addCommand
  1346. add a command context into the list
  1347. */
  1348. -(void)addCommand:(CommandContext*)command{
  1349. if(_commandContexts==nil)
  1350. _commandContexts=[[NSMutableArray alloc]init];
  1351. @synchronized(_commandContextsLock){
  1352. if([[[command getScanObject]Property]getID]==kSktScanPropIdAbort)
  1353. [_commandContexts removeAllObjects];
  1354. [_commandContexts addObject:command];
  1355. }
  1356. }
  1357. /**
  1358. initializeScanAPIThread
  1359. This is a thread for creating and opening the first
  1360. instance of ScanAPI which causes ScanAPI to initialize
  1361. itself. This might be a lengthy operation which is why
  1362. it is done in a thread.
  1363. */
  1364. -(void) initializeScanAPIThread:(id)arg{
  1365. #if __has_feature(objc_arc)
  1366. @autoreleasepool {
  1367. #else
  1368. NSAutoreleasePool* pool=[[NSAutoreleasePool alloc]init];
  1369. #endif
  1370. // release the previous ScanAPI object instance if
  1371. // it exists
  1372. // if(_scanApi!=nil){
  1373. // [_scanApi close];
  1374. // [SktClassFactory releaseScanApiInstance:_scanApi];
  1375. // }
  1376. _scanApi=[SktClassFactory createScanApiInstance];
  1377. SKTRESULT result=[_scanApi open:nil];
  1378. if((_delegate!=nil)&&([_delegate respondsToSelector:@selector(onScanApiInitializeComplete:)]))
  1379. {
  1380. [_delegate onScanApiInitializeComplete:result];
  1381. }
  1382. _scanApiTerminated=FALSE;
  1383. #if __has_feature(objc_arc)
  1384. }
  1385. #else
  1386. [pool drain];
  1387. #endif
  1388. }
  1389. /**
  1390. * doScanApiReceive
  1391. *
  1392. * Call this function from your timer routine, so it
  1393. * will consume ScanAPI asyncrhonous event
  1394. *
  1395. * This function should be called after initializing
  1396. * ScanAPI by calling ScanApiHelper open function
  1397. * which will call the onScanApiInitializeComplete delegate
  1398. *
  1399. * IF THIS FUNCTION IS NOT CALLED, YOU WON'T RECEIVE
  1400. * ANY ASYNCHRONOUS EVENT FROM SCANAPI
  1401. */
  1402. -(SKTRESULT)doScanApiReceive{
  1403. SKTRESULT result=ESKT_NOERROR;
  1404. BOOL closeScanApi=FALSE;
  1405. if(_scanApiTerminated==FALSE)
  1406. {
  1407. result=[_scanApi waitForScanObject:_scanObjectReceived TimeOut:1];
  1408. if(SKTSUCCESS(result))
  1409. {
  1410. if(result!=ESKT_WAITTIMEOUT)
  1411. {
  1412. closeScanApi=[self handleScanObject:_scanObjectReceived];
  1413. [_scanApi releaseScanObject:_scanObjectReceived];
  1414. }
  1415. else
  1416. {
  1417. // see if there is a command to send
  1418. result=[self sendNextCommand];
  1419. }
  1420. if(closeScanApi==TRUE)
  1421. {
  1422. // we won't receive any scanObject from ScanAPI anymore
  1423. // so we can release the scanObject instance here
  1424. [SktClassFactory releaseScanObject:_scanObjectReceived];
  1425. _scanObjectReceived=nil;
  1426. [_scanApi close];
  1427. [SktClassFactory releaseScanApiInstance:_scanApi];
  1428. _scanApi=nil;
  1429. _scanApiTerminated=TRUE;
  1430. }
  1431. }
  1432. else
  1433. {
  1434. if((_delegate!=nil)&&([_delegate respondsToSelector:@selector(onErrorRetrievingScanObject:)])){
  1435. [_delegate onErrorRetrievingScanObject:result];
  1436. }
  1437. }
  1438. }
  1439. else
  1440. #ifdef DEBUG
  1441. NSLog(@"scanApiTerminated");
  1442. #endif
  1443. ;
  1444. return result;
  1445. }
  1446. /**
  1447. * handleScanObject
  1448. *
  1449. * Call this function from your timer routine, so it
  1450. * will consume ScanAPI asyncrhonous event
  1451. */
  1452. -(BOOL)handleScanObject:(ISktScanObject*)scanObj{
  1453. BOOL closeScanApi=FALSE;
  1454. SKTRESULT result=ESKT_NOERROR;
  1455. switch([[scanObj Msg]MsgID]){
  1456. case kSktScanMsgIdDeviceArrival:
  1457. result=[self handleDeviceArrival:scanObj];
  1458. break;
  1459. case kSktScanMsgIdDeviceRemoval:
  1460. result=[self handleDeviceRemoval:scanObj];
  1461. break;
  1462. case kSktScanMsgIdTerminate:
  1463. if((_delegate!=nil)&&([_delegate respondsToSelector:@selector(onScanApiTerminated)])){
  1464. [_delegate onScanApiTerminated];
  1465. }
  1466. closeScanApi=TRUE;
  1467. break;
  1468. case kSktScanMsgSetComplete:
  1469. case kSktScanMsgGetComplete:
  1470. result=[self handleSetOrGetComplete:scanObj];
  1471. break;
  1472. case kSktScanMsgEvent:
  1473. result=[self handleEvent:scanObj];
  1474. break;
  1475. case kSktScanMsgIdNotInitialized:
  1476. case kSktScanMsgLastID:
  1477. default:
  1478. break;
  1479. }
  1480. // if there is an error then report it to the ScanAPIHelper user
  1481. if(!SKTSUCCESS(result)){
  1482. if((_delegate!=nil)&&([_delegate respondsToSelector:@selector(onError:)])){
  1483. #ifdef TEST_SCAN
  1484. UIApplication * app = [UIApplication sharedApplication];
  1485. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1486. NSString* str = [NSString stringWithFormat:@"handleScanObject error msgid:%d",[[scanObj Msg]MsgID]];
  1487. [appDelegate addlog:str];
  1488. #endif
  1489. [_delegate onError:result];
  1490. }
  1491. }
  1492. return closeScanApi;
  1493. }
  1494. /**
  1495. * handleDeviceArrival
  1496. * This is called when a scanner connects to the host.
  1497. *
  1498. * This function create a new DeviceInfo object and add it
  1499. * to the list and open the scanner so that it is ready to be
  1500. * used, and then notify the ScanApiHelper user a new
  1501. * scanner has connected
  1502. */
  1503. -(SKTRESULT)handleDeviceArrival:(ISktScanObject*)scanObj{
  1504. SKTRESULT result=ESKT_NOERROR;
  1505. ISktScanDevice* scanDevice=[SktClassFactory createDeviceInstance:_scanApi];
  1506. NSString* name=[[scanObj Msg]DeviceName];
  1507. NSString* guid=[[scanObj Msg]DeviceGuid];
  1508. long type=[[scanObj Msg]DeviceType];
  1509. // create a new DeviceInfo object
  1510. DeviceInfo* deviceInfo=[[DeviceInfo alloc]init:scanDevice name:name type:type];
  1511. // open the scanner which means that we can now receive
  1512. // any event (such as DecodedData event) from this scanner
  1513. result=[scanDevice open:guid];
  1514. if(SKTSUCCESS(result)){
  1515. if(_noDeviceText!=nil)
  1516. [_deviceInfoList removeObjectForKey:_noDeviceText];
  1517. // add the device info into the list
  1518. [_deviceInfoList setValue:deviceInfo forKey:[NSString stringWithFormat:@"%@",scanDevice]];
  1519. }
  1520. // notify the ScanApiHelper user a scanner has connected to this host
  1521. if((_delegate!=nil)&&([_delegate respondsToSelector:@selector(onDeviceArrival:device:)])){
  1522. [_delegate onDeviceArrival:result device:deviceInfo];
  1523. }
  1524. #if __has_feature(objc_arc)
  1525. #else
  1526. [deviceInfo release];// we don't keep this object since we couldn't open the scanner
  1527. #endif
  1528. return result;
  1529. }
  1530. /**
  1531. * handleDeviceRemoval
  1532. * This function is called when a scanner disconnects or
  1533. * when ScanAPI is shutting down after the Abort property has been set
  1534. *
  1535. * This function remove the device info from the list and notify
  1536. * the ScanApiHelper user that a scanner has been disconnected
  1537. * All the pending commands for this scanner are removed from the list.
  1538. */
  1539. -(SKTRESULT)handleDeviceRemoval:(ISktScanObject*)scanObj{
  1540. SKTRESULT result=ESKT_NOERROR;
  1541. ISktScanDevice* scanDevice=[[scanObj Msg]hDevice];
  1542. // retrieve the DeviceInfo object from the list
  1543. DeviceInfo* deviceInfo=[self getDeviceInfoFromScanObject:scanObj];
  1544. // if there is a text provided when no device is connected
  1545. // then if the list is empty that's the time to add this text in the list
  1546. if(_noDeviceText!=nil){
  1547. if([_deviceInfoList count]==0)
  1548. [_deviceInfoList setObject:_noDeviceText forKey:_noDeviceText];
  1549. }
  1550. // remove all the pending commands from the list for this scanner
  1551. [self removeCommand:deviceInfo];
  1552. [_deviceInfoList setValue:nil forKey:[NSString stringWithFormat:@"%@",scanDevice]];
  1553. //[_deviceInfoList removeAllObjects];
  1554. // close the scanner and release its instance
  1555. result=[scanDevice close];
  1556. [SktClassFactory releaseDeviceInstance:scanDevice];
  1557. // notify the ScanApiHelper user a scanner has connected to this host
  1558. if((_delegate!=nil)&&([_delegate respondsToSelector:@selector(onDeviceRemoval:)])){
  1559. [_delegate onDeviceRemoval:deviceInfo];
  1560. }
  1561. return result;
  1562. }
  1563. /**
  1564. * handleSetOrGetComplete
  1565. *
  1566. * handles both Set or Get complete property events
  1567. *
  1568. */
  1569. -(SKTRESULT)handleSetOrGetComplete:(ISktScanObject*)scanObj{
  1570. SKTRESULT result=ESKT_NOERROR;
  1571. BOOL doCallback=TRUE;
  1572. // retrieve the error for this complete event
  1573. result=[[scanObj Msg]Result];
  1574. CommandContext* commandContext=(CommandContext*)[[scanObj Property]getContext];
  1575. if(commandContext!=nil){
  1576. // only if there is a timeout error then retry the command
  1577. if(!SKTSUCCESS(result)){
  1578. if(result==ESKT_REQUESTTIMEDOUT){
  1579. if([commandContext retry]<CMD_MAX_RETRY){
  1580. doCallback=FALSE;// just retry without calling the command callback
  1581. }
  1582. }
  1583. }
  1584. if(doCallback==TRUE){
  1585. // the result will be NO_ERROR if the callback has been called
  1586. // and will be whatever result code we have in ScanObject if
  1587. // there is no callback
  1588. [commandContext doCallback:scanObj];
  1589. @synchronized(_commandContextsLock){
  1590. [_commandContexts removeObject:commandContext];
  1591. }
  1592. // the release has been done in the removeObject method
  1593. commandContext=nil;
  1594. }
  1595. else
  1596. [commandContext setStatus:statusReady];
  1597. }
  1598. // send the next command if there is one
  1599. result=[self sendNextCommand];
  1600. return result;
  1601. }
  1602. /**
  1603. * handleEvent
  1604. *
  1605. * handles all events received from ScanAPI
  1606. *
  1607. */
  1608. -(SKTRESULT)handleEvent:(ISktScanObject*)scanObj{
  1609. SKTRESULT result=ESKT_NOERROR;
  1610. switch([[[scanObj Msg]Event]ID]){
  1611. case kSktScanEventDecodedData:
  1612. result=[self handleDecodedData:scanObj];
  1613. break;
  1614. case kSktScanEventError:
  1615. if((_delegate!=nil)&&([_delegate respondsToSelector:@selector(onError:)]))
  1616. {
  1617. #ifdef TEST_SCAN
  1618. UIApplication * app = [UIApplication sharedApplication];
  1619. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1620. NSString* str = [NSString stringWithFormat:@"handleEvent error msgid:%d",[[scanObj Msg]MsgID]];
  1621. [appDelegate addlog:str];
  1622. #endif
  1623. [_delegate onError:[[scanObj Msg]Result]];
  1624. }
  1625. break;
  1626. case kSktScanEventListenerStarted:
  1627. break;
  1628. case kSktScanEventPower:
  1629. break;
  1630. case kSktScanEventLastID:
  1631. default:
  1632. break;
  1633. }
  1634. return result;
  1635. }
  1636. /**
  1637. * handleDecodedData
  1638. *
  1639. * call the delegate with decoded data
  1640. */
  1641. -(SKTRESULT)handleDecodedData:(ISktScanObject*)scanObj{
  1642. SKTRESULT result=ESKT_NOERROR;
  1643. result=[[scanObj Msg]Result];
  1644. DeviceInfo* deviceInfo=[self getDeviceInfoFromScanObject:scanObj];
  1645. if(_delegate!=nil){
  1646. if([_delegate respondsToSelector:@selector(onDecodedDataResult:device:decodedData:)]==YES){
  1647. [_delegate onDecodedDataResult:result device:deviceInfo decodedData:[[[scanObj Msg]Event]getDataDecodedData]];
  1648. }
  1649. else{
  1650. // call only in case of no error the legacy onDecodedData:
  1651. if(SKTSUCCESS(result)){
  1652. if([_delegate respondsToSelector:@selector(onDecodedData:decodedData:)]==YES){
  1653. [_delegate onDecodedData:deviceInfo decodedData:[[[scanObj Msg]Event]getDataDecodedData]];
  1654. }
  1655. }
  1656. }
  1657. }
  1658. // in case the user cancel the softscan
  1659. // we don't want to report this as an error
  1660. if(result==ESKT_CANCEL)
  1661. result=ESKT_NOERROR;
  1662. return result;
  1663. }
  1664. /**
  1665. * sendNextCommand
  1666. *
  1667. * sends the next command if there is one in the list
  1668. */
  1669. -(SKTRESULT)sendNextCommand{
  1670. SKTRESULT result=ESKT_NOERROR;
  1671. @synchronized(_commandContextsLock){
  1672. ISktScanDevice* lastDevice=nil;
  1673. int count=(int)[_commandContexts count];
  1674. if(count>0){
  1675. for(int i=0;i<count;i++){
  1676. CommandContext* newCommand=[_commandContexts objectAtIndex:i];
  1677. if([newCommand status]==statusReady){
  1678. result=[newCommand doCommand];
  1679. if(!SKTSUCCESS(result)){
  1680. ISktScanDevice*currentDevice=[newCommand getScanDevice];
  1681. #ifdef DEBUG
  1682. NSLog(@"Remove the command/property because we failed to send it");
  1683. #endif
  1684. [_commandContexts removeObject:newCommand];
  1685. i--;// the current command has been removed so stay at the same index
  1686. count--;
  1687. // the release has been done in the removeObject method
  1688. newCommand=nil;
  1689. // if there is an error and the last device
  1690. // we reported an error is not this one then
  1691. // report the error to the app. This is to
  1692. // avoid reporting multiple time an error because
  1693. // a particular device might be disconnected
  1694. if((_delegate!=nil)&&(lastDevice!=currentDevice)){
  1695. #ifdef TEST_SCAN
  1696. UIApplication * app = [UIApplication sharedApplication];
  1697. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1698. NSString* str = [NSString stringWithFormat:@"sendNextCommand error commond:%d",[[[newCommand getScanObject] Msg]MsgID]];
  1699. [appDelegate addlog:str];
  1700. #endif
  1701. [_delegate onError:result];// report an error but continue
  1702. lastDevice=currentDevice;
  1703. }
  1704. }
  1705. else{
  1706. break;
  1707. }
  1708. }
  1709. else
  1710. break;
  1711. }
  1712. }
  1713. }
  1714. return result;
  1715. }
  1716. /**
  1717. * generateDeviceArrivals
  1718. *
  1719. * internal function to generate device
  1720. * arrival notifications when the delegate
  1721. * change to a new delegate.
  1722. * This is used in a multi views application
  1723. * that has more than one view to receive the
  1724. * decoded data
  1725. */
  1726. -(void)generateDeviceArrivals{
  1727. // generate a device Arrival for each scanner we've already receive
  1728. // so that the new view can be aware of the connected scanners
  1729. if(_delegate!=nil && [_delegate respondsToSelector:@selector(onDeviceArrival:device:)]){
  1730. for (NSString* key in _deviceInfoList) {
  1731. DeviceInfo* device=[_deviceInfoList objectForKey:key];
  1732. [_delegate onDeviceArrival:ESKT_NOERROR device:device];
  1733. }
  1734. }
  1735. }
  1736. @end