PylonBase.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. //-----------------------------------------------------------------------------
  2. // Basler pylon SDK
  3. // Copyright (c) 2006-2021 Basler AG
  4. // http://www.baslerweb.com
  5. // Author: AH
  6. //-----------------------------------------------------------------------------
  7. /*!
  8. \file
  9. \brief Function and classes for initializing the pylon runtime.
  10. */
  11. #pragma once
  12. #ifndef PYLONBASE_H__
  13. #define PYLONBASE_H__
  14. #include <pylon/Platform.h>
  15. #ifdef _MSC_VER
  16. # pragma pack(push, PYLON_PACKING)
  17. #endif /* _MSC_VER */
  18. #include <pylon/stdinclude.h>
  19. #ifdef PYLONBASE_EXPORTS
  20. # define PYLONBASE_API APIEXPORT
  21. #else
  22. # define PYLONBASE_API APIIMPORT
  23. #endif
  24. #if defined(PYLON_BASE_3_0_NO_DEPRECATE)
  25. # define PYLON_BASE_3_0_DEPRECATED(message)
  26. #else
  27. # define PYLON_BASE_3_0_DEPRECATED(message) PYLON_DEPRECATED(message)
  28. #endif
  29. namespace Pylon
  30. {
  31. /**
  32. \brief Initializes the pylon runtime system.
  33. You must call PylonInitialize before calling any other pylon functions.
  34. When finished you must call PylonTerminate to free up all resources used by pylon.
  35. You can use the helperclass PylonAutoInitTerm to let the compiler call
  36. PylonInitialze and PylonTerminate.
  37. Just create a local object on the stack in your main function and
  38. the constructor and destructor will call the functions.
  39. See PylonAutoInitTerm for a sample.
  40. PylonInitialize/PylonTerminate is reference counted. For every call of PylonInitialize, a call to PylonTerminate is required.
  41. The last call to PylonTerminate will free up all resources.
  42. \if windows
  43. For MFC applications we recommend to call PylonInitialize and PylonTerminate in the
  44. application's InitInstance() and ExitInstance() methods.
  45. This prevents the MFC runtime from reporting a huge number of pretended memory leaks.
  46. This does not apply to DLLs using MFC (see below)!
  47. \note
  48. Due to the limitations of functions allowed during DLLMain, it is not allowed to call PylonIntialize from DLLMain.
  49. For further information see the official documentation of DLLMain in the Windows documentation.
  50. \endif
  51. */
  52. PYLONBASE_API void CDECL PylonInitialize( void );
  53. /**
  54. \brief Frees up resources allocated by the pylon runtime system.
  55. Call this function before terminating the application. Don't use any pylon methods or pylon objects after
  56. having called PylonTerminate().
  57. PylonInitialize/PylonTerminate is reference counted. For every call of PylonInitialize, a call to PylonTerminate is required.
  58. The last call to PylonTerminate will free up all resources.
  59. \if windows
  60. \note
  61. Due to the limitations of functions allowed during DLLMain, it is not allowed to call PylonTerminate from DLLMain.
  62. For further information see the official documentation of DLLMain in the Windows documentation.
  63. \endif
  64. */
  65. PYLONBASE_API void CDECL PylonTerminate( bool ShutDownLogging = true );
  66. /**
  67. \brief Returns the version number of pylon
  68. It is possible to pass a NULL pointer for a version number category if the value is not of interest.
  69. */
  70. extern "C" PYLONBASE_API void CDECL GetPylonVersion( unsigned int* major, unsigned int* minor, unsigned int* subminor, unsigned int* build );
  71. /**
  72. \brief Returns the version number of pylon as string.
  73. */
  74. extern "C" PYLONBASE_API const char* CDECL GetPylonVersionString();
  75. /**
  76. \brief Set the value of a property.
  77. \param propertyId Identifies the property.
  78. \param pData A pointer to the buffer containing the data.
  79. \param size Size of the buffer in bytes.
  80. Call this function to set the value of a property.
  81. You must have called PylonInitialize() before you can call this function.
  82. */
  83. PYLONBASE_API void CDECL SetProperty( int propertyId, const void* pData, size_t size );
  84. /**
  85. \brief Get the value of a property.
  86. \param propertyId Identifies the property.
  87. \param pData A pointer to the buffer containing the data.
  88. \param pSize Size of the buffer in bytes when calling. Holds the resulting size on return.
  89. Call this function to get the value of a property.
  90. You must have called PylonInitialize() before you can call this function.
  91. */
  92. PYLONBASE_API void CDECL GetProperty( int propertyId, void* pData, size_t* pSize );
  93. /**
  94. \brief Helper class to automagically call PylonInitialize and PylonTerminate in constructor and destructor
  95. \code
  96. #include <pylon/TlFactory.h>
  97. // ...
  98. using namespace Pylon;
  99. int main(int argc, char* argv[])
  100. {
  101. PylonAutoInitTerm autoInitTerm;
  102. // Get the transport layer factory
  103. CTlFactory& TlFactory = CTlFactory::GetInstance();
  104. // Get all attached cameras and exit application if no camera is found
  105. DeviceInfoList_t devices;
  106. if ( 0 == TlFactory.EnumerateDevices( devices ) )
  107. {
  108. cerr << "No camera present!" << endl;
  109. return 1;
  110. }
  111. else
  112. {
  113. // do something with devices ...
  114. //...
  115. }
  116. return 0;
  117. } // When leaving the main function, the destructor of the PylonAutoInitTerm object will be called
  118. // and it will in turn call PylonTerminate.
  119. \endcode
  120. */
  121. class PylonAutoInitTerm
  122. {
  123. public:
  124. PYLONBASE_API PylonAutoInitTerm( void )
  125. {
  126. PylonInitialize();
  127. }
  128. PYLONBASE_API ~PylonAutoInitTerm( void )
  129. {
  130. PylonTerminate();
  131. }
  132. private:
  133. // unimplemented new operator to prevent creation on the heap which is a bad idea.
  134. // This object must be created in the local stack frame (see sample above)
  135. void* operator new(size_t);
  136. void* operator new[]( size_t );
  137. };
  138. } // namespace Pylon
  139. #ifdef _MSC_VER
  140. # pragma pack(pop)
  141. #endif /* _MSC_VER */
  142. #endif /* PYLONBASE_H__ */