- Changes in logging and debug output
[public/netxms.git] / src / console / win32 / DCIDataView.cpp
1 // DCIDataView.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "nxcon.h"
6 #include "DCIDataView.h"
7
8 #ifdef _DEBUG
9 #define new DEBUG_NEW
10 #undef THIS_FILE
11 static char THIS_FILE[] = __FILE__;
12 #endif
13
14 /////////////////////////////////////////////////////////////////////////////
15 // CDCIDataView
16
17 IMPLEMENT_DYNCREATE(CDCIDataView, CMDIChildWnd)
18
19 CDCIDataView::CDCIDataView()
20 {
21 }
22
23 CDCIDataView::CDCIDataView(DWORD dwNodeId, DWORD dwItemId)
24 {
25 m_dwNodeId = dwNodeId;
26 m_dwItemId = dwItemId;
27 }
28
29 CDCIDataView::~CDCIDataView()
30 {
31 }
32
33
34 BEGIN_MESSAGE_MAP(CDCIDataView, CMDIChildWnd)
35 //{{AFX_MSG_MAP(CDCIDataView)
36 ON_WM_CREATE()
37 ON_WM_DESTROY()
38 ON_WM_SIZE()
39 ON_WM_SETFOCUS()
40 ON_COMMAND(ID_VIEW_REFRESH, OnViewRefresh)
41 //}}AFX_MSG_MAP
42 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_VIEW, OnListViewItemChange)
43 END_MESSAGE_MAP()
44
45 /////////////////////////////////////////////////////////////////////////////
46 // CDCIDataView message handlers
47
48
49 //
50 // WM_CREATE message handler
51 //
52
53 int CDCIDataView::OnCreate(LPCREATESTRUCT lpCreateStruct)
54 {
55 RECT rect;
56 static int widths[3] = { 80, 200, -1 };
57
58 if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
59 return -1;
60
61 GetClientRect(&rect);
62
63 m_wndStatusBar.Create(WS_CHILD | WS_VISIBLE, rect, this, IDC_STATUS_BAR);
64 m_wndStatusBar.SetParts(3, widths);
65
66 m_iStatusBarHeight = GetWindowSize(&m_wndStatusBar).cy;
67 rect.bottom -= m_iStatusBarHeight;
68 m_wndListCtrl.Create(WS_CHILD | WS_VISIBLE | LVS_REPORT, rect, this, IDC_LIST_VIEW);
69 m_wndListCtrl.SetExtendedStyle(LVS_EX_TRACKSELECT | LVS_EX_UNDERLINEHOT |
70 LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
71 m_wndListCtrl.SetHoverTime(0x7FFFFFFF);
72
73 // Setup columns
74 m_wndListCtrl.InsertColumn(0, "Timestamp", LVCFMT_LEFT, 130);
75 m_wndListCtrl.InsertColumn(1, "Value", LVCFMT_LEFT,
76 rect.right - 130 - GetSystemMetrics(SM_CXVSCROLL));
77
78 PostMessage(WM_COMMAND, ID_VIEW_REFRESH, 0);
79
80 return 0;
81 }
82
83
84 //
85 // WM_DESTROY message handler
86 //
87
88 void CDCIDataView::OnDestroy()
89 {
90 CMDIChildWnd::OnDestroy();
91
92 // TODO: Add your message handler code here
93
94 }
95
96
97 //
98 // WM_SIZE message handler
99 //
100
101 void CDCIDataView::OnSize(UINT nType, int cx, int cy)
102 {
103 CMDIChildWnd::OnSize(nType, cx, cy);
104
105 m_wndStatusBar.SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOZORDER);
106 m_wndListCtrl.SetWindowPos(NULL, 0, 0, cx, cy - m_iStatusBarHeight, SWP_NOZORDER);
107 }
108
109
110 //
111 // WM_SETFOCUS message handler
112 //
113
114 void CDCIDataView::OnSetFocus(CWnd* pOldWnd)
115 {
116 CMDIChildWnd::OnSetFocus(pOldWnd);
117
118 m_wndListCtrl.SetFocus();
119 }
120
121
122 //
123 // WM_COMMAND::ID_VIEW_REFRESH message handler
124 //
125
126 void CDCIDataView::OnViewRefresh()
127 {
128 DWORD dwResult;
129 int iItem;
130 NXC_DCI_DATA *pData;
131
132 m_wndListCtrl.DeleteAllItems();
133 dwResult = DoRequestArg6(NXCGetDCIData, (void *)m_dwNodeId, (void *)m_dwItemId,
134 (void *)1000, 0, 0, &pData, "Loading item data...");
135 if (dwResult == RCC_SUCCESS)
136 {
137 DWORD i;
138 NXC_DCI_ROW *pRow;
139 char szBuffer[256];
140
141 for(i = 0, pRow = pData->pRows; i < pData->dwNumRows; i++)
142 {
143 FormatTimeStamp(pRow->dwTimeStamp, szBuffer, TS_LONG_DATE_TIME);
144 iItem = m_wndListCtrl.InsertItem(0x7FFFFFFF, szBuffer);
145 if (iItem != -1)
146 {
147 if (pData->wDataType == DCI_DT_STRING)
148 {
149 m_wndListCtrl.SetItemText(iItem, 1, pRow->value.szString);
150 }
151 else
152 {
153 switch(pData->wDataType)
154 {
155 case DCI_DT_INT:
156 sprintf(szBuffer, "%ld", pRow->value.dwInt32);
157 break;
158 case DCI_DT_UINT:
159 sprintf(szBuffer, "%lu", pRow->value.dwInt32);
160 break;
161 case DCI_DT_INT64:
162 sprintf(szBuffer, "%I64d", pRow->value.qwInt64);
163 break;
164 case DCI_DT_UINT64:
165 sprintf(szBuffer, "%I64u", pRow->value.qwInt64);
166 break;
167 case DCI_DT_FLOAT:
168 sprintf(szBuffer, "%f", pRow->value.dFloat);
169 break;
170 default:
171 sprintf(szBuffer, "Unknown data type (%d)", pData->wDataType);
172 break;
173 }
174 m_wndListCtrl.SetItemText(iItem, 1, szBuffer);
175 }
176 }
177 inc_ptr(pRow, pData->wRowSize, NXC_DCI_ROW);
178 }
179 sprintf(szBuffer, "%d rows", pData->dwNumRows);
180 m_wndStatusBar.SetText(szBuffer, 0, 0);
181 NXCDestroyDCIData(pData);
182 }
183 else
184 {
185 theApp.ErrorBox(dwResult, "Unable to retrieve colected data: %s");
186 iItem = m_wndListCtrl.InsertItem(0, "");
187 if (iItem != -1)
188 m_wndListCtrl.SetItemText(iItem, 1, "ERROR LOADING DATA FROM SERVER");
189 }
190 }
191
192
193 //
194 // WM_NOTIFY::LVN_ITEMACTIVATE message handler
195 //
196
197 void CDCIDataView::OnListViewItemChange(LPNMLISTVIEW pNMHDR, LRESULT *pResult)
198 {
199 if (pNMHDR->iItem != -1)
200 if (pNMHDR->uChanged & LVIF_STATE)
201 {
202 if (pNMHDR->uNewState & LVIS_FOCUSED)
203 {
204 char szBuffer[64];
205
206 sprintf(szBuffer, "Current row: %d", pNMHDR->iItem + 1);
207 m_wndStatusBar.SetText(szBuffer, 1, 0);
208 }
209 else
210 {
211 m_wndStatusBar.SetText("", 1, 0);
212 }
213 }
214 }