CommandParameter.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. //------------------------------------------------------------------------------
  2. // Basler pylon SDK
  3. // Copyright (c) 2018-2021 Basler AG
  4. // http://www.baslerweb.com
  5. //------------------------------------------------------------------------------
  6. /*!
  7. \file
  8. \brief Contains the class CCommandParameter used to simplify access to %GenApi parameters.
  9. */
  10. #ifndef INCLUDED_BASLER_PYLON_CCOMMANDPARAMETER_H
  11. #define INCLUDED_BASLER_PYLON_CCOMMANDPARAMETER_H
  12. #pragma once
  13. #include <pylon/PylonBase.h>
  14. #include <GenApi/ICommand.h>
  15. #include <pylon/Parameter.h>
  16. #ifdef _MSC_VER
  17. # pragma pack(push, PYLON_PACKING)
  18. #endif /* _MSC_VER */
  19. #ifdef _MSC_VER
  20. # pragma warning( push )
  21. # pragma warning( disable : 4275 ) // Class needs to have a dll interface to be used by clients of the class.
  22. # pragma warning( disable : 4250 ) // warning C4250: 'Pylon::CXYZParameter': inherits 'Pylon::CParameter::Pylon::CParameter::ZYX' via dominance
  23. #endif
  24. namespace Pylon
  25. {
  26. /*!
  27. \brief Extends the GenApi::ICommand interface with convenience methods.
  28. */
  29. interface ICommandEx : virtual public GenApi::ICommand, virtual public IValueEx
  30. {
  31. using GenApi::ICommand::operator=;
  32. /*!
  33. \brief Executes the command and returns immediately if the parameter is writable.
  34. \return Returns false if the parameter is not writable.
  35. \threading
  36. The method accesses the parameter multiple times. These accesses are not synchronized by a lock.
  37. \error
  38. Can throw exceptions if accessing the camera failed.
  39. */
  40. virtual bool TryExecute() = 0;
  41. };
  42. /*!
  43. \brief CCommandParameter class used to simplify access to %GenApi parameters.
  44. */
  45. class PYLONBASE_API CCommandParameter : public ICommandEx, public CParameter
  46. {
  47. public:
  48. /*!
  49. \brief Creates an empty CCommandParameter object.
  50. \error
  51. Does not throw C++ exceptions.
  52. */
  53. CCommandParameter();
  54. /*!
  55. \brief Creates a CCommandParameter object and attaches it to a node, typically retrieved for a nodemap calling GetNode().
  56. \param[in] pNode The node to attach.
  57. \post
  58. <ul>
  59. <li>If the passed node does not match the parameter type, the parameter will be empty, see IsValid().
  60. <li>If the passed node does match the parameter type, it is attached and the parameter object can be used to access the node's functionality.
  61. <li>The parameter object must not be used to access the node's functionality if the source of the attached \c pNode has been destroyed. In this case, call Release() or attach a new node.
  62. </ul>
  63. \error
  64. Does not throw C++ exceptions.
  65. */
  66. explicit CCommandParameter( GenApi::INode* pNode );
  67. /*!
  68. \brief Creates a CCommandParameter object and attaches it to a node of a matching type.
  69. \param[in] pCommand The node to attach.
  70. \post
  71. The parameter object must not be used to access the node's functionality if the source of the attached \c pCommand has been destroyed. In this case, call Release() or attach a new node.
  72. \error
  73. Does not throw C++ exceptions.
  74. */
  75. explicit CCommandParameter( GenApi::ICommand* pCommand );
  76. /*!
  77. \brief Creates a CCommandParameter object and attaches it to a node retrieved from the provided node map.
  78. \param[in] pNodeMap The node map. The source of the parameter.
  79. \param[in] pName The name of the parameter to attach.
  80. \post
  81. <ul>
  82. <li>If \c pNodeMap or \c name is NULL, the parameter will be empty, see IsValid().
  83. <li>If the node does not match the parameter type, the parameter will be empty, see IsValid().
  84. <li>If the node does match the parameter type, it is attached and the parameter object can be used to access the node's functionality.
  85. <li>The parameter object must not be used to access the node's functionality if the provided node map has been destroyed. In this case, call Release() or attach a new node.
  86. </ul>
  87. \error
  88. The call to GenApi::INodeMap::GetNode can throw C++ exceptions.
  89. */
  90. CCommandParameter( GenApi::INodeMap* pNodeMap, const char* pName );
  91. /*!
  92. \brief Creates a CCommandParameter object and attaches it to a node retrieved from the provided node map.
  93. \param[in] nodeMap The node map. The source of the parameter.
  94. \param[in] pName The name of the parameter to attach.
  95. \post
  96. <ul>
  97. <li>If \c name is NULL, the parameter will be empty, see IsValid().
  98. <li>If the node does not match the parameter type, the parameter will be empty, see IsValid().
  99. <li>If the node does match the parameter type, it is attached and the parameter object can be used to access the node's functionality.
  100. <li>The parameter object must not be used to access the node's functionality if the provided node map has been destroyed. In this case, call Release() or attach a new node.
  101. </ul>
  102. \error
  103. The call to GenApi::INodeMap::GetNode can throw C++ exceptions.
  104. */
  105. CCommandParameter( GenApi::INodeMap& nodeMap, const char* pName );
  106. /*!
  107. \brief Copies a CCommandParameter object.
  108. \param[in] rhs The object to copy.
  109. \error
  110. Does not throw C++ exceptions.
  111. */
  112. CCommandParameter( const CCommandParameter& rhs );
  113. /*!
  114. \brief Destroys the CCommandParameter object.
  115. Does not access the attached node.
  116. \error
  117. Does not throw C++ exceptions.
  118. */
  119. virtual ~CCommandParameter();
  120. /*!
  121. \brief Attaches a node retrieved from the provided node map.
  122. \param[in] pNodeMap The node map. The source of the parameter.
  123. \param[in] pName The name of the parameter to attach.
  124. \return Returns true if the node has been attached.
  125. \post
  126. <ul>
  127. <li>If \c pNodeMap or \c name is NULL, the parameter will be empty, see IsValid().
  128. <li>If the node does not match the parameter type, the parameter will be empty, see IsValid().
  129. <li>If the node does match the parameter type, it is attached and the parameter object can be used to access the node's functionality.
  130. <li>The parameter object must not be used to access the node's functionality if the provided node map has been destroyed. In this case, call Release() or attach a new node.
  131. </ul>
  132. \error
  133. The call to GenApi::INodeMap::GetNode can throw C++ exceptions.
  134. */
  135. virtual bool Attach( GenApi::INodeMap* pNodeMap, const char* pName );
  136. /*!
  137. \brief Attaches a node retrieved from the provided node map.
  138. \param[in] nodeMap The node map. The source of the parameter.
  139. \param[in] pName The name of the parameter to attach.
  140. \return Returns true if the node has been attached.
  141. \post
  142. <ul>
  143. <li>If \c name is NULL the parameter will be empty, see IsValid().
  144. <li>If the node does not match the parameter type, the parameter will be empty, see IsValid().
  145. <li>If the node does match the parameter type, it is attached and the parameter object can be used to access the node's functionality.
  146. <li>The parameter object must not be used to access the node's functionality if the provided node map has been destroyed. In this case, call Release() or attach a new node.
  147. </ul>
  148. \error
  149. The call to GenApi::INodeMap::GetNode can throw C++ exceptions.
  150. */
  151. virtual bool Attach( GenApi::INodeMap& nodeMap, const char* pName );
  152. /*!
  153. \brief Attaches a node, typically retrieved for a nodemap calling GetNode().
  154. \param[in] pNode The node to assign.
  155. \return Returns true if the node has been attached.
  156. \post
  157. <ul>
  158. <li>If the node does not match the parameter type, the parameter will be empty, see IsValid().
  159. <li>If the node does match the parameter type, it is attached and the parameter object can be used to access the node's functionality.
  160. <li>The parameter object must not be used to access the node's functionality if the source of the attached \c pNode has been destroyed. In this case, call Release() or attach a new node.
  161. </ul>
  162. \error
  163. Does not throw C++ exceptions.
  164. */
  165. virtual bool Attach( GenApi::INode* pNode );
  166. /*!
  167. \brief Assigns a node of the same type to the parameter object.
  168. \param[in] pCommand The node to assign.
  169. \return Returns true if the node has been attached.
  170. \error
  171. Does not throw C++ exceptions.
  172. */
  173. virtual bool Attach( GenApi::ICommand* pCommand );
  174. /*!
  175. \brief Assigns a CCommandParameter object.
  176. \param[in] rhs The object to assign.
  177. \error
  178. Does not throw C++ exceptions.
  179. */
  180. CCommandParameter& operator=( const CCommandParameter& rhs );
  181. /*!
  182. \brief Returns true if the same nodes are attached or both parameters are empty.
  183. \param[in] rhs The object to compare to.
  184. \return Returns true if the same nodes are attached or both parameters are empty.
  185. \error
  186. Does not throw C++ exceptions.
  187. */
  188. virtual bool Equals( const CCommandParameter& rhs ) const;
  189. /*!
  190. \brief Returns true if the attached node pointer is equal.
  191. \param[in] pNode The node to compare to.
  192. \return Returns true if the attached node pointer is equal.
  193. \error
  194. Does not throw C++ exceptions.
  195. */
  196. virtual bool Equals( const GenApi::INode* pNode ) const;
  197. /*!
  198. \brief Returns true if the attached node pointer is equal.
  199. \param[in] pCommand The node to compare to.
  200. \return Returns true if the attached node pointer is equal.
  201. \error
  202. Does not throw C++ exceptions.
  203. */
  204. virtual bool Equals( const GenApi::ICommand* pCommand ) const;
  205. /*!
  206. \brief Releases the attached node.
  207. \error
  208. Does not throw C++ exceptions.
  209. */
  210. virtual void Release();
  211. // Implements IValueEx
  212. virtual bool IsValid() const;
  213. // Implements GenApi::ICommand
  214. virtual void Execute( bool verify = true );
  215. // Implements GenApi::ICommand
  216. virtual void operator()();
  217. // Implements GenApi::ICommand
  218. virtual bool IsDone( bool verify = true );
  219. // Implements ICommandEx
  220. virtual bool TryExecute();
  221. protected:
  222. GenApi::ICommand* m_pFeature;
  223. };
  224. }
  225. #ifdef _MSC_VER
  226. # pragma warning( pop )
  227. #endif
  228. #ifdef _MSC_VER
  229. # pragma pack(pop)
  230. #endif /* _MSC_VER */
  231. #endif /* INCLUDED_BASLER_PYLON_CCOMMANDPARAMETER_H */