1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | #include "syncml_tk_prefix_file.h" // %%% luz: needed for precompiled headers in eVC++ |
53 | |
54 | |
55 | #include <smldef.h> |
56 | #include <sml.h> |
57 | #include <smlerr.h> |
58 | #include "libmem.h" |
59 | #include "libstr.h" |
60 | #include "liblock.h" |
61 | #include "wsm.h" |
62 | #include "mgr.h" |
63 | #include <xltenc.h> |
64 | |
65 | |
66 | |
67 | |
68 | #ifndef NOWSM1 |
69 | #ifndef __SML_LITE__ /* Only ONE instance is supported in the Toolkit lite version */ |
70 | extern Ret_t addInfo(InstanceInfoPtr_t pInfo); |
71 | extern InstanceInfoPtr_t findInfo(InstanceID_t id); |
72 | extern Ret_t removeInfo(InstanceID_t id); |
73 | #endif |
74 | SyncMLInfoPtr_t mgrGetSyncMLAnchor(void); |
75 | #endif |
76 | |
77 | |
78 | SML_API Ret_t smlInitInstance(SmlCallbacksCPtr_t callbacks, SmlInstanceOptionsPtr_t pOptions, VoidPtr_t pUserData, InstanceID_t *pInstanceID); |
79 | SML_API Ret_t smlTerminateInstance (InstanceID_t id); |
80 | SML_API Ret_t smlLockReadBuffer(InstanceID_t id, MemPtr_t *pReadPosition, MemSize_t *usedSize); |
81 | SML_API Ret_t smlUnlockReadBuffer(InstanceID_t id, MemSize_t processedBytes); |
82 | #ifdef NOWSM1 |
83 | SML_API Ret_t smlSetMaxOutgoingSize(InstanceID_t id, MemSize_t maxOutgoingSize); |
84 | SML_API Ret_t smlSetOutgoingBegin(InstanceID_t id); |
85 | #endif |
86 | SML_API Ret_t smlLockWriteBuffer(InstanceID_t id, MemPtr_t *pWritePosition, MemSize_t *freeSize); |
87 | SML_API Ret_t smlUnlockWriteBuffer(InstanceID_t id, MemSize_t writtenBytes); |
88 | SML_API Ret_t smlSetCallbacks (InstanceID_t id, SmlCallbacksCPtr_t pCallbacks); |
89 | SML_API Ret_t smlSetUserData (InstanceID_t id, VoidPtr_t pUserData); |
90 | |
91 | SML_API Ret_t smlGetUserData(InstanceID_t id, VoidPtr_t *ppUserData); |
92 | SML_API Ret_t smlGetEncoding(InstanceID_t id, SmlEncoding_t *pEncoding); |
93 | #ifndef __SML_LITE__ /* these API calls are NOT included in the Toolkit lite version */ |
94 | SML_API Ret_t smlSetEncoding (InstanceID_t id, SmlEncoding_t encoding); |
95 | #endif |
96 | |
97 | |
98 | |
99 | |
100 | Ret_t freeInstanceOptions (InstanceInfoPtr_t pInstanceInfo); |
101 | static Ret_t freeInstanceInfo (InstanceInfoPtr_t pInfo); |
102 | Ret_t mgrResetWorkspace (InstanceID_t id); |
103 | Ret_t setInstanceOptions (InstanceID_t id, SmlInstanceOptionsPtr_t pOptions); |
104 | |
105 | |
106 | |
107 | |
108 | |
109 | |
110 | |
111 | |
112 | |
113 | |
114 | |
115 | |
116 | |
117 | |
118 | |
119 | |
120 | |
121 | |
122 | |
123 | |
124 | |
125 | |
126 | |
127 | |
128 | |
129 | |
130 | |
131 | |
132 | |
133 | |
134 | |
135 | |
136 | |
137 | |
138 | |
139 | SML_API Ret_t smlInitInstance(SmlCallbacksCPtr_t pCallbacks, SmlInstanceOptionsPtr_t pOptions, VoidPtr_t pUserData, InstanceID_t *pInstanceID) |
140 | { |
141 | |
142 | |
143 | InstanceInfoPtr_t pInstanceInfo; |
144 | Ret_t rc; |
145 | |
146 | |
147 | #ifndef NOWSM1 |
148 | |
149 | if (!pOptions || !pOptions->workspaceName) |
150 | return SML_ERR_WRONG_USAGE0x13; |
151 | |
152 | #ifdef __SML_LITE__ /* Only ONE instance is supported in the Toolkit lite version */ |
153 | |
154 | if (mgrGetInstanceListAnchor()!=NULL((void*)0)) |
155 | return SML_ERR_WRONG_USAGE0x13; |
156 | #endif |
157 | |
158 | |
159 | #ifdef __SML_LITE__ /* Only ONE instance is supported in the Toolkit lite version */ |
160 | pInstanceInfo = mgrGetInstanceListAnchor(); |
161 | #else |
162 | pInstanceInfo = (InstanceInfoPtr_t) findInfo(*pInstanceID); |
163 | #endif |
164 | |
165 | |
166 | if (pInstanceInfo != NULL((void*)0)) return SML_ERR_WRONG_USAGE0x13; |
167 | |
168 | |
169 | |
170 | LOCKTOOLKIT("smlInitInstance"); |
171 | if ((rc = wsmCreate(pOptions->workspaceName, pOptions->workspaceSize, pInstanceID)) != SML_ERR_OK0x00) { |
172 | RELEASETOOLKIT("smlInitInstance after wsmCreate failure"); |
173 | return rc; |
174 | } |
175 | RELEASETOOLKIT("smlInitInstance"); |
176 | #else // NOWSM |
177 | |
178 | if (!pOptions || !pOptions->workspaceSize) |
| 1 | Assuming 'pOptions' is non-null | |
|
| 2 | | Assuming the condition is false | |
|
| |
179 | return SML_ERR_WRONG_USAGE0x13; |
180 | |
181 | rc=SML_ERR_OK0x00; |
182 | #endif |
183 | |
184 | |
185 | pInstanceInfo = (InstanceInfoPtr_t)smlLibMalloc((MemSize_t)sizeof(InstanceInfo_t)); |
| 4 | | Value assigned to 'pInstanceInfo' | |
|
186 | if (pInstanceInfo==NULL((void*)0)) { |
| 5 | | Assuming 'pInstanceInfo' is equal to NULL | |
|
| |
187 | #ifndef NOWSM1 |
188 | wsmDestroy(pOptions->workspaceName); |
189 | return SML_ERR_NOT_ENOUGH_SPACE0x11; |
190 | #endif |
191 | } |
192 | #ifdef NOWSM1 |
193 | else { |
194 | |
195 | *pInstanceID = (InstanceID_t)pInstanceInfo; |
196 | } |
197 | #endif |
198 | |
199 | smlLibMemset(pInstanceInfo,0,(MemSize_t)sizeof(InstanceInfo_t)); |
200 | |
201 | |
202 | |
203 | |
204 | pInstanceInfo->status=MGR_IDLE; |
| 7 | | Access to field 'status' results in a dereference of a null pointer (loaded from variable 'pInstanceInfo') |
|
205 | pInstanceInfo->encoderState=NULL((void*)0); |
206 | pInstanceInfo->decoderState=NULL((void*)0); |
207 | #ifndef NOWSM1 |
208 | pInstanceInfo->id=*pInstanceID; |
209 | pInstanceInfo->workspaceState=NULL((void*)0); |
210 | pInstanceInfo->nextInfo=NULL((void*)0); |
211 | #else |
212 | |
213 | pInstanceInfo->instanceBufSiz=pOptions->workspaceSize; |
214 | pInstanceInfo->maxOutgoingSize=pOptions->maxOutgoingSize; |
215 | pInstanceInfo->instanceBuffer=smlLibMalloc(pInstanceInfo->instanceBufSiz); |
216 | if (pInstanceInfo->instanceBuffer==NULL((void*)0)) |
217 | return SML_ERR_NOT_ENOUGH_SPACE0x11; |
218 | |
219 | pInstanceInfo->readPointer=pInstanceInfo->instanceBuffer; |
220 | pInstanceInfo->writePointer=pInstanceInfo->instanceBuffer; |
221 | pInstanceInfo->readLocked=0; |
222 | pInstanceInfo->writeLocked=0; |
223 | pInstanceInfo->outgoingMsgStart=NULL((void*)0); |
224 | pInstanceInfo->incomingMsgStart=NULL((void*)0); |
225 | #endif |
226 | |
227 | |
228 | #ifndef NOWSM1 |
229 | |
230 | #ifdef __SML_LITE__ /* Only ONE instance is supported in the Toolkit lite version */ |
231 | mgrSetInstanceListAnchor(pInstanceInfo); |
232 | #else |
233 | rc = addInfo( pInstanceInfo ); |
234 | if (rc!=SML_ERR_OK0x00) return rc; |
235 | #endif |
236 | #endif |
237 | |
238 | |
239 | |
240 | |
241 | |
242 | pInstanceInfo->userData=pUserData; |
243 | |
244 | if (smlSetCallbacks(*pInstanceID, pCallbacks) != SML_ERR_OK0x00) { |
245 | #ifndef NOWSM1 |
246 | wsmDestroy(pOptions->workspaceName); |
247 | #endif |
248 | return rc; |
249 | } |
250 | |
251 | |
252 | |
253 | |
254 | |
255 | if (setInstanceOptions (*pInstanceID, pOptions) != SML_ERR_OK0x00) { |
256 | #ifndef NOWSM1 |
257 | wsmDestroy(pOptions->workspaceName); |
258 | #endif |
259 | return rc; |
260 | } |
261 | |
262 | return SML_ERR_OK0x00; |
263 | |
264 | } |
265 | |
266 | |
267 | |
268 | |
269 | |
270 | |
271 | |
272 | |
273 | |
274 | |
275 | |
276 | |
277 | SML_API Ret_t smlTerminateInstance (InstanceID_t id) |
278 | { |
279 | |
280 | |
281 | InstanceInfoPtr_t pInstanceInfo; |
282 | |
283 | #ifdef NOWSM1 |
284 | pInstanceInfo = (InstanceInfoPtr_t)id; |
285 | #else |
286 | Ret_t rc; |
287 | |
288 | |
289 | #ifdef __SML_LITE__ /* Only ONE instance is supported in the Toolkit lite version */ |
290 | pInstanceInfo = mgrGetInstanceListAnchor(); |
291 | #else |
292 | pInstanceInfo = (InstanceInfoPtr_t) findInfo(id); |
293 | #endif |
294 | #endif |
295 | |
296 | if (pInstanceInfo==NULL((void*)0)) return SML_ERR_MGR_INVALID_INSTANCE_INFO0x1002; |
297 | |
298 | #ifndef NOWSM1 |
299 | |
300 | if (pInstanceInfo->instanceOptions != NULL((void*)0)) { |
301 | LOCKTOOLKIT("smlTerminateInstance"); |
302 | rc = wsmDestroy(pInstanceInfo->instanceOptions->workspaceName); |
303 | RELEASETOOLKIT("smlTerminateInstance"); |
304 | if (rc!=SML_ERR_OK0x00) { |
305 | |
306 | return rc; |
307 | } |
308 | } |
309 | |
310 | |
311 | #ifdef __SML_LITE__ /* Only ONE instance is supported in the Toolkit lite version */ |
312 | mgrSetInstanceListAnchor(NULL((void*)0)); |
313 | #else |
314 | removeInfo(id); |
315 | #endif |
316 | #endif |
317 | |
318 | freeInstanceInfo (pInstanceInfo); |
319 | |
320 | return SML_ERR_OK0x00; |
321 | } |
322 | |
323 | |
324 | |
325 | |
326 | |
327 | |
328 | |
329 | |
330 | |
331 | |
332 | |
333 | |
334 | |
335 | |
336 | SML_API Ret_t smlSetCallbacks(InstanceID_t id, SmlCallbacksCPtr_t pCallbacks) |
337 | { |
338 | |
339 | |
340 | InstanceInfoPtr_t pInstanceInfo; |
341 | SmlCallbacksPtr_t pCallbacksCopy; |
342 | |
343 | |
344 | if (!pCallbacks) |
345 | return SML_ERR_WRONG_USAGE0x13; |
346 | |
347 | |
348 | #ifdef NOWSM1 |
349 | pInstanceInfo = (InstanceInfoPtr_t)id; |
350 | #else |
351 | |
352 | #ifdef __SML_LITE__ /* Only ONE instance is supported in the Toolkit lite version */ |
353 | pInstanceInfo = mgrGetInstanceListAnchor(); |
354 | #else |
355 | pInstanceInfo = (InstanceInfoPtr_t) findInfo(id); |
356 | #endif |
357 | |
358 | if (pInstanceInfo==NULL((void*)0)) return SML_ERR_MGR_INVALID_INSTANCE_INFO0x1002; |
359 | #endif |
360 | |
361 | |
362 | smlLibFree(pInstanceInfo->callbacks); |
363 | |
364 | |
365 | |
366 | pCallbacksCopy = (SmlCallbacksPtr_t)smlLibMalloc((MemSize_t)sizeof(SmlCallbacks_t)); |
367 | if (pCallbacksCopy==NULL((void*)0)) return SML_ERR_NOT_ENOUGH_SPACE0x11; |
368 | smlLibMemcpy(pCallbacksCopy,pCallbacks,(MemSize_t)sizeof(SmlCallbacks_t)); |
369 | |
370 | |
371 | |
372 | pInstanceInfo->callbacks = pCallbacksCopy; |
373 | |
374 | return SML_ERR_OK0x00; |
375 | } |
376 | |
377 | |
378 | |
379 | |
380 | |
381 | |
382 | |
383 | |
384 | |
385 | |
386 | |
387 | |
388 | |
389 | |
390 | |
391 | |
392 | |
393 | |
394 | |
395 | |
396 | SML_API Ret_t smlSetUserData(InstanceID_t id, VoidPtr_t pUserData) |
397 | { |
398 | |
399 | |
400 | InstanceInfoPtr_t pInstanceInfo; |
401 | |
402 | |
403 | #ifdef NOWSM1 |
404 | pInstanceInfo = (InstanceInfoPtr_t)id; |
405 | #else |
406 | |
407 | #ifdef __SML_LITE__ /* Only ONE instance is supported in the Toolkit lite version */ |
408 | pInstanceInfo = mgrGetInstanceListAnchor(); |
409 | #else |
410 | pInstanceInfo = (InstanceInfoPtr_t) findInfo(id); |
411 | #endif |
412 | #endif |
413 | |
414 | if (pInstanceInfo==NULL((void*)0)) return SML_ERR_MGR_INVALID_INSTANCE_INFO0x1002; |
415 | |
416 | |
417 | |
418 | pInstanceInfo->userData=pUserData; |
419 | |
420 | return SML_ERR_OK0x00; |
421 | } |
422 | |
423 | |
424 | |
425 | |
426 | |
427 | |
428 | |
429 | |
430 | |
431 | |
432 | |
433 | |
434 | |
435 | |
436 | SML_API Ret_t smlGetUserData(InstanceID_t id, VoidPtr_t *ppUserData) |
437 | { |
438 | |
439 | |
440 | InstanceInfoPtr_t pInstanceInfo; |
441 | |
442 | #ifdef NOWSM1 |
443 | pInstanceInfo = (InstanceInfoPtr_t)id; |
444 | #else |
445 | |
446 | #ifdef __SML_LITE__ /* Only ONE instance is supported in the Toolkit lite version */ |
447 | pInstanceInfo = mgrGetInstanceListAnchor(); |
448 | #else |
449 | pInstanceInfo = (InstanceInfoPtr_t) findInfo(id); |
450 | #endif |
451 | #endif |
452 | |
453 | if (pInstanceInfo==NULL((void*)0)) return SML_ERR_MGR_INVALID_INSTANCE_INFO0x1002; |
454 | |
455 | |
456 | |
457 | *ppUserData = pInstanceInfo->userData; |
458 | |
459 | return SML_ERR_OK0x00; |
460 | } |
461 | |
462 | |
463 | |
464 | |
465 | |
466 | |
467 | |
468 | |
469 | |
470 | |
471 | |
472 | |
473 | |
474 | SML_API Ret_t smlGetEncoding(InstanceID_t id, SmlEncoding_t *pEncoding) |
475 | { |
476 | |
477 | |
478 | InstanceInfoPtr_t pInstanceInfo; |
479 | |
480 | #ifdef NOWSM1 |
481 | pInstanceInfo = (InstanceInfoPtr_t)id; |
482 | #else |
483 | |
484 | #ifdef __SML_LITE__ /* Only ONE instance is supported in the Toolkit lite version */ |
485 | pInstanceInfo = mgrGetInstanceListAnchor(); |
486 | #else |
487 | pInstanceInfo = (InstanceInfoPtr_t) findInfo(id); |
488 | #endif |
489 | #endif |
490 | |
491 | if (pInstanceInfo==NULL((void*)0)) return SML_ERR_MGR_INVALID_INSTANCE_INFO0x1002; |
492 | |
493 | |
494 | *pEncoding = pInstanceInfo->instanceOptions->encoding; |
495 | |
496 | return SML_ERR_OK0x00; |
497 | } |
498 | |
499 | |
500 | |
501 | |
502 | |
503 | |
504 | |
505 | |
506 | |
507 | |
508 | |
509 | |
510 | #ifndef __SML_LITE__ /* these API calls are NOT included in the Toolkit lite version */ |
511 | SML_API Ret_t smlSetEncoding(InstanceID_t id, SmlEncoding_t encoding) |
512 | { |
513 | |
514 | |
515 | InstanceInfoPtr_t pInstanceInfo; |
516 | |
517 | |
518 | if (encoding==SML_UNDEF) |
519 | return SML_ERR_WRONG_USAGE0x13; |
520 | |
521 | |
522 | #ifdef NOWSM1 |
523 | pInstanceInfo = (InstanceInfoPtr_t)id; |
524 | #else |
525 | |
526 | #ifdef __SML_LITE__ /* Only ONE instance is supported in the Toolkit lite version */ |
527 | pInstanceInfo = mgrGetInstanceListAnchor(); |
528 | #else |
529 | pInstanceInfo = (InstanceInfoPtr_t) findInfo(id); |
530 | #endif |
531 | #endif |
532 | |
533 | if (pInstanceInfo==NULL((void*)0)) return SML_ERR_MGR_INVALID_INSTANCE_INFO0x1002; |
534 | |
535 | |
536 | |
537 | pInstanceInfo->instanceOptions->encoding = encoding; |
538 | |
539 | return SML_ERR_OK0x00; |
540 | } |
541 | #endif |
542 | |
543 | |
544 | |
545 | |
546 | |
547 | |
548 | |
549 | |
550 | |
551 | |
552 | |
553 | |
554 | |
555 | |
556 | |
557 | |
558 | |
559 | |
560 | |
561 | |
562 | |
563 | |
564 | |
565 | |
566 | |
567 | |
568 | |
569 | SML_API Ret_t smlLockReadBuffer(InstanceID_t id, MemPtr_t *pReadPosition, MemSize_t *usedSize) |
570 | { |
571 | #ifdef NOWSM1 |
572 | InstanceInfoPtr_t pInstanceInfo; |
573 | |
574 | pInstanceInfo = (InstanceInfoPtr_t)id; |
575 | if (pInstanceInfo==NULL((void*)0)) return SML_ERR_MGR_INVALID_INSTANCE_INFO0x1002; |
576 | |
577 | if (pInstanceInfo->readLocked) |
578 | return SML_ERR_WRONG_USAGE0x13; |
579 | |
580 | *pReadPosition = pInstanceInfo->readPointer; |
581 | |
582 | *usedSize = pInstanceInfo->writePointer-pInstanceInfo->readPointer; |
583 | |
584 | pInstanceInfo->readLocked=1; |
585 | #else |
586 | Ret_t rc; |
587 | |
588 | LOCKTOOLKIT("smlLockReadBuffer"); |
589 | |
590 | rc = wsmLockH(id, SML_FIRST_DATA_ITEM, pReadPosition); |
591 | RELEASETOOLKIT("smlLockReadBuffer"); |
592 | if (rc!=SML_ERR_OK0x00) return rc; |
593 | |
594 | |
595 | LOCKTOOLKIT("smlLockReadBuffer"); |
596 | rc = wsmGetUsedSize(id,usedSize); |
597 | RELEASETOOLKIT("smlLockReadBuffer"); |
598 | if (rc!=SML_ERR_OK0x00) return rc; |
599 | #endif |
600 | |
601 | return SML_ERR_OK0x00; |
602 | } |
603 | |
604 | |
605 | |
606 | |
607 | |
608 | |
609 | |
610 | |
611 | |
612 | |
613 | |
614 | |
615 | |
616 | |
617 | |
618 | |
619 | |
620 | |
621 | |
622 | SML_API Ret_t smlUnlockReadBuffer(InstanceID_t id, MemSize_t processedBytes) |
623 | { |
624 | #ifdef NOWSM1 |
625 | InstanceInfoPtr_t pInstanceInfo; |
626 | |
627 | pInstanceInfo = (InstanceInfoPtr_t)id; |
628 | if (pInstanceInfo==NULL((void*)0)) return SML_ERR_MGR_INVALID_INSTANCE_INFO0x1002; |
629 | |
630 | if (!pInstanceInfo->readLocked) |
631 | return SML_ERR_WRONG_USAGE0x13; |
632 | |
633 | if (pInstanceInfo->readPointer+processedBytes>pInstanceInfo->writePointer) |
634 | return SML_ERR_WRONG_USAGE0x13; |
635 | |
636 | pInstanceInfo->readPointer+=processedBytes; |
637 | |
638 | |
639 | |
640 | |
641 | |
642 | |
643 | |
644 | |
645 | |
646 | pInstanceInfo->readLocked=0; |
647 | #else |
648 | Ret_t rc; |
649 | |
650 | |
651 | LOCKTOOLKIT("smlUnlockReadBuffer"); |
652 | rc = wsmProcessedBytes (id,processedBytes); |
653 | RELEASETOOLKIT("smlUnlockReadBuffer"); |
654 | if (rc!=SML_ERR_OK0x00) return rc; |
655 | |
656 | |
657 | LOCKTOOLKIT("smlUnlockReadBuffer"); |
658 | rc = wsmUnlockH(id); |
659 | RELEASETOOLKIT("smlUnlockReadBuffer"); |
660 | if (rc!=SML_ERR_OK0x00) return rc; |
661 | #endif |
662 | |
663 | return SML_ERR_OK0x00; |
664 | } |
665 | |
666 | |
667 | #ifdef NOWSM1 |
668 | |
669 | |
670 | |
671 | |
672 | |
673 | |
674 | |
675 | |
676 | |
677 | |
678 | |
679 | |
680 | SML_API Ret_t smlSetMaxOutgoingSize(InstanceID_t id, MemSize_t maxOutgoingSize) |
681 | { |
682 | InstanceInfoPtr_t pInstanceInfo; |
683 | |
684 | pInstanceInfo = (InstanceInfoPtr_t)id; |
685 | if (pInstanceInfo==NULL((void*)0)) return SML_ERR_MGR_INVALID_INSTANCE_INFO0x1002; |
686 | |
687 | |
688 | pInstanceInfo->maxOutgoingSize = maxOutgoingSize; |
689 | |
690 | return SML_ERR_OK0x00; |
691 | } |
692 | |
693 | |
694 | |
695 | |
696 | |
697 | |
698 | |
699 | |
700 | |
701 | |
702 | |
703 | SML_API Ret_t smlSetOutgoingBegin(InstanceID_t id) |
704 | { |
705 | InstanceInfoPtr_t pInstanceInfo; |
706 | |
707 | pInstanceInfo = (InstanceInfoPtr_t)id; |
708 | if (pInstanceInfo==NULL((void*)0)) return SML_ERR_MGR_INVALID_INSTANCE_INFO0x1002; |
709 | |
710 | |
711 | pInstanceInfo->outgoingMsgStart=pInstanceInfo->writePointer; |
712 | |
713 | return SML_ERR_OK0x00; |
714 | } |
715 | |
716 | |
717 | |
718 | |
719 | |
720 | |
721 | |
722 | |
723 | |
724 | |
725 | |
726 | |
727 | |
728 | |
729 | |
730 | |
731 | |
732 | |
733 | |
734 | SML_API Ret_t smlReadOutgoingAgain(InstanceID_t id) |
735 | { |
736 | InstanceInfoPtr_t pInstanceInfo; |
737 | |
738 | pInstanceInfo = (InstanceInfoPtr_t)id; |
739 | if (pInstanceInfo==NULL((void*)0)) return SML_ERR_MGR_INVALID_INSTANCE_INFO0x1002; |
740 | |
741 | |
742 | if (pInstanceInfo->outgoingMsgStart==NULL((void*)0)) return SML_ERR_WRONG_USAGE0x13; |
743 | pInstanceInfo->readPointer=pInstanceInfo->outgoingMsgStart; |
744 | |
745 | return SML_ERR_OK0x00; |
746 | } |
747 | |
748 | |
749 | |
750 | |
751 | |
752 | |
753 | |
754 | |
755 | |
756 | |
757 | |
758 | |
759 | |
760 | |
761 | |
762 | |
763 | |
764 | |
765 | SML_API Ret_t smlPeekMessageBuffer(InstanceID_t id, Boolean_t outgoing, MemPtr_t *message, MemSize_t *msgsize) |
766 | { |
767 | InstanceInfoPtr_t pInstanceInfo; |
768 | |
769 | pInstanceInfo = (InstanceInfoPtr_t)id; |
770 | if (pInstanceInfo==NULL((void*)0)) return SML_ERR_MGR_INVALID_INSTANCE_INFO0x1002; |
771 | |
772 | if (outgoing) { |
773 | if (pInstanceInfo->outgoingMsgStart==NULL((void*)0)) return SML_ERR_WRONG_USAGE0x13; |
774 | *message = pInstanceInfo->outgoingMsgStart; |
775 | } |
776 | else { |
777 | if (pInstanceInfo->incomingMsgStart) { |
778 | |
779 | *message = pInstanceInfo->incomingMsgStart; |
780 | } |
781 | else { |
782 | |
783 | if (pInstanceInfo->readPointer==0) |
784 | return SML_ERR_WRONG_USAGE0x13; |
785 | *message = pInstanceInfo->readPointer; |
786 | } |
787 | } |
788 | if (*message>=pInstanceInfo->writePointer) return SML_ERR_WRONG_USAGE0x13; |
789 | |
790 | *msgsize = pInstanceInfo->writePointer-*message; |
791 | return SML_ERR_OK0x00; |
792 | } |
793 | |
794 | |
795 | #endif |
796 | |
797 | |
798 | |
799 | |
800 | |
801 | |
802 | |
803 | |
804 | |
805 | |
806 | |
807 | |
808 | |
809 | |
810 | |
811 | |
812 | |
813 | |
814 | |
815 | |
816 | |
817 | |
818 | |
819 | |
820 | |
821 | |
822 | SML_API Ret_t smlLockWriteBuffer(InstanceID_t id, MemPtr_t *pWritePosition, MemSize_t *freeSize) |
823 | { |
824 | #ifdef NOWSM1 |
825 | InstanceInfoPtr_t pInstanceInfo; |
826 | Boolean_t ogs; |
827 | |
828 | pInstanceInfo = (InstanceInfoPtr_t)id; |
829 | if (pInstanceInfo==NULL((void*)0)) return SML_ERR_MGR_INVALID_INSTANCE_INFO0x1002; |
830 | |
831 | if (pInstanceInfo->writeLocked) |
832 | return SML_ERR_WRONG_USAGE0x13; |
833 | |
834 | if (pInstanceInfo->readPointer == pInstanceInfo->writePointer) { |
835 | |
836 | ogs = pInstanceInfo->outgoingMsgStart == pInstanceInfo->writePointer; |
837 | |
838 | mgrResetWorkspace(pInstanceInfo); |
839 | |
840 | if (ogs) pInstanceInfo->outgoingMsgStart=pInstanceInfo->writePointer; |
841 | } |
842 | |
843 | |
844 | *pWritePosition = pInstanceInfo->writePointer; |
845 | |
846 | if ( |
847 | pInstanceInfo->maxOutgoingSize && |
848 | pInstanceInfo->outgoingMsgStart && |
849 | pInstanceInfo->outgoingMsgStart<pInstanceInfo->writePointer |
850 | ) { |
851 | |
852 | *freeSize = |
853 | (pInstanceInfo->maxOutgoingSize) - |
854 | (pInstanceInfo->writePointer-pInstanceInfo->outgoingMsgStart); |
855 | if (pInstanceInfo->writePointer+*freeSize > pInstanceInfo->instanceBuffer+pInstanceInfo->instanceBufSiz) { |
856 | |
857 | *freeSize = |
858 | (pInstanceInfo->instanceBuffer+pInstanceInfo->instanceBufSiz) - |
859 | pInstanceInfo->writePointer; |
860 | } |
861 | } |
862 | else { |
863 | |
864 | *freeSize = |
865 | (pInstanceInfo->instanceBuffer+pInstanceInfo->instanceBufSiz) - |
866 | pInstanceInfo->writePointer; |
867 | } |
868 | |
869 | pInstanceInfo->writeLocked=1; |
870 | #else |
871 | Ret_t rc; |
872 | |
873 | |
874 | LOCKTOOLKIT("smlLockWriteBuffer"); |
875 | rc = wsmLockH(id, SML_FIRST_FREE_ITEM, pWritePosition); |
876 | RELEASETOOLKIT("smlLockWriteBuffer"); |
877 | if (rc!=SML_ERR_OK0x00) return rc; |
878 | |
879 | |
880 | LOCKTOOLKIT("smlLockWriteBuffer"); |
881 | rc = wsmGetFreeSize(id, freeSize); |
882 | RELEASETOOLKIT("smlLockWriteBuffer"); |
883 | if (rc!=SML_ERR_OK0x00) return rc; |
884 | #endif |
885 | |
886 | return SML_ERR_OK0x00; |
887 | } |
888 | |
889 | |
890 | |
891 | |
892 | |
893 | |
894 | |
895 | |
896 | |
897 | |
898 | |
899 | |
900 | |
901 | |
902 | |
903 | |
904 | |
905 | |
906 | |
907 | |
908 | |
909 | SML_API Ret_t smlUnlockWriteBuffer(InstanceID_t id, MemSize_t writtenBytes) |
910 | { |
911 | #ifdef NOWSM1 |
912 | InstanceInfoPtr_t pInstanceInfo; |
913 | |
914 | pInstanceInfo = (InstanceInfoPtr_t)id; |
915 | if (pInstanceInfo==NULL((void*)0)) return SML_ERR_MGR_INVALID_INSTANCE_INFO0x1002; |
916 | |
917 | if (!pInstanceInfo->writeLocked) |
918 | return SML_ERR_WRONG_USAGE0x13; |
919 | if (writtenBytes > 0) { |
920 | |
921 | if (pInstanceInfo->writePointer+writtenBytes>pInstanceInfo->instanceBuffer+pInstanceInfo->instanceBufSiz) |
922 | return SML_ERR_WRONG_USAGE0x13; |
923 | |
924 | pInstanceInfo->writePointer+=writtenBytes; |
925 | } |
926 | |
927 | pInstanceInfo->writeLocked=0; |
928 | #else |
929 | Ret_t rc; |
930 | |
931 | if (writtenBytes > 0) |
932 | { |
933 | |
934 | LOCKTOOLKIT("smlUnlockWriteBuffer"); |
935 | rc = wsmSetUsedSize(id,writtenBytes); |
936 | RELEASETOOLKIT("smlUnlockWriteBuffer"); |
937 | if (rc!=SML_ERR_OK0x00) return rc; |
938 | } |
939 | |
940 | LOCKTOOLKIT("smlUnlockWriteBuffer"); |
941 | rc = wsmUnlockH(id); |
942 | RELEASETOOLKIT("smlUnlockWriteBuffer"); |
943 | if (rc!=SML_ERR_OK0x00) return rc; |
944 | #endif |
945 | |
946 | return SML_ERR_OK0x00; |
947 | } |
948 | |
949 | |
950 | |
951 | |
952 | |
953 | |
954 | |
955 | |
956 | |
957 | |
958 | |
959 | |
960 | |
961 | |
962 | |
963 | |
964 | |
965 | |
966 | Ret_t mgrResetWorkspace (InstanceID_t id) { |
967 | #ifdef NOWSM1 |
968 | InstanceInfoPtr_t pInstanceInfo; |
969 | |
970 | pInstanceInfo = (InstanceInfoPtr_t)id; |
971 | if (pInstanceInfo==NULL((void*)0)) return SML_ERR_MGR_INVALID_INSTANCE_INFO0x1002; |
972 | |
973 | pInstanceInfo->readPointer=pInstanceInfo->instanceBuffer; |
974 | pInstanceInfo->writePointer=pInstanceInfo->instanceBuffer; |
975 | pInstanceInfo->outgoingMsgStart=NULL((void*)0); |
976 | pInstanceInfo->incomingMsgStart=NULL((void*)0); |
977 | return SML_ERR_OK0x00; |
978 | #else |
979 | Ret_t rc; |
980 | LOCKTOOLKIT("mgrResetWorkspace"); |
981 | rc=wsmReset (id); |
982 | RELEASETOOLKIT("mgrResetWorkspace"); |
983 | return rc; |
984 | #endif |
985 | } |
986 | |
987 | |
988 | |
989 | |
990 | |
991 | |
992 | |
993 | |
994 | |
995 | |
996 | |
997 | |
998 | |
999 | |
1000 | |
1001 | Ret_t setInstanceOptions (InstanceID_t id, SmlInstanceOptionsPtr_t pOptions) |
1002 | { |
1003 | |
1004 | |
1005 | InstanceInfoPtr_t pInstanceInfo; |
1006 | SmlInstanceOptionsPtr_t pOptionsCopy; |
1007 | |
1008 | |
1009 | #ifdef NOWSM1 |
1010 | |
1011 | if (!pOptions || (pOptions->encoding==SML_UNDEF)) |
1012 | return SML_ERR_WRONG_USAGE0x13; |
1013 | |
1014 | pInstanceInfo = (InstanceInfoPtr_t)id; |
1015 | #else |
1016 | |
1017 | if (!pOptions || !pOptions->workspaceName|| (pOptions->encoding==SML_UNDEF)) |
1018 | return SML_ERR_WRONG_USAGE0x13; |
1019 | |
1020 | |
1021 | #ifdef __SML_LITE__ /* Only ONE instance is supported in the Toolkit lite version */ |
1022 | pInstanceInfo = mgrGetInstanceListAnchor(); |
1023 | #else |
1024 | pInstanceInfo = (InstanceInfoPtr_t) findInfo(id); |
1025 | #endif |
1026 | #endif |
1027 | |
1028 | if (pInstanceInfo==NULL((void*)0)) return SML_ERR_MGR_INVALID_INSTANCE_INFO0x1002; |
1029 | |
1030 | |
1031 | freeInstanceOptions(pInstanceInfo); |
1032 | |
1033 | |
1034 | pOptionsCopy = (SmlInstanceOptionsPtr_t)smlLibMalloc((MemSize_t)sizeof(SmlInstanceOptions_t)); |
1035 | if (pOptionsCopy==NULL((void*)0)) return SML_ERR_NOT_ENOUGH_SPACE0x11; |
1036 | smlLibMemcpy(pOptionsCopy,pOptions,(MemSize_t)sizeof(SmlInstanceOptions_t)); |
1037 | |
1038 | #ifndef NOWSM1 |
1039 | pOptionsCopy->workspaceName=smlLibStrdup(pOptions->workspaceName); |
1040 | |
1041 | if (pOptionsCopy->workspaceName == NULL((void*)0)) { |
1042 | pInstanceInfo->instanceOptions=NULL((void*)0); |
1043 | smlLibFree(pOptionsCopy); |
1044 | return SML_ERR_NOT_ENOUGH_SPACE0x11; |
1045 | } |
1046 | #endif |
1047 | |
1048 | |
1049 | pInstanceInfo->instanceOptions=pOptionsCopy; |
1050 | |
1051 | |
1052 | |
1053 | |
1054 | |
1055 | |
1056 | |
1057 | return SML_ERR_OK0x00; |
1058 | } |
1059 | |
1060 | |
1061 | |
1062 | |
1063 | |
1064 | |
1065 | |
1066 | |
1067 | |
1068 | |
1069 | Ret_t freeInstanceOptions (InstanceInfoPtr_t pInfo) { |
1070 | |
1071 | |
1072 | if (pInfo->instanceOptions!=NULL((void*)0)) { |
1073 | #ifndef NOWSM1 |
1074 | if (pInfo->instanceOptions->workspaceName!=NULL((void*)0)) |
1075 | smlLibFree(pInfo->instanceOptions->workspaceName); |
1076 | #endif |
1077 | smlLibFree(pInfo->instanceOptions); |
1078 | } |
1079 | |
1080 | return SML_ERR_OK0x00; |
1081 | } |
1082 | |
1083 | |
1084 | |
1085 | |
1086 | |
1087 | |
1088 | |
1089 | |
1090 | static Ret_t freeInstanceInfo(InstanceInfoPtr_t pInfo) { |
1091 | |
1092 | if (pInfo) { |
1093 | |
1094 | #ifdef NOWSM1 |
1095 | |
1096 | if (pInfo->instanceBuffer) |
1097 | smlLibFree(pInfo->instanceBuffer); |
1098 | #else |
1099 | if (pInfo->workspaceState) |
1100 | smlLibFree(pInfo->workspaceState); |
1101 | #endif |
1102 | if (pInfo->encoderState) |
1103 | xltEncReset((XltEncoderPtr_t)pInfo->encoderState); |
1104 | if (pInfo->decoderState) |
1105 | xltDecReset((XltDecoderPtr_t)pInfo->decoderState); |
1106 | if (pInfo->callbacks) |
1107 | smlLibFree(pInfo->callbacks); |
1108 | |
1109 | freeInstanceOptions(pInfo); |
1110 | |
1111 | smlLibFree(pInfo); |
1112 | } |
1113 | |
1114 | return SML_ERR_OK0x00; |
1115 | } |