appkit  1.5.1
RoadNarrows Robotics Application Kit
SessionWin.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: RoadNarrows Robotics Application Tool Kit
4 //
5 // Link: https://github.com/roadnarrows-robotics/rnr-sdk
6 //
7 // Library: librnr_win
8 //
9 // File: SessionWin.h
10 //
11 /*! \file
12  *
13  * $LastChangedDate: 2013-07-13 13:54:59 -0600 (Sat, 13 Jul 2013) $
14  * $Rev: 3122 $
15  *
16  * \brief SessionWin derived class.
17  *
18  * \author Robin Knight (robin.knight@roadnarrows.com)
19  * \author Daniel Packard (daniel@roadnarrows.com)
20  *
21  * \par Copyright
22  * \h_copy 2012-2017. RoadNarrows LLC.\n
23  * http://www.roadnarrows.com\n
24  * All Rights Reserved
25  */
26 /*
27  * @EulaBegin@
28  *
29  * Permission is hereby granted, without written agreement and without
30  * license or royalty fees, to use, copy, modify, and distribute this
31  * software and its documentation for any purpose, provided that
32  * (1) The above copyright notice and the following two paragraphs
33  * appear in all copies of the source code and (2) redistributions
34  * including binaries reproduces these notices in the supporting
35  * documentation. Substantial modifications to this software may be
36  * copyrighted by their authors and need not follow the licensing terms
37  * described here, provided that the new terms are clearly indicated in
38  * all files where they apply.
39  *
40  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
41  * OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
42  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
43  * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
44  * EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
45  * THE POSSIBILITY OF SUCH DAMAGE.
46  *
47  * THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
48  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
49  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
50  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
51  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
52  *
53  * @EulaEnd@
54  */
55 ////////////////////////////////////////////////////////////////////////////////
56 
57 #ifndef _RNR_SESSION_WIN_H
58 #define _RNR_SESSION_WIN_H
59 
60 #include <stdio.h>
61 
62 #include <string>
63 
64 #include "rnr/rnrconfig.h"
65 
66 #include "rnr/appkit/Win.h"
67 #include "rnr/appkit/State.h"
68 #include "rnr/appkit/StateMach.h"
69 #include "rnr/appkit/Session.h"
70 
71 /*!
72  * \brief RoadNarrows Robotics
73  */
74 namespace rnr
75 {
76  //----------------------------------------------------------------------------
77  // SessionWin Class
78  //----------------------------------------------------------------------------
79 
80  /*!
81  * Workflow Session Class
82  *
83  * Session state persist throughout the livetime of an application. A series
84  * of workflow states, each with its on finite state machine, is supportedc.
85  */
86  class SessionWin : public Session
87  {
88  public:
89  /*!
90  * \brief Video source types.
91  */
93  {
94  VideoSrcTypeDevice = 0, ///< source direct from video device
95  VideoSrcTypeUdp, ///< source from UDP stream
96  VideoSrcTypeFile, ///< source from file
97  VideoSrcTypeNumOf ///< number of video source types
98  };
99 
100  static const VideoSrcType VideoSrcTypeDft = VideoSrcTypeDevice;
101  static const char * const VideoDevNameDft;
102  static const int VideoIndexDft = 0;
103  static const int VideoPortDft = 4000;
104 
105  /*!
106  * \brief Default initialization contructor.
107  *
108  * \param nSessionId Session id.
109  * \param strSessionName Session name.
110  * \param pWin Pointer to created window.
111  */
112  SessionWin(int nSessionId = 0,
113  const std::string &strSessionName = "Session",
114  Win *pWin = NULL) :
115  Session(nSessionId, strSessionName),
116  m_pWin(pWin),
117  m_eVideoSrcType(VideoSrcTypeDft),
118  m_strVideoDevName(VideoDevNameDft),
119  m_nVideoIndex(VideoIndexDft),
120  m_nVideoPort(VideoPortDft)
121  {
122  }
123 
124  /*!
125  * \brief Destructor.
126  */
128  {
129  if( m_pWin != NULL )
130  {
131  delete m_pWin;
132  }
133  }
134 
135  /*!
136  * \brief Set session's window.
137  *
138  * The session own the window object and will delete it window replacement
139  * or on session object deletion.
140  *
141  * \param pWin Pointer to window object.
142  */
143  void setWin(Win *pWin)
144  {
145  if( m_pWin != NULL )
146  {
147  delete m_pWin;
148  }
149  m_pWin = pWin;
150  }
151 
152  /*!
153  * \brief Get the session window object.
154  *
155  * \return Pointer to the window object.
156  */
158  {
159  return m_pWin;
160  }
161 
162  /*!
163  * \brief Get the session window object.
164  *
165  * \return Reference to the window object. Cannot be null.
166  */
167  Win &win()
168  {
169  return *m_pWin;
170  }
171 
172  /*!
173  * \brief Get the video source type.
174  *
175  * \return Return one of \ref VideoSrcType.
176  */
178  {
179  return m_eVideoSrcType;
180  }
181 
182  /*!
183  * \brief Set the video source type.
184  *
185  * \param eVideoSrcType One of \ref VideoSrcType.
186  */
187  void setVideoSrcType(VideoSrcType eVideoSrcType)
188  {
189  m_eVideoSrcType = eVideoSrcType;
190  }
191 
192  /*!
193  * \brief Set the video device name.
194  *
195  * The video index (device minor number) is determined and also set.
196  *
197  * \param strVideoDevName Video device name.
198  */
199  int setVideoDevice(const std::string &strVideoDevName);
200 
201  /*!
202  * \brief Get the video device name.
203  *
204  * \return String.
205  */
206  std::string getVideoDevName()
207  {
208  return m_strVideoDevName;
209  }
210 
211  /*!
212  * \brief Get the video device index.
213  *
214  * \return Integer index.
215  */
217  {
218  return m_nVideoIndex;
219  }
220 
221  /*!
222  * \brief Get the video index associated with the device.
223  *
224  * \param strVideoDevName Video camera device name.
225  *
226  * \return Returns video index on success, \ref RC_ERROR(-1) on failure.
227  */
228  int getVideoIndex(const std::string &strVideoDevName);
229 
230  /*!
231  * \brief Get the video stream port.
232  *
233  * \return UDP port.
234  */
236  {
237  return m_nVideoPort;
238  }
239 
240  /*!
241  * \brief Set the video stream port.
242  *
243  * \param nVideoPort UDP port.
244  */
245  void setVideoPort(int nVideoPort)
246  {
247  m_nVideoPort = nVideoPort;
248  }
249 
250  protected:
251  Win *m_pWin; ///< application main gui window
252  VideoSrcType m_eVideoSrcType; ///< video source type
253  std::string m_strVideoDevName; ///< video device name
254  int m_nVideoIndex; ///< video index (device minor number)
255  int m_nVideoPort; ///< video stream UDP/IP port
256  };
257 
258 } // namespace rnr
259 
260 
261 #endif // _RNR_SESSION_WIN_H
Session base class.
SessionWin(int nSessionId=0, const std::string &strSessionName="Session", Win *pWin=NULL)
Default initialization contructor.
Definition: SessionWin.h:112
Win & win()
Get the session window object.
Definition: SessionWin.h:167
int getVideoIndex()
Get the video device index.
Definition: SessionWin.h:216
~SessionWin()
Destructor.
Definition: SessionWin.h:127
number of video source types
Definition: SessionWin.h:97
VideoSrcType
Video source types.
Definition: SessionWin.h:92
std::string m_strVideoDevName
video device name
Definition: SessionWin.h:253
int m_nVideoPort
video stream UDP/IP port
Definition: SessionWin.h:255
Win * getWin()
Get the session window object.
Definition: SessionWin.h:157
source from UDP stream
Definition: SessionWin.h:95
Finite State Machine interface.
source direct from video device
Definition: SessionWin.h:94
RoadNarrows Robotics Win abstract base class interface.
Win * m_pWin
application main gui window
Definition: SessionWin.h:251
VideoSrcType getVideoSrcType()
Get the video source type.
Definition: SessionWin.h:177
Session Class.
Definition: Session.h:84
void setWin(Win *pWin)
Set session&#39;s window.
Definition: SessionWin.h:143
void setVideoPort(int nVideoPort)
Set the video stream port.
Definition: SessionWin.h:245
int getVideoPort()
Get the video stream port.
Definition: SessionWin.h:235
int m_nVideoIndex
video index (device minor number)
Definition: SessionWin.h:254
RNR Win window abstract base class.
Definition: Win.h:211
State base class interface.
void setVideoSrcType(VideoSrcType eVideoSrcType)
Set the video source type.
Definition: SessionWin.h:187
int setVideoDevice(const std::string &strVideoDevName)
Set the video device name.
Definition: SessionWin.cxx:77
RoadNarrows Robotics.
Definition: Camera.h:74
VideoSrcType m_eVideoSrcType
video source type
Definition: SessionWin.h:252
std::string getVideoDevName()
Get the video device name.
Definition: SessionWin.h:206