-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclsLoggerWatch.c
86 lines (75 loc) · 1.73 KB
/
clsLoggerWatch.c
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
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the ig-logger project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Original author: Christian Kaiser <[email protected]>
*/
#include "logig.h"
#include "clsExcept.h"
#include "clsLocalNet.h"
clsLoggerWatch::clsLoggerWatch(clsLocalNet* pLocalNet)
: clsThreadBase("clsLoggerWatch")
, _pLocalNet(pLocalNet)
{
ThreadStart();
}
clsLoggerWatch::~clsLoggerWatch()
{
ThreadJoin();
}
void clsLoggerWatch::Watch(const clsDeviceID& ID)
{
_ID = ID;
}
virtual DWORD clsLoggerWatch::ThreadFunction(void)
{
UINT nErrorCount = 0;
while (ThreadWait(1100))
{
if (_ID.bOk())
{
try
{
clsDeviceID ID;
if (_pLocalNet->QueryDataloggerID(ID))
{
// printf(" ID: %x-%x\n",nID,_nID);
if (ID != _ID)
{
_pLocalNet->AddException(
new clsExcept(
"Warning: datalogger ID did change unexpectedly!\n(old: %s, new: %s)",
(LPCTSTR)_ID.AsStr(),
(LPCTSTR)ID.AsStr()
));
}
nErrorCount = 0;
}
else
{
if (++nErrorCount >= 3)
{
_pLocalNet->AddException(
new clsConnectionLostExcept(
"Warning: datalogger %s cannot be reached!",
(LPCTSTR)_ID.AsStr()
));
}
}
}
catch (clsExceptBase& e)
{
e.Push("Warning: datalogger %s cannot be reached! %s",
(LPCTSTR)_ID.AsStr());
_pLocalNet->AddException(
new clsConnectionLostExcept(e));
}
}
}
return(0);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */