...
 
......@@ -240,6 +240,7 @@ message TokenState {
required State state = 2;
required uint32 ownerClientID = 3;
required string ownerEndpoint = 4;
required string user = 5;
}
message ChatMessage {
......
......@@ -61,17 +61,20 @@ message RemoteControlRequest {
required uint32 clientID = 1;
required string clientType = 2;
required string user = 3;
}
message GetTokenRequest {
required uint32 clientID = 1;
required string clientType = 2;
required string user = 3;
}
message ReleaseTokenRequest {
required uint32 clientID = 1;
required string user = 2;
}
message EmptyRequest {
......
......@@ -185,6 +185,7 @@ void SessionManager::checkRequesterApplications() {
m_tokenState = TokenState::FREE;
m_tokenClientID = 0;
m_tokenOwner = "";
m_tokenUser = "";
// Notify the token state.
notifyTokenState();
......@@ -286,7 +287,7 @@ void SessionManager::loginRefused(cameo::application::Request * request, const s
LogHandler::getInstance()->write(SimpleLog(common::LOG_DEBUG, "User " + user + " refused from client " + hostname(applicationEndpoint) + " : " + reason));
}
void SessionManager::enableRemoteControl(cameo::application::Request * request, uint32 clientID, const std::string& clientType) {
void SessionManager::enableRemoteControl(cameo::application::Request * request, uint32 clientID, const std::string& clientType, const std::string& user) {
// Get the application.
RequesterApplication application = getRequesterApplication(request);
......@@ -305,17 +306,18 @@ void SessionManager::enableRemoteControl(cameo::application::Request * request,
m_tokenState = TokenState::OWNED;
m_tokenClientID = clientID;
m_tokenOwner = endpoint;
m_tokenUser = user;
// Notify the token state.
notifyTokenState();
updateTokenActivity();
LogHandler::getInstance()->write(SimpleLog(common::LOG_DEBUG, "Client " + hostname(endpoint) + " enables remote control and has the token"));
LogHandler::getInstance()->write(SimpleLog(common::LOG_DEBUG, "User " + user + " on client " + hostname(endpoint) + " enables remote control and has the token"));
}
}
}
void SessionManager::disableRemoteControl(cameo::application::Request * request, uint32 clientID, const std::string& clientType) {
void SessionManager::disableRemoteControl(cameo::application::Request * request, uint32 clientID, const std::string& clientType, const std::string& user) {
// Get the application.
RequesterApplication application = getRequesterApplication(request);
......@@ -334,17 +336,18 @@ void SessionManager::disableRemoteControl(cameo::application::Request * request,
m_tokenState = TokenState::OWNED;
m_tokenClientID = clientID;
m_tokenOwner = endpoint;
m_tokenUser = user;
// Notify the token state.
notifyTokenState();
updateTokenActivity();
LogHandler::getInstance()->write(SimpleLog(common::LOG_DEBUG, "Client " + hostname(endpoint) + " disables remote control and has the token"));
LogHandler::getInstance()->write(SimpleLog(common::LOG_DEBUG, "User " + user + " on client " + hostname(endpoint) + " disables remote control and has the token"));
}
}
}
void SessionManager::requestToken(cameo::application::Request * request, uint32 clientID, const std::string& clientType) {
void SessionManager::requestToken(cameo::application::Request * request, uint32 clientID, const std::string& clientType, const std::string& user) {
// Get the application.
RequesterApplication application = getRequesterApplication(request);
......@@ -362,12 +365,13 @@ void SessionManager::requestToken(cameo::application::Request * request, uint32
m_tokenState = TokenState::OWNED;
m_tokenClientID = clientID;
m_tokenOwner = endpoint;
m_tokenUser = user;
// Notify the token state.
notifyTokenState();
updateTokenActivity();
LogHandler::getInstance()->write(SimpleLog(common::LOG_DEBUG, "Client " + hostname(endpoint) + " has the token"));
LogHandler::getInstance()->write(SimpleLog(common::LOG_DEBUG, "User " + user + " on Client " + hostname(endpoint) + " has the token"));
}
else {
// It is not possible to request the token when remote control is disabled.
......@@ -382,18 +386,19 @@ void SessionManager::requestToken(cameo::application::Request * request, uint32
m_tokenState = TokenState::OWNED;
m_tokenClientID = clientID;
m_tokenOwner = endpoint;
m_tokenUser = user;
// Notify the token state.
notifyTokenState();
updateTokenActivity();
LogHandler::getInstance()->write(SimpleLog(common::LOG_DEBUG, "Client " + hostname(endpoint) + " has the token"));
LogHandler::getInstance()->write(SimpleLog(common::LOG_DEBUG, "User " + user + " on client " + hostname(endpoint) + " has the token"));
}
}
}
}
void SessionManager::releaseToken(cameo::application::Request * request, uint32 clientID) {
void SessionManager::releaseToken(cameo::application::Request * request, uint32 clientID, const std::string& user) {
// Get the application.
RequesterApplication application = getRequesterApplication(request);
......@@ -411,11 +416,12 @@ void SessionManager::releaseToken(cameo::application::Request * request, uint32
m_tokenState = TokenState::FREE;
m_tokenClientID = 0;
m_tokenOwner = "";
m_tokenUser = "";
// Notify the token state.
notifyTokenState();
LogHandler::getInstance()->write(SimpleLog(common::LOG_DEBUG, "Client " + hostname(endpoint) + " released the token"));
LogHandler::getInstance()->write(SimpleLog(common::LOG_DEBUG, "User " + user + " on client " + hostname(endpoint) + " released the token"));
}
}
}
......@@ -423,7 +429,7 @@ void SessionManager::releaseToken(cameo::application::Request * request, uint32
void SessionManager::notifyTokenState() {
// Notifies the data change publisher that will send an event.
m_stateAccessor->notifyTokenStateChanged(m_remoteControlState, m_tokenState, m_tokenClientID, m_tokenOwner);
m_stateAccessor->notifyTokenStateChanged(m_remoteControlState, m_tokenState, m_tokenClientID, m_tokenOwner, m_tokenUser);
}
void SessionManager::notifyTokenActivity() {
......
......@@ -96,22 +96,22 @@ public:
/**
* Enables the remote control depending on conditions.
*/
void enableRemoteControl(cameo::application::Request * request, uint32 clientID, const std::string& clientType);
void enableRemoteControl(cameo::application::Request * request, uint32 clientID, const std::string& clientType, const std::string& user);
/**
* Disables the remote control depending on conditions.
*/
void disableRemoteControl(cameo::application::Request * request, uint32 clientID, const std::string& clientType);
void disableRemoteControl(cameo::application::Request * request, uint32 clientID, const std::string& clientType, const std::string& user);
/**
* Requests the token.
*/
void requestToken(cameo::application::Request * request, uint32 clientID, const std::string& clientType);
void requestToken(cameo::application::Request * request, uint32 clientID, const std::string& clientType, const std::string& user);
/**
* Releases the token.
*/
void releaseToken(cameo::application::Request * request, uint32 clientID);
void releaseToken(cameo::application::Request * request, uint32 clientID, const std::string& user);
/**
* Requests a synchronization so that a token event is sent.
......@@ -154,6 +154,7 @@ private:
common::TokenState m_tokenState = common::TokenState::FREE;
uint32 m_tokenClientID;
std::string m_tokenOwner;
std::string m_tokenUser;
std::mutex m_mutex;
std::chrono::system_clock::time_point m_lastTokenActivityDate;
......
......@@ -133,7 +133,7 @@ void SessionResponder::processEnableRemoteControlRequest(cameo::application::Req
messageRequest.ParseFromString(message);
// Forwards to the session manager.
SessionManager::getInstance()->enableRemoteControl(request, messageRequest.clientid(), messageRequest.clienttype());
SessionManager::getInstance()->enableRemoteControl(request, messageRequest.clientid(), messageRequest.clienttype(), messageRequest.user());
responseMessage.set_value(true);
......@@ -149,7 +149,7 @@ void SessionResponder::processDisableRemoteControlRequest(cameo::application::Re
messageRequest.ParseFromString(message);
// Forwards to the session manager.
SessionManager::getInstance()->disableRemoteControl(request, messageRequest.clientid(), messageRequest.clienttype());
SessionManager::getInstance()->disableRemoteControl(request, messageRequest.clientid(), messageRequest.clienttype(), messageRequest.user());
responseMessage.set_value(true);
......@@ -165,7 +165,7 @@ void SessionResponder::processGetTokenRequest(cameo::application::Request * requ
messageRequest.ParseFromString(message);
// Forwards to the session manager.
SessionManager::getInstance()->requestToken(request, messageRequest.clientid(), messageRequest.clienttype());
SessionManager::getInstance()->requestToken(request, messageRequest.clientid(), messageRequest.clienttype(), messageRequest.user());
responseMessage.set_value(true);
......@@ -181,7 +181,7 @@ void SessionResponder::processReleaseTokenRequest(cameo::application::Request *
messageRequest.ParseFromString(message);
// Forwards to the session manager.
SessionManager::getInstance()->releaseToken(request, messageRequest.clientid());
SessionManager::getInstance()->releaseToken(request, messageRequest.clientid(), messageRequest.user());
responseMessage.set_value(true);
......
......@@ -45,8 +45,8 @@ void DirectStateAccessor::notifyUserVariableStateChanged(unsigned long databaseI
_proxy->notifyUserVariableStateChanged(databaseId, name, enabled);
}
void DirectStateAccessor::notifyTokenStateChanged(common::RemoteControlState remoteControlState, common::TokenState state, uint32 ownerClientID, const std::string& ownerEndpoint) {
_proxy->notifyTokenStateChanged(remoteControlState, state, ownerClientID, ownerEndpoint);
void DirectStateAccessor::notifyTokenStateChanged(common::RemoteControlState remoteControlState, common::TokenState state, uint32 ownerClientID, const std::string& ownerEndpoint, const std::string& user) {
_proxy->notifyTokenStateChanged(remoteControlState, state, ownerClientID, ownerEndpoint, user);
}
void DirectStateAccessor::notifyChatMessage(uint32 clientID, int64 date, const std::string& sender, const std::string& message) {
......
......@@ -68,7 +68,7 @@ public:
/**
* Notifies a token state change.
*/
virtual void notifyTokenStateChanged(common::RemoteControlState remoteControlState, common::TokenState state, uint32 ownerClientID, const std::string& ownerEndpoint);
virtual void notifyTokenStateChanged(common::RemoteControlState remoteControlState, common::TokenState state, uint32 ownerClientID, const std::string& ownerEndpoint, const std::string& user);
/**
* Notifies a chat message.
......
......@@ -64,7 +64,7 @@ public:
/**
* Notifies a token state change.
*/
virtual void notifyTokenStateChanged(common::RemoteControlState remoteControlState, common::TokenState state, uint32 ownerClientID, const std::string& ownerEndpoint) = 0;
virtual void notifyTokenStateChanged(common::RemoteControlState remoteControlState, common::TokenState state, uint32 ownerClientID, const std::string& ownerEndpoint, const std::string& user) = 0;
/**
* Notifies a chat message.
......
......@@ -21,12 +21,13 @@
namespace dataprovider {
TokenStateChangedMessage::TokenStateChangedMessage(common::RemoteControlState remoteControlState, common::TokenState state, uint32 ownerClientID, const std::string& ownerEndpoint) :
TokenStateChangedMessage::TokenStateChangedMessage(common::RemoteControlState remoteControlState, common::TokenState state, uint32 ownerClientID, const std::string& ownerEndpoint, const std::string& user) :
NotificationMessage(0),
m_remoteControlState(remoteControlState),
m_state(state),
m_ownerClientID(ownerClientID),
m_ownerEndpoint(ownerEndpoint) {
m_ownerEndpoint(ownerEndpoint),
m_user(user) {
}
TokenStateChangedMessage::~TokenStateChangedMessage() {
......@@ -48,8 +49,12 @@ uint32 TokenStateChangedMessage::getOwnerClientID() const {
return m_ownerClientID;
}
std::string TokenStateChangedMessage::getOwnerEndpoint() const {
const std::string& TokenStateChangedMessage::getOwnerEndpoint() const {
return m_ownerEndpoint;
}
const std::string& TokenStateChangedMessage::getUser() const {
return m_user;
}
}
......@@ -34,7 +34,7 @@ public:
/**
* Constructor.
*/
TokenStateChangedMessage(common::RemoteControlState remoteControlState, common::TokenState state, uint32 ownerClientID, const std::string& ownerEndpoint);
TokenStateChangedMessage(common::RemoteControlState remoteControlState, common::TokenState state, uint32 ownerClientID, const std::string& ownerEndpoint, const std::string& user);
/**
* Virtual destructor.
......@@ -64,13 +64,19 @@ public:
/**
* Gets the owner endpoint.
*/
std::string getOwnerEndpoint() const;
const std::string& getOwnerEndpoint() const;
/**
* Gets the user.
*/
const std::string& getUser() const;
private:
common::RemoteControlState m_remoteControlState;
common::TokenState m_state;
uint32 m_ownerClientID;
std::string m_ownerEndpoint;
std::string m_user;
};
......
......@@ -373,7 +373,7 @@ void DataChangePublisher::notifyUserVariableStateChanged(unsigned long databaseI
m_publisher->sendTwoBinaryParts(messageType.SerializeAsString(), message.SerializeAsString());
}
void DataChangePublisher::notifyTokenStateChanged(common::RemoteControlState remoteControlState, common::TokenState state, uint32 ownerClientID, const std::string& ownerEndpoint) {
void DataChangePublisher::notifyTokenStateChanged(common::RemoteControlState remoteControlState, common::TokenState state, uint32 ownerClientID, const std::string& ownerEndpoint, const std::string& user) {
// Create the type.
notification::Message messageType;
......@@ -401,6 +401,7 @@ void DataChangePublisher::notifyTokenStateChanged(common::RemoteControlState rem
message.set_ownerclientid(ownerClientID);
message.set_ownerendpoint(ownerEndpoint);
message.set_user(user);
// Publish the message
m_publisher->sendTwoBinaryParts(messageType.SerializeAsString(), message.SerializeAsString());
......
......@@ -103,7 +103,7 @@ public:
/**
* Notifies the token changed.
*/
void notifyTokenStateChanged(common::RemoteControlState remoteControlState, common::TokenState state, uint32 ownerClientID, const std::string& ownerEndpoint);
void notifyTokenStateChanged(common::RemoteControlState remoteControlState, common::TokenState state, uint32 ownerClientID, const std::string& ownerEndpoint, const std::string& user);
/**
* Notifies a chat message.
......
......@@ -180,8 +180,8 @@ void NotificationServer::newFile(const std::string& message) {
_queue->put(new NewFileMessage(message));
}
void NotificationServer::tokenStateChanged(common::RemoteControlState remoteControlState, common::TokenState state, uint32 ownerClientID, const std::string& ownerEndpoint) {
_queue->put(new TokenStateChangedMessage(remoteControlState, state, ownerClientID, ownerEndpoint));
void NotificationServer::tokenStateChanged(common::RemoteControlState remoteControlState, common::TokenState state, uint32 ownerClientID, const std::string& ownerEndpoint, const std::string& user) {
_queue->put(new TokenStateChangedMessage(remoteControlState, state, ownerClientID, ownerEndpoint, user));
}
void NotificationServer::chatMessage(uint32 clientID, int64 date, const std::string& sender, const std::string& message) {
......@@ -358,7 +358,7 @@ void NotificationServer::processMessage(LogDataImageReadyMessage* message) {
void NotificationServer::processMessage(TokenStateChangedMessage* message) {
_dataChangePublisher->notifyTokenStateChanged(message->getRemoteControlState(), message->getState(), message->getOwnerClientID(), message->getOwnerEndpoint());
_dataChangePublisher->notifyTokenStateChanged(message->getRemoteControlState(), message->getState(), message->getOwnerClientID(), message->getOwnerEndpoint(), message->getUser());
}
void NotificationServer::processMessage(ChatMessage* message) {
......
......@@ -191,7 +191,7 @@ public:
/**
* Notifies a token state change.
*/
void tokenStateChanged(common::RemoteControlState remoteControlState, common::TokenState state, uint32 ownerClientID, const std::string& ownerEndpoint);
void tokenStateChanged(common::RemoteControlState remoteControlState, common::TokenState state, uint32 ownerClientID, const std::string& ownerEndpoint, const std::string& user);
/**
* Notifies a chat message.
......
......@@ -46,8 +46,8 @@ void StateAccessorDirectImpl::notifyUserVariableStateChanged(unsigned long datab
NotificationServer::getInstance()->userVariableStateChanged(databaseId, name, enabled);
}
void StateAccessorDirectImpl::notifyTokenStateChanged(common::RemoteControlState remoteControlState, common::TokenState state, uint32 ownerClientID, const std::string& ownerEndpoint) {
NotificationServer::getInstance()->tokenStateChanged(remoteControlState, state, ownerClientID, ownerEndpoint);
void StateAccessorDirectImpl::notifyTokenStateChanged(common::RemoteControlState remoteControlState, common::TokenState state, uint32 ownerClientID, const std::string& ownerEndpoint, const std::string& user) {
NotificationServer::getInstance()->tokenStateChanged(remoteControlState, state, ownerClientID, ownerEndpoint, user);
}
void StateAccessorDirectImpl::notifyChatMessage(uint32 clientID, int64 date, const std::string& sender, const std::string& message) {
......
......@@ -61,7 +61,7 @@ public:
/**
* Notifies a token state change.
*/
void notifyTokenStateChanged(common::RemoteControlState remoteControlState, common::TokenState state, uint32 ownerClientID, const std::string& ownerEndpoint);
void notifyTokenStateChanged(common::RemoteControlState remoteControlState, common::TokenState state, uint32 ownerClientID, const std::string& ownerEndpoint, const std::string& user);
/**
* Notifies a chat message.
......