mrDarker
2025-08-13 5cc675212e96d87ebbf00f4fd7a8106b06a490ff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// MCpp_ChannelImpl.h - MULTICAM C++ API - ChannelImpl
#if !defined(__MCPP_CHANNELIMPL_H__)
#define __MCPP_CHANNELIMPL_H__
 
#include "MCpp_Channel.h"
 
namespace Euresys
{
  namespace MultiCam
  {
    // Constructors
    inline Channel::Channel(Board *b, int Connector) :
    SurfaceList(NULL)
    {
      try {
        InitChannel(b);
        SetParam(MC_Connector, Connector);
      } catch (...) {
        if (Handle != 0)
          McDelete(Handle);
        delete SurfaceList;
        throw;
      }
    }
 
    inline Channel::Channel(Board *b, const char *Connector) :
    SurfaceList(NULL)
    {
      try {
        InitChannel(b);
        SetParam(MC_Connector, Connector);
      } catch (...) {
        if (Handle != 0)
          McDelete(Handle);
        delete SurfaceList;
        throw;
      }
    }
 
    inline void Channel::InitChannel(Board *b)
    {
      WRAPPING_MEMBERS_INIT
 
      MCSTATUS status;
      MCHANDLE handle;
      int boardIx;
 
      status = McCreate(MC_CHANNEL, &handle);
      if (status != MC_OK)
        ThrowMultiCamException(status, TYPE_CREATE, "Channel");
      Handle = handle;
 
      b->GetParam(MC_DriverIndex, boardIx);
      SetParam(MC_DriverIndex, boardIx);
 
      SurfaceList = new Internal::List<Surface *, 16>();
    }
 
    // Destructor
    inline Channel::~Channel()
    {
      MCSTATUS status;
      int i;
 
      if (Handle != 0)
      {
        status = McDelete(Handle);
        if (status != MC_OK)
          ThrowMultiCamException(status, TYPE_DELETE, "Channel");
      }
 
      for (i = 0 ; i < SurfaceList->GetCount() ; i++)
      {
        if (SurfaceList->At(i) != NULL)
          delete SurfaceList->At(i);
      }
      delete SurfaceList;
 
      WRAPPING_MEMBERS_UNINIT
    }
 
    // Channel activation
    inline void Channel::SetActive()
    {
      SetParam(MC_ChannelState, MC_ChannelState_ACTIVE);
    }
 
    // Channel deactivation
    inline void Channel::SetIdle()
    {
      int state;
 
      GetParam(MC_ChannelState, state);
      if (state == MC_ChannelState_ACTIVE)
        SetParam(MC_ChannelState, MC_ChannelState_IDLE);
    }
 
    // Channel preparation
    inline void Channel::Prepare()
    {
      int state;
 
      GetParam(MC_ChannelState, state);
      if (state == MC_ChannelState_ORPHAN)
        SetParam(MC_ChannelState, MC_ChannelState_IDLE);
      else if (state != MC_ChannelState_ACTIVE)
        SetParam(MC_ChannelState, MC_ChannelState_READY);
    }
 
    // Get Surface from handle
    inline Surface *Channel::GetSurface(MCHANDLE sHandle)
    {
      MCSTATUS status;
      void *address;
      Surface *surface;
 
      if ((sHandle & 0xF0000000) != (MC_DEFAULT_SURFACE_HANDLE & 0xF0000000))
        ThrowMultiCamException(MC_INVALID_VALUE);
      status = McGetParamPtr(sHandle, MC_sctxt, &address);
      if (status != MC_OK)
      {
        Euresys::MultiCam::Exception e(status, "µC++ Internal Error");
        throw e;
      }
 
      if (address != NULL)
        surface = reinterpret_cast<Surface *>(address);
      else
      {
        surface = new Surface(sHandle);
        SurfaceList->Add(surface);
      }
 
      return surface;
    }
 
  }
}
#endif