Subversion Repositories HomeAutomation

Rev

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

Rev 1598 Rev 1601
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
 
-
 
23
#include <boost/date_time/posix_time/posix_time.hpp>
22
 
24
 
23
#include "Message.h"
25
#include "Message.h"
24
#include "broker/Manager.h"
26
#include "broker/Manager.h"
25
 
27
 
26
namespace atom {
28
namespace atom {
27
namespace can {
29
namespace can {
28
   
30
   
29
Node::Node(Node::Id id)
31
Node::Node(Node::Id id)
30
{
32
{
31
    this->state_ = STATE_OFFLINE;
33
    this->state_ = STATE_OFFLINE;
32
    this->id_ = id;
34
    this->id_ = id;
33
}
35
}
34
 
36
 
35
Node::~Node()
37
Node::~Node()
36
{
38
{
37
 
39
 
38
}
40
}
39
 
41
 
40
Node::Id Node::GetId()
42
Node::Id Node::GetId()
41
{
43
{
42
    return this->id_;
44
    return this->id_;
43
}
45
}
44
 
46
 
45
Node::State Node::GetState()
47
Node::State Node::GetState()
46
{
48
{
47
    return this->state_;
49
    return this->state_;
48
}
50
}
49
 
51
 
50
void Node::SetState(Node::State state)
52
void Node::SetState(Node::State state)
-
 
53
{
-
 
54
    this->state_ = state;
-
 
55
}
-
 
56
 
-
 
57
bool Node::CheckTimeout()
-
 
58
{
-
 
59
    if (this->last_active_ + 10 < time(NULL))
-
 
60
    {
-
 
61
        this->state_ = STATE_OFFLINE;
-
 
62
        return false;
-
 
63
    }
-
 
64
   
-
 
65
    return true;
-
 
66
}
-
 
67
 
-
 
68
void Node::ResetTimeout()
51
{
69
{
52
    this->state_ = state;
70
    this->last_active_ = time(NULL);
53
}
71
}
54
   
72
   
55
}; // namespace can
73
}; // namespace can
56
}; // namespace atom
74
}; // namespace atom
57
 
75