-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from iuginP/develop
Sprint 5 - closed
- Loading branch information
Showing
104 changed files
with
3,649 additions
and
2,204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
client/src/main/scala/it/cwmp/client/controller/ActorAlertManagement.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package it.cwmp.client.controller | ||
|
||
import akka.actor.Actor.Receive | ||
import it.cwmp.client.controller.AlertMessages._ | ||
import it.cwmp.client.view.FXAlertsController | ||
|
||
/** | ||
* A trait that gives autonomous management of alert messages; | ||
* | ||
* To use it you need to add "alertBehaviour" to your Actor receive | ||
* | ||
* @author Eugenio Pierfederici | ||
* @author contributor Enrico Siboni | ||
*/ | ||
trait ActorAlertManagement { | ||
|
||
/** | ||
* @return the alerts controller | ||
*/ | ||
protected def fxController: FXAlertsController | ||
|
||
/** | ||
* @return the behaviour that manages alert messages | ||
*/ | ||
protected def alertBehaviour: Receive = { | ||
case Info(title, message) => onInfoAlertReceived(title, message) | ||
case Error(title, message) => onErrorAlertReceived(title, message) | ||
} | ||
|
||
/** | ||
* Called when a info alert is received | ||
* | ||
* @param title the title of the info | ||
* @param message the message of the info | ||
*/ | ||
protected def onInfoAlertReceived(title: String, message: String): Unit = | ||
fxController showInfo(title, message) | ||
|
||
/** | ||
* Called when an error alert is received | ||
* | ||
* @param title the title of the error | ||
* @param message the message of the error | ||
*/ | ||
protected def onErrorAlertReceived(title: String, message: String): Unit = | ||
fxController showError(title, message) | ||
} | ||
|
||
/** | ||
* A collection of AlertMessages | ||
*/ | ||
object AlertMessages { | ||
|
||
/** | ||
* Tells to show info message | ||
* | ||
* @param title the title | ||
* @param message the message | ||
*/ | ||
case class Info(title: String, message: String) | ||
|
||
/** | ||
* Tells to show an error message | ||
* | ||
* @param title the title | ||
* @param message the message | ||
*/ | ||
case class Error(title: String, message: String) | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
client/src/main/scala/it/cwmp/client/controller/ActorViewVisibilityManagement.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package it.cwmp.client.controller | ||
|
||
import akka.actor.Actor.Receive | ||
import it.cwmp.client.controller.ViewVisibilityMessages.{Hide, Show} | ||
import it.cwmp.client.view.{FXRunOnUIThread, FXViewController} | ||
|
||
/** | ||
* A trait that give autonomous management to view visibility | ||
* | ||
* To use it you need to add "visibilityBehaviour" to your Actor receive | ||
* | ||
* @author Enrico Siboni | ||
*/ | ||
trait ActorViewVisibilityManagement extends FXRunOnUIThread { | ||
|
||
/** | ||
* @return the visibility controller | ||
*/ | ||
protected def fxController: FXViewController | ||
|
||
/** | ||
* @return the behaviour that manages alert messages | ||
*/ | ||
protected def visibilityBehaviour: Receive = { | ||
case Show => onShowGUI() | ||
case Hide => onHideGUI() | ||
} | ||
|
||
/** | ||
* Called when GUI is shown | ||
*/ | ||
protected def onShowGUI(): Unit = runOnUIThread(() => fxController showGUI()) | ||
|
||
/** | ||
* Called when GUI is hidden | ||
*/ | ||
protected def onHideGUI(): Unit = runOnUIThread(() => fxController hideGUI()) | ||
} | ||
|
||
|
||
/** | ||
* A collection of view visibility messages | ||
*/ | ||
object ViewVisibilityMessages { | ||
|
||
/** | ||
* Shows the underlying graphical interface | ||
*/ | ||
case object Show | ||
|
||
/** | ||
* Hides the underlying graphical interface | ||
*/ | ||
case object Hide | ||
|
||
} |
87 changes: 87 additions & 0 deletions
87
client/src/main/scala/it/cwmp/client/controller/ApiClientActor.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package it.cwmp.client.controller | ||
|
||
import akka.actor.Actor | ||
import it.cwmp.client.controller.messages.AuthenticationRequests.{LogIn, SignUp} | ||
import it.cwmp.client.controller.messages.AuthenticationResponses.{LogInFailure, LogInSuccess, SignUpFailure, SignUpSuccess} | ||
import it.cwmp.client.controller.messages.RoomsRequests.{ServiceCreate, ServiceEnterPrivate, ServiceEnterPublic} | ||
import it.cwmp.client.controller.messages.RoomsResponses._ | ||
import it.cwmp.services.wrapper.{AuthenticationApiWrapper, RoomsApiWrapper} | ||
import it.cwmp.utils.Utils.stringToOption | ||
|
||
import scala.concurrent.ExecutionContext.Implicits.global | ||
import scala.language.implicitConversions | ||
import scala.util.{Failure, Success, Try} | ||
|
||
/** | ||
* A class that implements the actor that will manage communications with services APIs | ||
*/ | ||
case class ApiClientActor() extends Actor { | ||
|
||
override def receive: Receive = authenticationBehaviour orElse roomsBehaviour | ||
|
||
/** | ||
* @return the behaviour of authenticating user online | ||
*/ | ||
private def authenticationBehaviour: Receive = { | ||
val authenticationApiWrapper = AuthenticationApiWrapper() | ||
//noinspection ScalaStyle | ||
import authenticationApiWrapper._ | ||
{ | ||
case LogIn(username, password) => | ||
val senderTmp = sender | ||
login(username, password).onComplete(replyWith( | ||
token => senderTmp ! LogInSuccess(token), | ||
exception => senderTmp ! LogInFailure(exception.getMessage) | ||
)) | ||
case SignUp(username, password) => | ||
val senderTmp = sender | ||
signUp(username, password).onComplete(replyWith( | ||
token => senderTmp ! SignUpSuccess(token), | ||
exception => senderTmp ! SignUpFailure(exception.getMessage) | ||
)) | ||
} | ||
} | ||
|
||
/** | ||
* @return the behaviour of managing the rooms online | ||
*/ | ||
private def roomsBehaviour: Receive = { | ||
val roomApiWrapper = RoomsApiWrapper() | ||
//noinspection ScalaStyle | ||
import roomApiWrapper._ | ||
{ | ||
case ServiceCreate(roomName, playersNumber, token) => | ||
val senderTmp = sender | ||
createRoom(roomName, playersNumber)(token).onComplete(replyWith( | ||
token => senderTmp ! CreateSuccess(token), | ||
exception => senderTmp ! CreateFailure(exception.getMessage) | ||
)) | ||
case ServiceEnterPrivate(idRoom, address, webAddress, token) => | ||
val senderTmp = sender | ||
enterRoom(idRoom, address, webAddress)(token).onComplete(replyWith( | ||
_ => senderTmp ! EnterPrivateSuccess, | ||
exception => senderTmp ! EnterPrivateFailure(exception.getMessage) | ||
)) | ||
case ServiceEnterPublic(nPlayer, address, webAddress, token) => | ||
val senderTmp = sender | ||
enterPublicRoom(nPlayer, address, webAddress)(token).onComplete(replyWith( | ||
_ => senderTmp ! EnterPublicSuccess, | ||
exception => senderTmp ! EnterPublicFailure(exception.getMessage) | ||
)) | ||
} | ||
} | ||
|
||
/** | ||
* A utility method to match Success or failure of a try and do something with results | ||
* | ||
* @param onSuccess the action to do on success | ||
* @param onFailure the action to do on failure | ||
* @param toCheck the try to check | ||
* @tparam T the type of the result if present | ||
*/ | ||
private def replyWith[T](onSuccess: => T => Unit, onFailure: => Throwable => Unit) | ||
(toCheck: Try[T]): Unit = toCheck match { | ||
case Success(value) => onSuccess(value) | ||
case Failure(ex) => onFailure(ex) | ||
} | ||
} |
Oops, something went wrong.