Subversion Repositories HomeAutomation

Rev

Rev 1959 | Rev 1987 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1959 Rev 1986
Line 63... Line 63...
63
   
63
   
64
        net::Manager::Instance()->SendToAll(this->server_id_, common::Byteset(line, true));
64
        net::Manager::Instance()->SendToAll(this->server_id_, common::Byteset(line, true));
65
    }
65
    }
66
}
66
}
67
 
67
 
68
void CanDaemon::SlotOnNewDataHandler(net::SocketId client_id, net::SocketId server_id, common::Byteset data)
68
void CanDaemon::SlotOnNewDataHandler(net::SocketId id, common::Byteset data)
69
{
69
{
70
    if (server_id != this->server_id_)
70
    if (std::find(this->clients_.begin(), this->clients_.end(), id) == this->clients_.end())
71
    {
71
    {
72
        return;
72
      return;
73
    }
73
    }
74
   
74
   
75
    std::string str = data.ToCharString();
75
    std::string str = data.ToCharString();
76
   
76
   
77
    boost::algorithm::trim_right_if(str, boost::is_any_of("\r\n"));
77
    boost::algorithm::trim_right_if(str, boost::is_any_of("\r\n"));
78
   
78
   
79
    //LOG.Info("Received: \"" + str + "\" from client " + boost::lexical_cast<std::string>(client_id) + " on server " + boost::lexical_cast<std::string>(server_id));
79
    LOG.Info("Received: \"" + str + "\" from client " + boost::lexical_cast<std::string>(id) + " on server " + boost::lexical_cast<std::string>(this->server_id_));
80
   
80
   
81
    std::string* payload_str = new std::string(str);
81
    std::string* payload_str = new std::string(str);
82
    broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_RAW_MESSAGE, broker::Message::PayloadPointer(payload_str), this)));
82
    broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_RAW_MESSAGE, broker::Message::PayloadPointer(payload_str), this)));
83
   
83
   
84
    //LOG.Info("Sent...");
84
    //LOG.Info("Sent...");
85
   
85
   
86
    if (str == "q" || str == "quit")
86
    if (str == "q" || str == "quit")
87
    {
87
    {
88
        LOG.Info("Client " + boost::lexical_cast<std::string>(client_id) + " has requested to be disconnected.");
88
        LOG.Info("Client " + boost::lexical_cast<std::string>(id) + " has requested to be disconnected.");
89
        net::Manager::Instance()->Disconnect(client_id);
89
        net::Manager::Instance()->Disconnect(id);
90
    }
90
    }
91
}
91
}
92
 
92
 
93
void CanDaemon::SlotOnNewStateHandler(net::SocketId client_id, net::SocketId server_id, net::ClientState client_state)
93
void CanDaemon::SlotOnNewClientHandler(net::SocketId id, net::SocketId server_id)
94
{
94
{
95
    if (server_id != this->server_id_)
95
  if (server_id == this->server_id_)
-
 
96
  {
-
 
97
    this->clients_.insert(id);
-
 
98
  }
-
 
99
}
-
 
100
 
-
 
101
void CanDaemon::SlotOnNewStateHandler(net::SocketId id, net::ClientState client_state)
-
 
102
{
-
 
103
    if (std::find(this->clients_.begin(), this->clients_.end(), id) == this->clients_.end())
96
    {
104
    {
97
        return;
105
      return;
98
    }
106
    }
99
   
107
 
100
    if (client_state == net::CLIENT_STATE_DISCONNECTED)
108
    if (client_state == net::CLIENT_STATE_DISCONNECTED)
101
    {
109
    {
102
        LOG.Info("Client " + boost::lexical_cast<std::string>(client_id) + " has disconnected.");
110
        LOG.Info("Client " + boost::lexical_cast<std::string>(id) + " has disconnected.");
-
 
111
        this->clients_.erase(id);
103
    }
112
    }
104
    else if (client_state == net::CLIENT_STATE_CONNECTED)
113
    else if (client_state == net::CLIENT_STATE_CONNECTED)
105
    {
114
    {
106
        LOG.Info("Client " + boost::lexical_cast<std::string>(client_id) + " has connected.");
115
        LOG.Info("Client " + boost::lexical_cast<std::string>(id) + " has connected.");
107
    }
116
    }
108
    else
117
    else
109
    {
118
    {
110
        LOG.Debug("Got state: " + boost::lexical_cast<std::string>((int)client_state));
119
        LOG.Debug("Got state: " + boost::lexical_cast<std::string>((int)client_state));
111
    }
120
    }