[PB ALL]-With debugger works, no debugger does not work. HLP

Just starting out? Need help? Post your questions and find answers here.
User avatar
holzhacker
Enthusiast
Enthusiast
Posts: 123
Joined: Mon Mar 08, 2010 9:14 pm
Location: "Mens sana in corpore sano"
Contact:

[PB ALL]-With debugger works, no debugger does not work. HLP

Post by holzhacker »

Friends (help Fred please) I have two ghosts with Purebasic that I can not solve.

The first major problem is that the application works with the debugger turned on, however, when debugging is disabled it does not work.

The second problem is that when using module to improve the code the call is performed but it presents an error in the command line of the call (SIP :: MakeCall), but when carrying out the direct call of the functions of the library everything happens well, the call is and the code runs normally.

Can anyone help?

The Library (pjsipDll_notls.dll) can be found at: https://github.com/pavram/sipeksdk
IN TIME: This library makes VoIP calls using an Asterisk server or account.

Code: Select all

EnableExplicit

DeclareModule SIP
  
  #PJ_SUCCESS    = 0
  #PJ_TRUE       = 1
  #PJ_FALSE      = 0
  
  #SIP_OK        = 200
  #SIP_FORBIDDEN = 403
  
  Enumeration 1;-CallStates
    #Calling
    #IncoingCall
    #RingingUp
    #Attended
    #StopingCalling
    #HungUp
  EndEnumeration
  
  Enumeration 1
    #Register
    #State
    #Incomming
    #Hold
    #Received
    #Status
    #DTMFDigit
    #Waiting
  EndEnumeration

  Structure cfg
    domain.s
    port.i
    protocol.s
    name.s
    username.s
    password.s
    proxy.s
    isdefault.i
    uri.s
    reguri.s
  EndStructure
  
  Global cfg.cfg

  Global RegisterAccount, getNumOfCodecs, GetCodec, MakeCall, AnswerCall, HoldCall
  Global *onRegStateCallback, *onCallStateCallback, *onCallIncoming, *onCallHoldConfirmCallback, *onMessageReceivedCallback, *onBuddyStatusChangedCallback, 
         *onDtmfDigitCallback, *onMessageWaitingCallback
  
  Prototype.i dll_RegisterAccount(uri.p-ascii, reguri.p-ascii, name.p-ascii, username.p-ascii, password.p-ascii, proxy.p-ascii, isdefault.i)
  Prototype.i dll_makeCall(accountId.i, uri.p-ascii)
  Prototype.s dll_getCodec(index.i)
  Prototype.i dll_getNumOfCodecs()
  Prototype.i dll_answerCall(callId.i, code.i)
  Prototype.i dll_holdCall(callId.i)
  
  Declare   Init()
  Declare   Destroy()
  Declare   SetSIPCallBack(target.i, function.i)

;   Declare   Register()
  Declare   getNumCodecs()
;   Declare.s getCodec_(index.i)
  Declare   Call(accountId.i, uri.s)
  
  Declare SetAccount(domain.s,port.i,protocol.s,name.s,username.s,password.s,proxy.s="",isdefault.i=#True)
  
; -NOT WORK in DeclareModule
;   PJSIP:
;     IncludeBinary "pjsipDll_notls.dll"
;   PJSIPEnd:  
;   
EndDeclareModule

Module SIP
  
  Procedure Init()
;     Shared PJSIPLib.i
    
;     OpenFile(0,(GetTemporaryDirectory()+"pjsipDll_notls.dll"))
;     WriteData(0,?PJSIP,(?PJSIPend-?PJSIP)):CloseFile(0)
;     OpenLibrary(0,(GetTemporaryDirectory()+"pjsipDll_notls.dll"))
    
;     CompilerIf #PB_Compiler_Debugger
      PJSIPLib = OpenLibrary(0, "pjsipDll_notls.dll")
;     CompilerElse
;       PJSIPLib = OpenLibrary(0, GetTemporaryDirectory()+"pjsipDll_notls.dll")
;     CompilerEndIf
    
      Debug PJSIPLib
      
    If PJSIPLib
      
      CompilerIf #PB_Compiler_Debugger
        ExamineLibraryFunctions(0)
        While NextLibraryFunction()
          Debug LibraryFunctionName()
        Wend 
      CompilerEndIf

      ;-Prototype
      RegisterAccount.dll_registerAccount = GetFunction(0, "dll_registerAccount");(char* uri, char* reguri, char* name, char* username, char* password, char* proxy, bool isdefault);
      getNumOfCodecs.dll_getNumOfCodecs   = GetFunction(0, "dll_getNumOfCodecs") ;();
      GetCodec.dll_getCodec               = GetFunction(0, "dll_getCodec")       ;(int index, char* codec);
      MakeCall.dll_makeCall               = GetFunction(0, "dll_makeCall")       ;(int accountId, char* uri); 
      AnswerCall.dll_answerCall           = GetFunction(0, "dll_answerCall")     ;(int callId, int code);
      HoldCall.dll_holdCall               = GetFunction(0, "dll_holdCall")       ;(int callId);
      
      ;// Callback registration 
      *onRegStateCallback           = GetFunction(0, "onRegStateCallback")          ;(fptr_regstate cb);	  // register registration notifier
      *onCallStateCallback          = GetFunction(0, "onCallStateCallback")         ;(fptr_callstate cb); // register call notifier
      ;*onCallIncoming = GetFunction(0, "onCallIncoming");(fptr_callincoming cb)    ; // register incoming call notifier
      *onCallIncoming               = GetFunction(0, "onCallIncoming")              ;(fptr_callincoming cb); // register incoming call notifier
      *onCallHoldConfirmCallback    = GetFunction(0, "onCallHoldConfirmCallback")   ;(fptr_callholdconf cb); // register call notifier
      ;//GetFunction(0, "onCallRetrieveConfirm(fptr_callretrieveconf cb)            ; // register call notifier
      *onMessageReceivedCallback    = GetFunction(0, "onMessageReceivedCallback")   ;(fptr_msgrec cb); // register call notifier
      *onBuddyStatusChangedCallback = GetFunction(0, "onBuddyStatusChangedCallback");(fptr_buddystatus cb); // register call notifier
      *onDtmfDigitCallback          = GetFunction(0, "onDtmfDigitCallback")         ;(fptr_dtmfdigit cb); // register dtmf digit notifier
      *onMessageWaitingCallback     = GetFunction(0, "onMessageWaitingCallback")    ;(fptr_mwi cb); // register MWI notifier
      *onCallReplaced               = GetFunction(0, "onCallReplaced")              ;(fptr_crep cb); // register Call replaced notifier
      ;// pjsip common API
      *dll_setSipConfig             = GetFunction(0, "dll_setSipConfig")            ;(SipConfigStruct* config);
      *dll_init                     = GetFunction(0, "dll_init")
      *dll_shutdown                 = GetFunction(0, "dll_shutdown")
      *dll_main                     = GetFunction(0, "dll_main")                    ;(void);
      *dll_setCodecPriority         = GetFunction(0, "dll_setCodecPriority")        ;(char* name, int index);
      ;// pjsip call API
      *dll_releaseCall              = GetFunction(0, "dll_releaseCall")             ;(int callId); 
      *dll_retrieveCall             = GetFunction(0, "dll_retrieveCall")            ;(int callId);
      *dll_xferCall                 = GetFunction(0, "dll_xferCall")                ;(int callid, char* uri);
      *dll_xferCallWithReplaces     = GetFunction(0, "dll_xferCallWithReplaces")    ;(int callId, int dstSession);
      *dll_serviceReq               = GetFunction(0, "dll_serviceReq")              ;(int callId, int serviceCode, const char* destUri);
      *dll_dialDtmf                 = GetFunction(0, "dll_dialDtmf")                ;(int callId, char* digits, int mode);
      *dll_removeAccounts           = GetFunction(0, "dll_removeAccounts")
      *dll_sendInfo                 = GetFunction(0, "dll_sendInfo")                ;(int callid, char* content);
      *dll_getCurrentCodec          = GetFunction(0, "dll_getCurrentCodec")         ;(int callId, char* codec);
      *dll_makeConference           = GetFunction(0, "dll_makeConference")          ;(int callId);
      *dll_sendCallMessage          = GetFunction(0, "dll_sendCallMessage")         ;(int callId, char* message);
      ;// IM & Presence api
      *dll_addBuddy                 = GetFunction(0, "dll_addBuddy")                ;(char* uri, bool subscribe);
      *dll_removeBuddy              = GetFunction(0, "dll_removeBuddy")             ;(int buddyId);
      *dll_sendMessage              = GetFunction(0, "dll_sendMessage")             ;(int accId, char* uri, char* message);
      *dll_setStatus                = GetFunction(0, "dll_setStatus")               ;(int accId, int presence_state);
      *dll_setSoundDevice           = GetFunction(0, "dll_setSoundDevice")          ;(char* playbackDeviceId, char* recordingDeviceId);
      *dll_pollForEvents            = GetFunction(0, "dll_pollForEvents")           ;(int timeout);
      
      CallCFunctionFast(*dll_init)
      CallCFunctionFast(*dll_main)       
      
    Else
      MessageRequester("Attention!", "pjsipDll_notls.dll Not loaded!", #PB_MessageRequester_Error)
      End 
    EndIf
    
  EndProcedure
  
  Procedure getNumCodecs()
    ProcedureReturn getNumOfCodecs()
  EndProcedure
  
;   Procedure.s  getCodec_(index.i)
;    *buffer = UTF8(getCodec(index))
;     ProcedureReturn  PeekS(*buffer)    
;   EndProcedure
  
  Procedure SetAccount(domain.s,port.i,protocol.s,name.s,username.s,password.s,proxy.s="",isdefault.i=#True)
    cfg\domain    = domain
    cfg\port      = port
    cfg\protocol  = protocol
    cfg\name      = name
    cfg\username  = username
    cfg\password  = password
    cfg\proxy     = proxy
    cfg\isdefault = isdefault
    
    cfg\uri       = "sip:" + cfg\username + "@" + cfg\domain
    cfg\reguri    = cfg\uri + ":" + Str( cfg\port ) + ";transport=" + cfg\protocol 
  EndProcedure

  Procedure Destroy()
    If IsLibrary(0): CloseLibrary(0): EndIf 
    Delay(100)
    If FileSize(GetTemporaryDirectory()+"pjsipDll_notls.dll") > 0
      DeleteFile(GetTemporaryDirectory()+"pjsipDll_notls.dll")
    EndIf
  EndProcedure
  
  Procedure SetSIPCallBack(target.i, function.i)
    Select target
      Case #Register
        CallCFunctionFast(*onRegStateCallback, @function)
      Case #State
        CallCFunctionFast(*onCallStateCallback, @function)
      Case #Incomming
        CallCFunctionFast(*onCallIncoming, @function)
      Case #Hold
        CallCFunctionFast(*onCallHoldConfirmCallback, @function)
      Case #Received
        CallCFunctionFast(*onMessageReceivedCallback, @function)
      Case #Status
        CallCFunctionFast(*onBuddyStatusChangedCallback, @function)
      Case #DTMFDigit
        CallCFunctionFast(*onDtmfDigitCallback, @function)
      Case #Waiting
        CallCFunctionFast(*onMessageWaitingCallback, @function)
    EndSelect
  EndProcedure

;   Procedure Register()
;     ProcedureReturn RegisterAccount(cfg\uri, cfg\reguri, cfg\name, cfg\username, cfg\password, cfg\proxy, cfg\isdefault)
;   EndProcedure
  
  Procedure Call(accountId.i, uri.s)
    MakeCall(accountId, uri)
  EndProcedure
  
EndModule

;-TEST
CompilerIf #PB_Compiler_IsMainFile
  
;   UseModule SIP

  Structure reg
    accountId.i
    regState.i
    stateName.s
  EndStructure
  
  Global Dim reg.reg(1)      
  
  Procedure onRegStateChanged(accountId, regState)
    Define c
    
    Debug "onRegStateChanged"
    
    Debug accountId
    Debug regState
    Debug c
    
    Select regState
      Case SIP::#SIP_OK
        reg(accountId)\accountId = accountId
        reg(accountId)\regState  = regState
        reg(accountId)\stateName = "200 OK"
      Case SIP::#SIP_FORBIDDEN
        reg(accountId)\accountId = accountId
        reg(accountId)\regState  = regState
        reg(accountId)\stateName = "403 Forbidden"      
    EndSelect    
    
    Debug "Status: " + reg(accountId)\stateName
  
  EndProcedure
  
  Procedure OnCallStateChanged(a, b)
    Debug "OnCallStateChanged "
    Debug a
    Debug b
  
    Select b
      Case SIP::#Calling
        Debug "Calling"
      Case SIP::#IncoingCall
        Debug "Incoing Call: " + b 
  ;      answerCall(b, 200)
  
      Case SIP::#RingingUp
        Debug "Ringing Up"
      Case SIP::#Attended
        Debug "Attended"
      Case SIP::#StopingCalling
        Debug "Stoping Calling"
      Case SIP::#HungUp
        Debug "Hung Up"
      Default
        Debug "DEFAULT = " + Str(b)
    EndSelect
    
  EndProcedure
  
  Procedure onCallIncomingChange(a, *b)
    Debug "onCallIncomingChange"
    Debug a
    Debug *b
    Debug PeekS(*b, -1, #PB_UTF8)
  EndProcedure
  
  Procedure onCallHoldConfirmCallbackChange(a, b)
    Debug "onCallHoldConfirmCallbackChange"
    Debug a
    Debug b
  ;   Debug PeekS(*b, -1, #PB_UTF8)
  EndProcedure
  
  Procedure onMessageReceivedCallbackChange(a, b)
    Debug "onMessageReceivedCallbackChange"
    Debug a
    Debug b
  ;   Debug PeekS(*b, -1, #PB_UTF8)
  EndProcedure
  
  Procedure onBuddyStatusChangedCallbackChange(a, b)
    Debug "onBuddyStatusChangedCallbackChange"
    Debug a
    Debug b
  ;   Debug PeekS(*b, -1, #PB_UTF8)
  EndProcedure
  
  Procedure onDtmfDigitCallbackChange(a, b)
    Debug "onDtmfDigitCallbackChange"
    Debug a
    Debug b
  ;   Debug PeekS(*b, -1, #PB_UTF8)
  EndProcedure
  
  Procedure onMessageWaitingCallbackChange(a, *b)
    Protected.s msg
    Debug "onMessageWaitingCallbackChange"
    Debug a
    Debug *b
    msg = PeekS(*b, -1, #PB_UTF8)
    Debug "msg.....: " + msg
  
  EndProcedure
  
  Procedure onCallReplacedChange(a, b)
    Debug "onCallReplaced"
    Debug a
    Debug b
  ;   Debug PeekS(*b, -1, #PB_UTF8)
  EndProcedure
  
  ;When you cancel this line the call is performed but it shows error in the MakeCall line
;   #SimulateGhostError = #True 
  
  Procedure SIPTest()  
    
    SIP::Init()
    
    CompilerIf Defined(SimulateGhostError, #PB_Constant)
      
     ;{ GHOST ERROR
      SIP::SetSIPCallBack(SIP::#Register,  @onRegStateChanged())
      SIP::SetSIPCallBack(SIP::#State,     @OnCallStateChanged())
      SIP::SetSIPCallBack(SIP::#Incomming, @onCallIncomingChange())
      SIP::SetSIPCallBack(SIP::#Hold,      @onCallHoldConfirmCallbackChange())
      SIP::SetSIPCallBack(SIP::#Received,  @onMessageReceivedCallbackChange())
      SIP::SetSIPCallBack(SIP::#Status,    @onBuddyStatusChangedCallbackChange())
      SIP::SetSIPCallBack(SIP::#DTMFDigit, @onDtmfDigitCallbackChange())
      SIP::SetSIPCallBack(SIP::#Waiting,   @onMessageWaitingCallbackChange())  
      ;}
      
    CompilerElse
      
      CallCFunctionFast(SIP::*onRegStateCallback,           @onRegStateChanged())
      CallCFunctionFast(SIP::*onCallStateCallback,          @OnCallStateChanged())
      CallCFunctionFast(SIP::*onCallIncoming,               @onCallIncomingChange())
      CallCFunctionFast(SIP::*onCallHoldConfirmCallback,    @onCallHoldConfirmCallbackChange())
      CallCFunctionFast(SIP::*onMessageReceivedCallback,    @onMessageReceivedCallbackChange())
      CallCFunctionFast(SIP::*onBuddyStatusChangedCallback, @onBuddyStatusChangedCallbackChange())
      CallCFunctionFast(SIP::*onDtmfDigitCallback,          @onDtmfDigitCallbackChange())
      CallCFunctionFast(SIP::*onMessageWaitingCallback,     @onMessageWaitingCallbackChange())
      
    CompilerEndIf
 
    Define.i ID, nrCodecs, time
    
    ;Format Parameters 
    ;
    ;uri.p-ascii      = "sip:username@ip_or_domain"
    ;reguri.p-ascii   = "sip:username@ip_or_domain:port;transport=udp"
    ;name.p-ascii     = "name_account or * (example)"
    ;username.p-ascii = "username"
    ;password.p-ascii = "passwords"
    ;proxy.p-ascii    = "ip_or_domaind or "" (example)"
    ;isdefault.i      = #true or #false     
    
    ID = SIP::RegisterAccount("sip:1000@your_asterisk_domain.myvnc.com", "sip:1000@your_asterisk_domain.myvnc.com:5060;transport=udp", "*", "1000", "1234", "",#True);-Example
    Debug "ID: " + Str(ID)
    
    If ID > 0
      ReDim reg.reg(ID)
      
      nrCodecs = SIP::getNumCodecs()
      Debug "Number of Codecs: " + Str(nrCodecs)      
      
      SIP::MakeCall(ID, "sip:1001@your_asterisk_domain.myvnc.com")

      
      For time=1 To 10000
        Delay(1)  
      Next
      
    Else
      MessageRequester("Error", "Error")
    EndIf
    
    SIP::Destroy()
  EndProcedure
  
  SIPTest()

CompilerEndIf 
I use RasPBX (raspberry pi) as the VoIP server that will originate and receive the connection between extensions of the client requesting support and the team that will accept the request and receive the call.

If anyone can help, I will be very grateful and happy.

Reading the PJSIP license well it could turn into an official PB library in the future.
Last edited by holzhacker on Tue Oct 23, 2018 7:45 pm, edited 1 time in total.
Greetings and thanks!

Romerio Medeiros
romerio@gmail.com
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: [PB ALL]-With debugger works, no debugger does not work.

Post by Little John »

holzhacker wrote:The first major problem is that the application works with the debugger turned on, however, when debugging is disabled it does not work.
When the debugger is off, the following function calls are never executed:

Code: Select all

      Debug CallCFunctionFast(SIP::*onRegStateCallback,           @onRegStateChanged())
      Debug CallCFunctionFast(SIP::*onCallStateCallback,          @OnCallStateChanged())
      Debug CallCFunctionFast(SIP::*onCallIncoming,               @onCallIncomingChange())
      Debug CallCFunctionFast(SIP::*onCallHoldConfirmCallback,    @onCallHoldConfirmCallbackChange())
      Debug CallCFunctionFast(SIP::*onMessageReceivedCallback,    @onMessageReceivedCallbackChange())
      Debug CallCFunctionFast(SIP::*onBuddyStatusChangedCallback, @onBuddyStatusChangedCallbackChange())
      Debug CallCFunctionFast(SIP::*onDtmfDigitCallback,          @onDtmfDigitCallbackChange())
      Debug CallCFunctionFast(SIP::*onMessageWaitingCallback,     @onMessageWaitingCallbackChange())
That might be the cause of the issue.

If you change it like this:

Code: Select all

      x = CallCFunctionFast(SIP::*onRegStateCallback,           @onRegStateChanged())
      Debug x
then the functions will always be called, regardless whether the debugger is enabled or disabled.
User avatar
holzhacker
Enthusiast
Enthusiast
Posts: 123
Joined: Mon Mar 08, 2010 9:14 pm
Location: "Mens sana in corpore sano"
Contact:

Re: [PB ALL]-With debugger works, no debugger does not work.

Post by holzhacker »

Little John wrote:
holzhacker wrote:The first major problem is that the application works with the debugger turned on, however, when debugging is disabled it does not work.
When the debugger is off, the following function calls are never executed:

Thank you very much Little John :D, you have helped me a lot to solve the problem with the Debugger.

Do you have any idea why it does not work when using a module?
Greetings and thanks!

Romerio Medeiros
romerio@gmail.com
User avatar
Demivec
Addict
Addict
Posts: 4082
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: [PB ALL]-With debugger works, no debugger does not work.

Post by Demivec »

Code: Select all

; -NOT WORK in DeclareModule
;   PJSIP:
;     IncludeBinary "pjsipDll_notls.dll"
;   PJSIPEnd:  
; 
This should be put in a DataSection:

Code: Select all

DataSection
  PJSIP:
    IncludeBinary "pjsipDll_notls.dll"
  PJSIPEnd:  
EndDataSection
 
You have a lot of commented sections here that are redundant, at least one and only one should be uncommented at a time but none are. The shared variable PJSIPLib is not declared anywhere else.

Code: Select all

  Procedure Init()
;     Shared PJSIPLib.i
    
;     OpenFile(0,(GetTemporaryDirectory()+"pjsipDll_notls.dll"))
;     WriteData(0,?PJSIP,(?PJSIPend-?PJSIP)):CloseFile(0)
;     OpenLibrary(0,(GetTemporaryDirectory()+"pjsipDll_notls.dll"))
    
;     CompilerIf #PB_Compiler_Debugger
      PJSIPLib = OpenLibrary(0, "pjsipDll_notls.dll")
;     CompilerElse
;       PJSIPLib = OpenLibrary(0, GetTemporaryDirectory()+"pjsipDll_notls.dll")
;     CompilerEndIf
infratec
Always Here
Always Here
Posts: 6810
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: [PB ALL]-With debugger works, no debugger does not work.

Post by infratec »

And you have to use

Code: Select all

PrototypeC
infratec
Always Here
Always Here
Posts: 6810
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: [PB ALL]-With debugger works, no debugger does not work.

Post by infratec »

Your SetSIPCallBack() is wrong.
You already give the address of the function as paramater, so you don't need the address of the address.

Code: Select all

  Procedure SetSIPCallBack(target.i, *function)
    
    Protected Result.i
    
    
    Select target
      Case #Register
        Result = CallCFunctionFast(*onRegStateCallback, *function)
      Case #State
        Result = CallCFunctionFast(*onCallStateCallback, *function)
      Case #Incomming
        Result = CallCFunctionFast(*onCallIncoming, *function)
      Case #Hold
        Result = CallCFunctionFast(*onCallHoldConfirmCallback, *function)
      Case #Received
        Result = CallCFunctionFast(*onMessageReceivedCallback, *function)
      Case #Status
        Result = CallCFunctionFast(*onBuddyStatusChangedCallback, *function)
      Case #DTMFDigit
        Result = CallCFunctionFast(*onDtmfDigitCallback, *function)
      Case #Waiting
        Result = CallCFunctionFast(*onMessageWaitingCallback, *function)
    EndSelect
    
    Debug "SetSipCallback: " + Str(Result)
    
  EndProcedure
User avatar
holzhacker
Enthusiast
Enthusiast
Posts: 123
Joined: Mon Mar 08, 2010 9:14 pm
Location: "Mens sana in corpore sano"
Contact:

Re: [PB ALL]-With debugger works, no debugger does not work.

Post by holzhacker »

I would like to thank everyone for the answers, unfortunately life is very busy and I have very little time to play so many parallel developments, but gradually I am following.

The initial result can be seen here as a minimally usable module: viewtopic.php?f=12&t=71926

Again many thanks to all
Greetings and thanks!

Romerio Medeiros
romerio@gmail.com
Post Reply