// Path: IPC/src/main/java/co/flyver/IPC/JSONUtils.java
// public class JSONUtils {
//     private static Gson mGson = new Gson();
//     private static final String TAG = "JSONIPC";
// 
//     /**
//      * Validates if a string is a valid JSON object
//      *
//      * @param json - String to be validated
//      * @return - boolean, true if the string is a valid JSON object
//      */
//     public static boolean validateJson(String json) {
//         try {
//             mGson.fromJson(json, Object.class);
//             return true;
//         } catch (JsonSyntaxException e) {
//             return false;
//         }
//     }
// 
// 
//     private static <T> T fromJSON(String json, Type type) {
//         if (validateJson(json)) {
//             return mGson.fromJson(json, type);
//         } else {
//             return null;
//         }
//     }
// 
//     /**
//      * Creates a generic type object from JSON
//      * @param json - String describing the JSON object
//      * @param type - Type derived from TypeToken, created with Google GSON
//      * @param <T> - Generic object
//      * @return
//      */
//     public static <T> T deserialize(String json, Type type) {
//         T jsonObj;
//         jsonObj = co.flyver.IPC.JSONUtils.fromJSON(json, type);
//         if (jsonObj == null) {
//             throw new NullPointerException("JSON is null");
//         }
//         return jsonObj;
//     }
// 
//     /**
//      * Creates a JSON from a generic object
//      * @param t - Object to be serialzied into JSON
//      * @param type - Type derived from TypeToken, created with Google GSON
//      * @param <T> - Generic object
//      * @return
//      */
//     public static <T> String serialize(T t, Type type) {
//         return mGson.toJson(t, type);
//     }
// 
//     public static <T> String serialize(T t) {
//         return mGson.toJson(t);
//     }
// 
// }


import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import co.flyver.IPC.JSONUtils;
    private static boolean mConnected = false;
    private IBinder mBinder = new LocalBinder();

    public Client() {
        super("Client");
    }

    public static void setServerIP(String sServerIP) {
        Client.sServerIP = sServerIP;
    }

    public static void setLastToast(Toast sLastToast) {
        Client.sLastToast = sLastToast;
    }

    public static void setMainContext(Context sMainContext) {
        Client.sMainContext = sMainContext;
    }

    public static void registerCallback(String key, ClientCallback callback) {
        if (callback != null) {
            sCallbacks.put(key, callback);
        }
    }

    public static void registerConnectionHooks(ConnectionHooks hooks) {
        sConnectionHooks = hooks;
    }

    public static void sendMsg(String json) {
// Path: IPC/src/main/java/co/flyver/IPC/JSONUtils.java
// public class JSONUtils {
//     private static Gson mGson = new Gson();
//     private static final String TAG = "JSONIPC";
// 
//     /**
//      * Validates if a string is a valid JSON object
//      *
//      * @param json - String to be validated
//      * @return - boolean, true if the string is a valid JSON object
//      */
//     public static boolean validateJson(String json) {
//         try {
//             mGson.fromJson(json, Object.class);
//             return true;
//         } catch (JsonSyntaxException e) {
//             return false;
//         }
//     }
// 
// 
//     private static <T> T fromJSON(String json, Type type) {
//         if (validateJson(json)) {
//             return mGson.fromJson(json, type);
//         } else {
//             return null;
//         }
//     }
// 
//     /**
//      * Creates a generic type object from JSON
//      * @param json - String describing the JSON object
//      * @param type - Type derived from TypeToken, created with Google GSON
//      * @param <T> - Generic object
//      * @return
//      */
//     public static <T> T deserialize(String json, Type type) {
//         T jsonObj;
//         jsonObj = co.flyver.IPC.JSONUtils.fromJSON(json, type);
//         if (jsonObj == null) {
//             throw new NullPointerException("JSON is null");
//         }
//         return jsonObj;
//     }
// 
//     /**
//      * Creates a JSON from a generic object
//      * @param t - Object to be serialzied into JSON
//      * @param type - Type derived from TypeToken, created with Google GSON
//      * @param <T> - Generic object
//      * @return
//      */
//     public static <T> String serialize(T t, Type type) {
//         return mGson.toJson(t, type);
//     }
// 
//     public static <T> String serialize(T t) {
//         return mGson.toJson(t);
//     }
// 
// }


// Path: Client/src/main/java/co/flyver/Client/Client.java
import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import co.flyver.IPC.JSONUtils;

    private static boolean mConnected = false;
    private IBinder mBinder = new LocalBinder();

    public Client() {
        super("Client");
    }

    public static void setServerIP(String sServerIP) {
        Client.sServerIP = sServerIP;
    }

    public static void setLastToast(Toast sLastToast) {
        Client.sLastToast = sLastToast;
    }

    public static void setMainContext(Context sMainContext) {
        Client.sMainContext = sMainContext;
    }

    public static void registerCallback(String key, ClientCallback callback) {
        if (callback != null) {
            sCallbacks.put(key, callback);
        }
    }

    public static void registerConnectionHooks(ConnectionHooks hooks) {
        sConnectionHooks = hooks;
    }

    public static void sendMsg(String json) {
        if(!JSONUtils.validateJson(json)) {