1 | /***************************************************************************** |
---|
2 | File: $CVSROOT/support/opcApp/src/Group.cpp |
---|
3 | |
---|
4 | Project: OPC group class |
---|
5 | |
---|
6 | Description: Contents one OPC group and creates several OPC items |
---|
7 | |
---|
8 | Author: Winkler |
---|
9 | |
---|
10 | Version: $Revision: 0.91 $ |
---|
11 | |
---|
12 | History: |
---|
13 | |
---|
14 | $Log: Group.cpp,v $ |
---|
15 | |
---|
16 | |
---|
17 | Copyright: |
---|
18 | This software is copyrighted by the BERLINER SPEICHERRING |
---|
19 | GESELLSCHAFT FUER SYNCHROTRONSTRAHLUNG M.B.H., BERLIN, GERMANY. |
---|
20 | The following terms apply to all files associated with the software. |
---|
21 | |
---|
22 | BESSY hereby grants permission to use, copy and modify this |
---|
23 | software and its documentation for non-commercial, educational or |
---|
24 | research purposes provided that existing copyright notices are |
---|
25 | retained in all copies. |
---|
26 | |
---|
27 | The receiver of the software provides BESSY with all enhancements, |
---|
28 | including complete translations, made by the receiver. |
---|
29 | |
---|
30 | IN NO EVENT SHALL BESSY BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, |
---|
31 | SPECIAL, INCIDENTIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE |
---|
32 | OF THIS SOFTWARE, ITS DOCUMENTATION OR ANY DERIVATIVES THEREOF, EVEN |
---|
33 | IF BESSY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
34 | |
---|
35 | BESSY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED |
---|
36 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
---|
37 | PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" |
---|
38 | BASIS, AND BESSY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, |
---|
39 | UPDATES, ENHANCEMENTS OF MODIFICTAIONS. |
---|
40 | */ |
---|
41 | |
---|
42 | // Group.cpp: Implementation of CGroup class. |
---|
43 | // |
---|
44 | ////////////////////////////////////////////////////////////////////// |
---|
45 | |
---|
46 | #include "stdafx.h" |
---|
47 | #include "Item.h" |
---|
48 | #include "Group.h" |
---|
49 | extern int dbg_level; |
---|
50 | extern char szDbgMessage[256]; |
---|
51 | extern "C" int iIocInitReady; |
---|
52 | char * GroupId = |
---|
53 | "Group.cpp: $Revision: 0.91 $\n"; |
---|
54 | |
---|
55 | CGroup::CGroup(IN CServer* parent) |
---|
56 | { |
---|
57 | m_ItemCount = 0; |
---|
58 | m_Parent = parent; |
---|
59 | m_ItemArray = NULL; |
---|
60 | m_iRefreshTime = 0; |
---|
61 | m_hRefreshTimer = 0; |
---|
62 | } |
---|
63 | |
---|
64 | CGroup::~CGroup() |
---|
65 | { |
---|
66 | if(m_ItemArray) |
---|
67 | { |
---|
68 | for(unsigned long ul = 0;ul < m_ItemCount;ul++) |
---|
69 | { |
---|
70 | m_ItemArray[ul]->release(); |
---|
71 | m_ItemArray[ul] = NULL; |
---|
72 | } |
---|
73 | delete m_ItemArray; |
---|
74 | m_ItemArray = NULL; |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | BOOL CGroup::AddItem(LPCTSTR szItemID, LPCTSTR szPvName) |
---|
79 | { |
---|
80 | BOOL bResult = FALSE; |
---|
81 | if(m_ItemArray = (CItem**)realloc(m_ItemArray, (1+m_ItemCount)*sizeof(CItem**))) |
---|
82 | { |
---|
83 | if(m_ItemArray[m_ItemCount] = (CItem*)addItem(szItemID)) |
---|
84 | { |
---|
85 | m_ItemArray[m_ItemCount]->m_soItemID = szItemID; |
---|
86 | m_ItemArray[m_ItemCount]->m_sPvName = szPvName; |
---|
87 | m_ItemCount++; |
---|
88 | if(DBG_OPC_VARS & dbg_level) |
---|
89 | { |
---|
90 | sprintf(szDbgMessage," %s <==> %s (%d)",m_ItemArray[m_ItemCount-1]->m_soItemID,m_ItemArray[m_ItemCount-1]->m_sPvName.c_str(),m_ItemCount); |
---|
91 | dbgPrintf(DBG_OPC_VARS); |
---|
92 | szDbgMessage[0] = NULL; |
---|
93 | } |
---|
94 | bResult = TRUE; |
---|
95 | } |
---|
96 | } |
---|
97 | return bResult; |
---|
98 | } |
---|
99 | |
---|
100 | void CGroup::SetRefreshTimer(int iRefreshTime) |
---|
101 | { |
---|
102 | if(DBG_OPC_REFRESH & dbg_level) |
---|
103 | { |
---|
104 | sprintf(szDbgMessage,"SetRefreshTimer: %s will be refreshed every %d ms ",m_sGroupName.c_str(),iRefreshTime); |
---|
105 | dbgPrintf(DBG_OPC_REFRESH); |
---|
106 | szDbgMessage[0] = NULL; |
---|
107 | } |
---|
108 | m_iRefreshTime = iRefreshTime; |
---|
109 | if(m_hRefreshTimer == 0) |
---|
110 | m_hRefreshTimer = _beginthread(RefreshTimer, 0, this); |
---|
111 | // printf("(%lu)\n",m_hRefreshTimer); |
---|
112 | } |
---|
113 | |
---|
114 | void CGroup::RefreshTimer(void *param) |
---|
115 | { |
---|
116 | if(DBG_OPC_REFRESH & dbg_level) |
---|
117 | { |
---|
118 | sprintf(szDbgMessage,"\nRefresh-circle of Group %s started with %d ms refresh cycle.\n\tWaiting for \"iocInit()\" ...\n",((CGroup*)(param))->m_sGroupName.c_str(),((CGroup*)param)->m_iRefreshTime); |
---|
119 | dbgPrintf(DBG_OPC_REFRESH); |
---|
120 | szDbgMessage[0] = NULL; |
---|
121 | } |
---|
122 | while(((CGroup*)(param))->m_iRefreshTime > 0) |
---|
123 | { |
---|
124 | Sleep(((CGroup*)param)->m_iRefreshTime); |
---|
125 | if(iIocInitReady==1) |
---|
126 | { |
---|
127 | ((CGroup*)param)->asyncRefresh(OPC_DS_DEVICE);//OPC_DS_CACHE); |
---|
128 | if(DBG_OPC_REFRESH & dbg_level) |
---|
129 | { |
---|
130 | sprintf(szDbgMessage,"Group %s refreshed.",((CGroup*)(param))->m_sGroupName.c_str()); |
---|
131 | dbgPrintf(DBG_OPC_REFRESH); |
---|
132 | szDbgMessage[0] = NULL; |
---|
133 | } |
---|
134 | } |
---|
135 | } |
---|
136 | _endthread(); |
---|
137 | } |
---|