test.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // test.cpp : Defines the entry point for the console application.
  2. //
  3. #include "stdafx.h"
  4. #include <assert.h>
  5. #include <api_engine.h>
  6. #include <api_stack.h>
  7. #define STACK_ID 1234
  8. #ifdef WIN32
  9. # include <windows.h>
  10. #endif
  11. /* Event listening using a static method */
  12. void OnRegistrationStateChanged(int stack_id, dgo::sip_state_registration_t state, int sipcode, const char* sipdesc)
  13. {
  14. /* check if it's our stack */
  15. if(stack_id != STACK_ID) return;
  16. switch(state)
  17. {
  18. case dgo::srs_none: printf("Test_OnRegistrationStateChanged: %s(%s)\n", "srs_none", sipdesc); break;
  19. case dgo::srs_trying: printf("Test_OnRegistrationStateChanged: %s(%s)\n", "srs_trying", sipdesc); break;
  20. case dgo::srs_authentifying: printf("Test_OnRegistrationStateChanged: %s(%s)\n", "srs_authentifying", sipdesc); break;
  21. case dgo::srs_unregistered: printf("Test_OnRegistrationStateChanged: %s(%s)\n", "srs_unregistered", sipdesc); break;
  22. case dgo::srs_registered: printf("Test_OnRegistrationStateChanged: %s(%s)\n", "srs_registered", sipdesc); break;
  23. }
  24. }
  25. int _tmain(int argc, _TCHAR* argv[])
  26. {
  27. /* MUST call this function to initialize the engine befor using the first stack */
  28. assert( ERR_SUCCEED(dgo::engine_initialize()) );
  29. /* create the stack */
  30. dgo::stack* stack = new dgo::stack(STACK_ID);
  31. /* Events registration */
  32. stack->registrationStateChanged.connect(&OnRegistrationStateChanged);
  33. /* check that the stack has been successfuly initialized */
  34. assert(stack->get_initialized());
  35. /* MUST: Initialize mandatory parameters */
  36. stack->set_public_id("sip:bob@ims.inexbee.com");
  37. stack->set_private_id("bob@ims.inexbee.com");
  38. stack->set_pcscf("192.168.0.14");
  39. stack->set_pcscf_port(4060);
  40. stack->set_realm("ims.inexbee.com");
  41. /* Not mandatory but must be set before starting */
  42. stack->set_sigcomp(true);
  43. /* run stack */
  44. assert( ERR_SUCCEED(stack->run()) );
  45. /* set other optional parameters */
  46. stack->set_displayname("Doubango");
  47. stack->set_privacy("none");
  48. stack->set_password("bob");
  49. stack->set_early_ims(false);
  50. stack->set_expires(10);
  51. /* register */
  52. stack->sip_register();
  53. /* wait */
  54. #ifdef WIN32
  55. Sleep(500000);
  56. #else
  57. getchar();
  58. #endif
  59. /* Now it's time to unregister */
  60. stack->sip_unregister();
  61. /* wait */
  62. getchar();
  63. /* destroy the engine and unregister all identities*/
  64. assert( ERR_SUCCEED(dgo::engine_deinitialize()) );
  65. return 0;
  66. }