@@ -193,19 +193,46 @@ type SolClientResponseCode = C.solClient_session_responseCode_t
193193// SolClientErrorInfoWrapper is assigned a value
194194type SolClientErrorInfoWrapper C.solClient_errorInfo_wrapper_t
195195
196+ // SolClientErrorInfoWrapperDetailed is assigned a value
197+ type SolClientErrorInfoWrapperDetailed C.solClient_errorInfo_t
198+
196199func (info * SolClientErrorInfoWrapper ) String () string {
197200 if info == nil {
198201 return ""
199202 }
200- return fmt .Sprintf ("{ReturnCode: %d, SubCode: %d, ResponseCode: %d, ErrorStr: %s}" , info .ReturnCode , info .SubCode , info .ResponseCode , info .GetMessageAsString ())
203+ if info .DetailedErrorInfo == nil {
204+ return fmt .Sprintf ("{ReturnCode: %d, SubCode: nil, ResponseCode: nil, ErrorStr: nil}" , info .ReturnCode )
205+ }
206+ detailedErrorInfo := * (info .DetailedErrorInfo )
207+ return fmt .Sprintf ("{ReturnCode: %d, SubCode: %d, ResponseCode: %d, ErrorStr: %s}" ,
208+ info .ReturnCode ,
209+ detailedErrorInfo .subCode ,
210+ detailedErrorInfo .responseCode ,
211+ info .GetMessageAsString ())
201212}
202213
203214// GetMessageAsString function outputs a string
204215func (info * SolClientErrorInfoWrapper ) GetMessageAsString () string {
205- if len (info .ErrorStr ) == 0 {
216+ if info . DetailedErrorInfo == nil || len (info .DetailedErrorInfo . errorStr ) == 0 {
206217 return ""
207218 }
208- return C .GoString ((* C .char )(& info .ErrorStr [0 ]))
219+ return C .GoString ((* C .char )(& info .DetailedErrorInfo .errorStr [0 ]))
220+ }
221+
222+ // SubCode function returns subcode if available
223+ func (info * SolClientErrorInfoWrapper ) SubCode () SolClientSubCode {
224+ if info .DetailedErrorInfo != nil {
225+ return (* (info .DetailedErrorInfo )).subCode
226+ }
227+ return SolClientSubCode (0 )
228+ }
229+
230+ // ResponseCode function returns response code if available
231+ func (info * SolClientErrorInfoWrapper ) ResponseCode () SolClientResponseCode {
232+ if info .DetailedErrorInfo != nil {
233+ return (* (info .DetailedErrorInfo )).responseCode
234+ }
235+ return SolClientResponseCode (0 )
209236}
210237
211238// Definition of structs returned from this package to be used externally
@@ -415,6 +442,21 @@ func (session *SolClientSession) SolClientSessionUnsubscribe(topic string, dispa
415442 return session .solClientSessionUnsubscribeWithFlags (topic , C .SOLCLIENT_SUBSCRIBE_FLAGS_REQUEST_CONFIRM , dispatchID , correlationID )
416443}
417444
445+ // SolClientEndpointUnsusbcribe wraps solClient_session_endpointTopicUnsubscribe
446+ func (session * SolClientSession ) SolClientEndpointUnsusbcribe (properties []string , topic string , correlationID uintptr ) * SolClientErrorInfoWrapper {
447+ return handleCcsmpError (func () SolClientReturnCode {
448+ cString := C .CString (topic )
449+ defer C .free (unsafe .Pointer (cString ))
450+ endpointProps , endpointFree := ToCArray (properties , true )
451+ defer endpointFree ()
452+ return C .SessionTopicEndpointUnsubscribeWithFlags (session .pointer ,
453+ endpointProps ,
454+ C .SOLCLIENT_SUBSCRIBE_FLAGS_REQUEST_CONFIRM ,
455+ cString ,
456+ C .solClient_uint64_t (correlationID ))
457+ })
458+ }
459+
418460// SolClientEndpointProvision wraps solClient_session_endpointProvision
419461func (session * SolClientSession ) SolClientEndpointProvision (properties []string ) * SolClientErrorInfoWrapper {
420462 return handleCcsmpError (func () SolClientReturnCode {
@@ -424,29 +466,54 @@ func (session *SolClientSession) SolClientEndpointProvision(properties []string)
424466 })
425467}
426468
427- // SolClientEndpointUnsusbcribe wraps solClient_session_endpointTopicUnsubscribe
428- func (session * SolClientSession ) SolClientEndpointUnsusbcribe (properties []string , topic string , correlationID uintptr ) * SolClientErrorInfoWrapper {
469+ // SolClientEndpointProvisionWithFlags wraps solClient_session_endpointProvision
470+ func (session * SolClientSession ) SolClientEndpointProvisionWithFlags (properties []string , flags C. solClient_uint32_t , correlationID uintptr ) * SolClientErrorInfoWrapper {
429471 return handleCcsmpError (func () SolClientReturnCode {
430- cString := C .CString (topic )
431- defer C .free (unsafe .Pointer (cString ))
432472 endpointProps , endpointFree := ToCArray (properties , true )
433473 defer endpointFree ()
434- return C .SessionTopicEndpointUnsubscribeWithFlags (session .pointer ,
474+ return C .SessionEndpointProvisionWithFlags (session .pointer ,
435475 endpointProps ,
436- C .SOLCLIENT_SUBSCRIBE_FLAGS_REQUEST_CONFIRM ,
437- cString ,
476+ flags ,
477+ C .solClient_uint64_t (correlationID ))
478+ })
479+ }
480+
481+ // SolClientEndpointDeprovisionWithFlags wraps solClient_session_endpointDeprovision
482+ func (session * SolClientSession ) SolClientEndpointDeprovisionWithFlags (properties []string , flags C.solClient_uint32_t , correlationID uintptr ) * SolClientErrorInfoWrapper {
483+ return handleCcsmpError (func () SolClientReturnCode {
484+ endpointProps , endpointFree := ToCArray (properties , true )
485+ defer endpointFree ()
486+ return C .SessionEndpointDeprovisionWithFlags (session .pointer ,
487+ endpointProps ,
488+ flags ,
438489 C .solClient_uint64_t (correlationID ))
439490 })
440491}
441492
493+ // SolClientEndpointProvisionAsync wraps solClient_session_endpointProvision
494+ func (session * SolClientSession ) SolClientEndpointProvisionAsync (properties []string , correlationID uintptr , ignoreExistErrors bool ) * SolClientErrorInfoWrapper {
495+ if ignoreExistErrors {
496+ return session .SolClientEndpointProvisionWithFlags (properties , C .SOLCLIENT_PROVISION_FLAGS_IGNORE_EXIST_ERRORS , correlationID )
497+ }
498+ return session .SolClientEndpointProvisionWithFlags (properties , 0x0 , correlationID ) // no flag pass here
499+ }
500+
501+ // SolClientEndpointDeprovisionAsync wraps solClient_session_endpointDeprovision
502+ func (session * SolClientSession ) SolClientEndpointDeprovisionAsync (properties []string , correlationID uintptr , ignoreMissingErrors bool ) * SolClientErrorInfoWrapper {
503+ if ignoreMissingErrors {
504+ return session .SolClientEndpointDeprovisionWithFlags (properties , C .SOLCLIENT_PROVISION_FLAGS_IGNORE_EXIST_ERRORS , correlationID )
505+ }
506+ return session .SolClientEndpointDeprovisionWithFlags (properties , 0x0 , correlationID ) // no flag pass here
507+ }
508+
442509// SolClientSessionGetRXStat wraps solClient_session_getRxStat
443510func (session * SolClientSession ) SolClientSessionGetRXStat (stat SolClientStatsRX ) (value uint64 ) {
444511 err := handleCcsmpError (func () SolClientReturnCode {
445512 return C .solClient_session_getRxStat (session .pointer , C .solClient_stats_rx_t (stat ), (C .solClient_stats_pt )(unsafe .Pointer (& value )))
446513 })
447514 // we should not in normal operation encounter an error fetching stats, but just in case...
448515 if err != nil {
449- logging .Default .Warning ("Encountered error loading core rx stat: " + err .GetMessageAsString () + ", subcode " + fmt .Sprint (err .SubCode ))
516+ logging .Default .Warning ("Encountered error loading core rx stat: " + err .GetMessageAsString () + ", subcode " + fmt .Sprint (err .SubCode () ))
450517 }
451518 return value
452519}
@@ -457,7 +524,7 @@ func (session *SolClientSession) SolClientSessionGetTXStat(stat SolClientStatsTX
457524 return C .solClient_session_getTxStat (session .pointer , C .solClient_stats_tx_t (stat ), (C .solClient_stats_pt )(unsafe .Pointer (& value )))
458525 })
459526 if err != nil {
460- logging .Default .Warning ("Encountered error loading core stat: " + err .GetMessageAsString () + ", subcode " + fmt .Sprint (err .SubCode ))
527+ logging .Default .Warning ("Encountered error loading core stat: " + err .GetMessageAsString () + ", subcode " + fmt .Sprint (err .SubCode () ))
461528 }
462529 return value
463530}
@@ -581,17 +648,28 @@ func NewSessionReplyDispatch(id uint64) uintptr {
581648 return uintptr (id )
582649}
583650
651+ // GetLastErrorInfoReturnCodeOnly returns a SolClientErrorInfoWrapper with only the ReturnCode field set.
652+ // This adds a function call on failure paths, but we'd be passing strings around in that case anyways and it should
653+ // happen rarely, so it's fine to slow it down a bit more if it means avoiding code duplication. See this function's
654+ // usage in GetLastErrorInfo() and handleCcsmpError to see where the duplicated code would otherwise have been.
655+ func GetLastErrorInfoReturnCodeOnly (returnCode SolClientReturnCode ) * SolClientErrorInfoWrapper {
656+ errorInfo := & SolClientErrorInfoWrapper {}
657+ errorInfo .ReturnCode = returnCode
658+ return errorInfo
659+ }
660+
584661// GetLastErrorInfo should NOT be called in most cases as it is dependent on the thread.
585662// Unless you know that the goroutine running the code will not be interrupted, do NOT
586663// call this function!
587664func GetLastErrorInfo (returnCode SolClientReturnCode ) * SolClientErrorInfoWrapper {
588- errorInfo := & SolClientErrorInfoWrapper {}
589- errorInfo .ReturnCode = returnCode
665+ errorInfo := GetLastErrorInfoReturnCodeOnly (returnCode )
590666 if returnCode != SolClientReturnCodeNotFound {
667+ detailedErrorInfo := C.solClient_errorInfo_t {}
591668 solClientErrorInfoPt := C .solClient_getLastErrorInfo ()
592- errorInfo .SubCode = solClientErrorInfoPt .subCode
593- errorInfo .ResponseCode = solClientErrorInfoPt .responseCode
594- C .strcpy ((* C .char )(& errorInfo .ErrorStr [0 ]), (* C .char )(& solClientErrorInfoPt .errorStr [0 ]))
669+ detailedErrorInfo .subCode = solClientErrorInfoPt .subCode
670+ detailedErrorInfo .responseCode = solClientErrorInfoPt .responseCode
671+ C .strcpy ((* C .char )(& detailedErrorInfo .errorStr [0 ]), (* C .char )(& solClientErrorInfoPt .errorStr [0 ]))
672+ errorInfo .DetailedErrorInfo = & detailedErrorInfo
595673 }
596674 return errorInfo
597675}
@@ -609,8 +687,12 @@ func handleCcsmpError(f func() SolClientReturnCode) *SolClientErrorInfoWrapper {
609687 defer runtime .UnlockOSThread ()
610688
611689 returnCode := f ()
612- if returnCode != SolClientReturnCodeOk && returnCode != SolClientReturnCodeInProgress {
690+ if returnCode == SolClientReturnCodeFail || returnCode == SolClientReturnCodeNotReady {
691+ // Return full error struct if rc requires additional error info.
613692 return GetLastErrorInfo (returnCode )
693+ } else if returnCode != SolClientReturnCodeOk && returnCode != SolClientReturnCodeInProgress {
694+ // Return partial error if not ok but not failure so that caller can parse on rc
695+ return GetLastErrorInfoReturnCodeOnly (returnCode )
614696 }
615697 return nil
616698}
0 commit comments