Subversion Repositories HomeAutomation

Rev

Rev 1601 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1601 Rev 1606
1
/*
1
/*
2
 *
2
 *
3
 *  Copyright (C) 2010  Mattias Runge
3
 *  Copyright (C) 2010  Mattias Runge
4
 *
4
 *
5
 *  This program is free software; you can redistribute it and/or modify
5
 *  This program is free software; you can redistribute it and/or modify
6
 *  it under the terms of the GNU General Public License as published by
6
 *  it under the terms of the GNU General Public License as published by
7
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  the Free Software Foundation; either version 2 of the License, or
8
 *  (at your option) any later version.
8
 *  (at your option) any later version.
9
 *
9
 *
10
 *  This program is distributed in the hope that it will be useful,
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
13
 *  GNU General Public License for more details.
14
 *
14
 *
15
 *  You should have received a copy of the GNU General Public License along
15
 *  You should have received a copy of the GNU General Public License along
16
 *  with this program; if not, write to the Free Software Foundation, Inc.,
16
 *  with this program; if not, write to the Free Software Foundation, Inc.,
17
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
 *
18
 *
19
 */
19
 */
20
 
20
 
21
#include "Node.h"
21
#include "Node.h"
22
 
22
 
23
#include <boost/date_time/posix_time/posix_time.hpp>
23
#include <boost/date_time/posix_time/posix_time.hpp>
24
 
24
 
25
#include "Message.h"
25
#include "Message.h"
26
#include "broker/Manager.h"
26
#include "broker/Manager.h"
27
 
27
 
28
namespace atom {
28
namespace atom {
29
namespace can {
29
namespace can {
30
   
30
   
31
Node::Node(Node::Id id)
31
Node::Node(Node::Id id)
32
{
32
{
33
    this->state_ = STATE_OFFLINE;
33
    this->state_ = STATE_OFFLINE;
34
    this->id_ = id;
34
    this->id_ = id;
35
}
35
}
36
 
36
 
37
Node::~Node()
37
Node::~Node()
38
{
38
{
39
 
39
 
40
}
40
}
41
 
41
 
42
Node::Id Node::GetId()
42
Node::Id Node::GetId()
43
{
43
{
44
    return this->id_;
44
    return this->id_;
45
}
45
}
46
 
46
 
47
Node::State Node::GetState()
47
Node::State Node::GetState()
48
{
48
{
49
    return this->state_;
49
    return this->state_;
50
}
50
}
51
 
51
 
52
void Node::SetState(Node::State state)
52
void Node::SetState(Node::State state)
53
{
53
{
54
    this->state_ = state;
54
    this->state_ = state;
55
}
55
}
56
 
56
 
57
bool Node::CheckTimeout()
57
bool Node::CheckTimeout()
58
{
58
{
-
 
59
    if (this->state_ == STATE_OFFLINE)
-
 
60
    {
-
 
61
        return true;
-
 
62
    }
-
 
63
   
59
    if (this->last_active_ + 10 < time(NULL))
64
    if (this->last_active_ + 10 < time(NULL))
60
    {
65
    {
61
        this->state_ = STATE_OFFLINE;
66
        this->state_ = STATE_OFFLINE;
62
        return false;
67
        return false;
63
    }
68
    }
64
   
69
   
65
    return true;
70
    return true;
66
}
71
}
67
 
72
 
68
void Node::ResetTimeout()
73
void Node::ResetTimeout()
69
{
74
{
70
    this->last_active_ = time(NULL);
75
    this->last_active_ = time(NULL);
71
}
76
}
72
   
77
   
73
}; // namespace can
78
}; // namespace can
74
}; // namespace atom
79
}; // namespace atom
75
 
80