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 117... Line 117...
117
       
117
       
118
        net::Manager::Instance()->SendToAll(this->server_id_, common::Byteset(line));
118
        net::Manager::Instance()->SendToAll(this->server_id_, common::Byteset(line));
119
    }
119
    }
120
}
120
}
121
 
121
 
122
void Monitor::SlotOnNewDataHandler(net::SocketId client_id, net::SocketId server_id, common::Byteset data)
122
void Monitor::SlotOnNewDataHandler(net::SocketId id, common::Byteset data)
123
{
123
{
124
    if (server_id != this->server_id_)
124
    if (std::find(this->clients_.begin(), this->clients_.end(), id) == this->clients_.end())
125
    {
125
    {
126
        return;
126
      return;
127
    }
127
    }
128
   
128
 
129
    std::string str = data.ToCharString();
129
    std::string str = data.ToCharString();
130
   
130
   
131
    boost::algorithm::trim_right_if(str, boost::is_any_of("\r\n"));
131
    boost::algorithm::trim_right_if(str, boost::is_any_of("\r\n"));
132
   
132
   
133
    LOG.Debug("Received: \"" + str + "\" from client " + boost::lexical_cast<std::string>(client_id) + " on server " + boost::lexical_cast<std::string>(server_id));
133
    LOG.Debug("Received: \"" + str + "\" from client " + boost::lexical_cast<std::string>(id) + " on server " + boost::lexical_cast<std::string>(this->server_id_));
134
   
134
   
135
    if (str == "q" || str == "quit")
135
    if (str == "q" || str == "quit")
136
    {
136
    {
137
        LOG.Info("Client " + boost::lexical_cast<std::string>(client_id) + " has requested to be disconnected.");
137
        LOG.Info("Client " + boost::lexical_cast<std::string>(id) + " has requested to be disconnected.");
138
        net::Manager::Instance()->Disconnect(client_id);
138
        net::Manager::Instance()->Disconnect(id);
139
    }
139
    }
140
}
140
}
141
 
141
 
142
void Monitor::SlotOnNewStateHandler(net::SocketId client_id, net::SocketId server_id, net::ClientState client_state)
142
void Monitor::SlotOnNewClientHandler(net::SocketId id, net::SocketId server_id)
143
{
143
{
144
    if (server_id != this->server_id_)
144
  if (server_id == this->server_id_)
-
 
145
  {
-
 
146
    this->clients_.insert(id);
-
 
147
  }
-
 
148
}
-
 
149
 
-
 
150
void Monitor::SlotOnNewStateHandler(net::SocketId id, net::ClientState client_state)
-
 
151
{
-
 
152
    if (std::find(this->clients_.begin(), this->clients_.end(), id) == this->clients_.end())
145
    {
153
    {
146
        return;
154
      return;
147
    }
155
    }
148
   
156
 
149
    if (client_state == net::CLIENT_STATE_DISCONNECTED)
157
    if (client_state == net::CLIENT_STATE_DISCONNECTED)
150
    {
158
    {
151
        LOG.Info("Client " + boost::lexical_cast<std::string>(client_id) + " has disconnected.");
159
        LOG.Info("Client " + boost::lexical_cast<std::string>(id) + " has disconnected.");
-
 
160
        this->clients_.erase(id);
152
    }
161
    }
153
    else if (client_state == net::CLIENT_STATE_CONNECTED)
162
    else if (client_state == net::CLIENT_STATE_CONNECTED)
154
    {
163
    {
155
        LOG.Info("Client " + boost::lexical_cast<std::string>(client_id) + " has connected.");
164
        LOG.Info("Client " + boost::lexical_cast<std::string>(id) + " has connected.");
156
        net::Manager::Instance()->SendTo(client_id, common::Byteset("Welcome to Atom CAN monitoring\n"));
165
        net::Manager::Instance()->SendTo(id, common::Byteset("Welcome to Atom CAN monitoring\n"));
157
    }
166
    }
158
    else
167
    else
159
    {
168
    {
160
        LOG.Debug("Got state: " + boost::lexical_cast<std::string>((int)client_state));
169
        LOG.Debug("Got state: " + boost::lexical_cast<std::string>((int)client_state));
161
    }
170
    }