// Path: localnet/src/main/java/dev/jokr/localnet/models/ConnectedClients.java
// public class ConnectedClients {
// 
//     private HashMap<Long, RegisterMessage> registeredClients;
// 
//     public ConnectedClients(HashMap<Long, RegisterMessage> registeredClients) {
//         this.registeredClients = registeredClients;
//     }
// 
//     public Payload<?> getPayload(int clientId) {
//         if (registeredClients.containsKey(clientId))
//             return registeredClients.get(clientId).getPayload();
//         else
//             return null;
//     }
// 
//     public Set<Long> getAllClientsIds() {
//         return registeredClients.keySet();
//     }
// 
//     public int getClientsSize() {
//         return registeredClients.size();
//     }
// 
// }
// 
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
// 
//     private T payload;
// 
//     public Payload(T payload) {
//         this.payload = payload;
//     }
// 
//     public T getPayload() {
//         return payload;
//     }
// 
// 
// }
// 
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
// 
//     public static final int NONE = 0;
//     public static final int START = 1;
//     public static final int END = 2;
// 
//     private Payload<?> payload;
//     private int signal;
// 
// 
//     public SessionMessage(Payload<?> payload) {
//         this.payload = payload;
//         this.signal = NONE;
//     }
// 
//     public SessionMessage(Payload<?> payload, int signal) {
//         this.payload = payload;
//         this.signal = signal;
//     }
// 
//     public int getSignal() {
//         return signal;
//     }
// 
//     public Payload<?> getPayload() {
//         return payload;
//     }
// }


import android.os.Bundle;
import java.util.HashMap;
import dev.jokr.localnet.models.ConnectedClients;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.SessionMessage;
package dev.jokr.localnet;




/**
 * Created by JoKr on 8/30/2016.
 */
public abstract class LocalSession {

    /*
     *  Class that represent session of messaging between devices.
     *  All session events (like sending or receiving a message) and logic connected to them
     *  should be implemented here, not in Activity class or others.
     *
     *
     *  Code here will be executed in service.
     *
     */

    // Communicator for interacting with running service
    private Communicator communicator;

    public LocalSession() {}

    /*
     * This method sends session message to specified recipient. Recipient will
     * receive message in their LocalClient instance.
     */
    public void sendMessage(long recipientId, Payload<?> payload) {
        communicator.sendMessage(recipientId, payload);
    }

    /*
     * This method is used to send message to all clients connected.
     */
    public void sendBroadcastMessage(Payload<?> payload) {
        communicator.sendBroadcastMessage(payload);
    }

    /*
     * Logic in this class is executed in service. If you want show some data on the UI, you can use
     * this method to send data to your Activity/Fragment or other classes.
     */
    public void sendUiEvent(Payload<?> payload) {
        communicator.sendUiEvent(payload);
    }

    /*
     * This method is used for setting communicator with running service. Called before onCreate.
     */
    public void preCreateInit(Communicator communicator) {
        this.communicator = communicator;
    }

    /*
     * This is where you should start your session logic. You receive bundle (if you set any from
     * Local Server) and connected clients.
     */
// Path: localnet/src/main/java/dev/jokr/localnet/models/ConnectedClients.java
// public class ConnectedClients {
// 
//     private HashMap<Long, RegisterMessage> registeredClients;
// 
//     public ConnectedClients(HashMap<Long, RegisterMessage> registeredClients) {
//         this.registeredClients = registeredClients;
//     }
// 
//     public Payload<?> getPayload(int clientId) {
//         if (registeredClients.containsKey(clientId))
//             return registeredClients.get(clientId).getPayload();
//         else
//             return null;
//     }
// 
//     public Set<Long> getAllClientsIds() {
//         return registeredClients.keySet();
//     }
// 
//     public int getClientsSize() {
//         return registeredClients.size();
//     }
// 
// }
// 
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
// 
//     private T payload;
// 
//     public Payload(T payload) {
//         this.payload = payload;
//     }
// 
//     public T getPayload() {
//         return payload;
//     }
// 
// 
// }
// 
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
// 
//     public static final int NONE = 0;
//     public static final int START = 1;
//     public static final int END = 2;
// 
//     private Payload<?> payload;
//     private int signal;
// 
// 
//     public SessionMessage(Payload<?> payload) {
//         this.payload = payload;
//         this.signal = NONE;
//     }
// 
//     public SessionMessage(Payload<?> payload, int signal) {
//         this.payload = payload;
//         this.signal = signal;
//     }
// 
//     public int getSignal() {
//         return signal;
//     }
// 
//     public Payload<?> getPayload() {
//         return payload;
//     }
// }


// Path: localnet/src/main/java/dev/jokr/localnet/LocalSession.java
import android.os.Bundle;
import java.util.HashMap;
import dev.jokr.localnet.models.ConnectedClients;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.SessionMessage;

package dev.jokr.localnet;




/**
 * Created by JoKr on 8/30/2016.
 */
public abstract class LocalSession {

    /*
     *  Class that represent session of messaging between devices.
     *  All session events (like sending or receiving a message) and logic connected to them
     *  should be implemented here, not in Activity class or others.
     *
     *
     *  Code here will be executed in service.
     *
     */

    // Communicator for interacting with running service
    private Communicator communicator;

    public LocalSession() {}

    /*
     * This method sends session message to specified recipient. Recipient will
     * receive message in their LocalClient instance.
     */
    public void sendMessage(long recipientId, Payload<?> payload) {
        communicator.sendMessage(recipientId, payload);
    }

    /*
     * This method is used to send message to all clients connected.
     */
    public void sendBroadcastMessage(Payload<?> payload) {
        communicator.sendBroadcastMessage(payload);
    }

    /*
     * Logic in this class is executed in service. If you want show some data on the UI, you can use
     * this method to send data to your Activity/Fragment or other classes.
     */
    public void sendUiEvent(Payload<?> payload) {
        communicator.sendUiEvent(payload);
    }

    /*
     * This method is used for setting communicator with running service. Called before onCreate.
     */
    public void preCreateInit(Communicator communicator) {
        this.communicator = communicator;
    }

    /*
     * This is where you should start your session logic. You receive bundle (if you set any from
     * Local Server) and connected clients.
     */
    public abstract void onCreate(Bundle bundle, ConnectedClients connectedClients);