server
Clone or download
Modified Files
--- 'a/src/main/java/com/StreamPi/Server/Action/NormalActionPlugins.java'
+++ b/src/main/java/com/StreamPi/Server/Action/NormalActionPlugins.java
@@ -1,16 +1,29 @@
+/*
+Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macropad
+Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+Written by : Debayan Sutradhar (rnayabed)
+*/
+
package com.StreamPi.Server.Action;
import com.StreamPi.ActionAPI.Action.Action;
import com.StreamPi.ActionAPI.Action.ActionType;
import com.StreamPi.ActionAPI.Action.ServerConnection;
import com.StreamPi.ActionAPI.Action.PropertySaver;
-import com.StreamPi.ActionAPI.ActionProperty.ClientProperties;
-import com.StreamPi.ActionAPI.ActionProperty.Property.ControlType;
import com.StreamPi.ActionAPI.ActionProperty.Property.Property;
import com.StreamPi.ActionAPI.ActionProperty.Property.Type;
import com.StreamPi.ActionAPI.ActionProperty.ServerProperties;
import com.StreamPi.ActionAPI.NormalAction.NormalAction;
-import com.StreamPi.Server.Controller.Controller;
import com.StreamPi.Util.Exception.MinorException;
import com.StreamPi.Util.Exception.SevereException;
import com.StreamPi.Util.Exception.StreamPiException;
@@ -26,9 +39,7 @@ import javax.xml.transform.TransformerFa
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
-import javafx.scene.image.ImageView;
import org.w3c.dom.NodeList;
-import org.kordamp.ikonli.javafx.FontIcon;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
@@ -45,9 +56,6 @@ import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.w3c.dom.Element;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.transform.Transformer;
public class NormalActionPlugins
{
@@ -60,6 +68,11 @@ public class NormalActionPlugins
private static String pluginsLocation = null;
+ /**
+ * Singleton class instance getter. Creates new one, when asked for the first time
+ *
+ * @return returns instance of NormalActionPlugins (one and only, always)
+ */
public static synchronized NormalActionPlugins getInstance()
{
if(instance == null)
@@ -70,29 +83,50 @@ public class NormalActionPlugins
return instance;
}
+ /**
+ * Sets the folder location where the plugin JARs and their dependencies are stored
+ *
+ * @param location Folder location
+ */
public static void setPluginsLocation(String location)
{
pluginsLocation = location;
}
-
+ /**
+ * Private constructor
+ */
private NormalActionPlugins()
{
logger = Logger.getLogger(NormalActionPlugins.class.getName());
normalPluginsHashmap = new HashMap<>();
}
+ /**
+ * init Method
+ */
public void init() throws SevereException, MinorException
{
registerPlugins();
initPlugins();
}
+ /**
+ * Used to fetch list of all external Plugins
+ *
+ * @return List of plugins
+ */
public List<NormalAction> getPlugins()
{
return normalPlugins;
}
+ /**
+ * Returns a plugin by its module name
+ *
+ * @param name Module Name
+ * @return The plugin. If not found, then null is returned
+ */
public NormalAction getPluginByModuleName(String name)
{
logger.info("Plugin being requested : "+name);
@@ -108,6 +142,9 @@ public class NormalActionPlugins
private List<NormalAction> normalPlugins = null;
HashMap<String, Integer> normalPluginsHashmap;
+ /**
+ * Used to register plugins from plugin location
+ */
public void registerPlugins() throws SevereException, MinorException
{
logger.info("Registering external plugins from "+pluginsLocation+" ...");
@@ -146,7 +183,7 @@ public class NormalActionPlugins
- String name="";
+ String name;
Version version;
try
{
@@ -249,8 +286,10 @@ public class NormalActionPlugins
sortedPlugins = new HashMap<>();
- for (NormalAction eachPlugin : normalPlugins) {
- try {
+ for (NormalAction eachPlugin : normalPlugins)
+ {
+ try
+ {
eachPlugin.setPropertySaver(propertySaver);
eachPlugin.setServerConnection(serverConnection);
eachPlugin.initProperties();
@@ -314,18 +353,9 @@ public class NormalActionPlugins
sortedPlugins.get(eachPlugin.getCategory()).add(eachPlugin);
- /*logger.debug("-----Custom Plugin Debug-----" +
- "\nAction Type : " + eachPlugin.getActionType() +
- "\nName : " + eachPlugin.getName() +
- "\nFull Module Name : " + eachPlugin.getModuleName() +
- "\nAuthor : " + eachPlugin.getAuthor() +
- "\nCategory : " + eachPlugin.getCategory() +
- "\nRepo : " + eachPlugin.getRepo() +
- "\nVersion : " + eachPlugin.getVersion().getText() +
- "\n---------------------------");*/
-
-
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
e.printStackTrace();
errorModules.add(eachPlugin);
errorModuleError.add(e.getMessage());
@@ -360,6 +390,9 @@ public class NormalActionPlugins
}
}
+ /**
+ * Used to init plugins
+ */
public void initPlugins() throws MinorException
{
StringBuilder errors = new StringBuilder("There were errors registering the following plugins. As a result, they have been omitted : ");
@@ -396,16 +429,29 @@ public class NormalActionPlugins
HashMap<String, ArrayList<NormalAction>> sortedPlugins;
+ /**
+ * Gets list of sorted plugins
+ *
+ * @return Hashmap with category key, and list of plugins of each category
+ */
public HashMap<String, ArrayList<NormalAction>> getSortedPlugins()
{
return sortedPlugins;
}
+ /**
+ * @return Gets actions element from the config.xml in plugins folder
+ */
private Element getActionsElement()
{
return (Element) document.getElementsByTagName("actions").item(0);
}
+ /**
+ * Saves ServerProperties of every plugin in config.xml in plugins folder
+ *
+ * @throws MinorException Thrown when failed to save settings
+ */
public void saveServerSettings() throws MinorException
{
XMLConfigHelper.removeChilds(getActionsElement());
@@ -450,6 +496,10 @@ public class NormalActionPlugins
private PropertySaver propertySaver = null;
+ /**
+ * Set PropertySaver class
+ * @param propertySaver instance of PropertySaver
+ */
public void setPropertySaver(PropertySaver propertySaver)
{
this.propertySaver = propertySaver;
@@ -457,17 +507,29 @@ public class NormalActionPlugins
private ServerConnection serverConnection = null;
+ /**
+ * Set setServerConnection class
+ * @param serverConnection instance of ServerConnection
+ */
public void setServerConnection(ServerConnection serverConnection)
{
this.serverConnection = serverConnection;
}
-
+ /**
+ * Get plugin from index from list
+ *
+ * @param index of plugin
+ * @return found plugin
+ */
public NormalAction getActionFromIndex(int index)
{
return normalPlugins.get(index);
}
+ /**
+ * Calls onShutDown method in every plugin
+ */
public void shutDownActions()
{
if(normalPlugins != null)
@@ -488,6 +550,10 @@ public class NormalActionPlugins
}
}
+ /**
+ * Saves all Server Properties of each Plugin in config.xml in Plugins folder
+ * @throws MinorException thrown when failed to save
+ */
public void save() throws MinorException
{
try
--- 'a/src/main/java/com/StreamPi/Server/Client/Client.java'
+++ b/src/main/java/com/StreamPi/Server/Client/Client.java
@@ -1,24 +1,34 @@
+/*
+Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macropad
+Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+Written by : Debayan Sutradhar (rnayabed)
+*/
+
package com.StreamPi.Server.Client;
-import com.StreamPi.Server.Connection.ClientConnection;
-import com.StreamPi.ThemeAPI.Theme;
-import com.StreamPi.Util.Exception.MinorException;
import com.StreamPi.Util.Platform.Platform;
import com.StreamPi.Util.Platform.ReleaseStatus;
import com.StreamPi.Util.Version.Version;
-import javafx.geometry.Dimension2D;
import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.LinkedList;
import java.util.List;
public class Client {
private String nickName;
private final SocketAddress remoteSocketAddress;
private final Platform platform;
- private ClientConnection connectionHandler;
private final Version version;
private final Version commStandardVersion;
private final Version themeAPIVersion;
@@ -33,8 +43,6 @@ public class Client {
private String defaultProfileID;
private String defaultThemeFullName;
- private int totalNoOfProfiles;
-
public Client(Version version, ReleaseStatus releaseStatus, Version commStandardVersion, Version themeAPIVersion, String nickName, Platform platform, SocketAddress remoteSocketAddress)
{
this.version = version;
@@ -60,16 +68,6 @@ public class Client {
return defaultThemeFullName;
}
- public void setTotalNoOfProfiles(int totalNoOfProfiles)
- {
- this.totalNoOfProfiles = totalNoOfProfiles;
- }
-
- public int getTotalNoOfProfiles()
- {
- return totalNoOfProfiles;
- }
-
public void setDefaultProfileID(String ID)
{
defaultProfileID = ID;
@@ -100,23 +98,8 @@ public class Client {
return defaultProfileID;
}
- public void setConnectionHandler(ClientConnection connectionHandler)
- {
- this.connectionHandler = connectionHandler;
- }
-
- public ClientConnection getConnectionHandler()
- {
- return connectionHandler;
- }
-
//Client Profiles
- /*public ArrayList<ClientProfile> getProfiles()
- {
- return profiles;
- }*/
-
public void setNickName(String nickName)
{
this.nickName = nickName;
@@ -130,7 +113,8 @@ public class Client {
return clientProfiles;
}
- public void removeProfileFromID(String ID) throws MinorException {
+ public void removeProfileFromID(String ID)
+ {
profiles.remove(ID);
}
--- 'a/src/main/java/com/StreamPi/Server/Client/ClientProfile.java'
+++ b/src/main/java/com/StreamPi/Server/Client/ClientProfile.java
@@ -1,17 +1,22 @@
+/*
+Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macropad
+Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+Written by : Debayan Sutradhar (rnayabed)
+*/
+
package com.StreamPi.Server.Client;
import com.StreamPi.ActionAPI.Action.Action;
-import com.StreamPi.ActionAPI.Action.ActionType;
-import com.StreamPi.ActionAPI.Action.DisplayTextAlignment;
-import com.StreamPi.ActionAPI.Action.Location;
-import com.StreamPi.ActionAPI.ActionProperty.ClientProperties;
-import com.StreamPi.ActionAPI.NormalAction.NormalAction;
-import com.StreamPi.Server.Action.NormalActionPlugins;
-import com.StreamPi.Server.Window.Dashboard.ActionGridPane.ActionBox;
-import com.StreamPi.Util.Exception.MinorException;
-import javafx.geometry.Dimension2D;
-
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import java.util.UUID;
--- 'a/src/main/java/com/StreamPi/Server/Connection/ClientConnection.java'
+++ b/src/main/java/com/StreamPi/Server/Connection/ClientConnection.java
@@ -497,7 +497,6 @@ public class ClientConnection extends Th
logger.info("Registering profiles ...");
int noOfProfiles = Integer.parseInt(sep[1]);
- getClient().setTotalNoOfProfiles(noOfProfiles);
for(int i = 2; i<(noOfProfiles + 2); i++)
{
--- 'a/src/main/java/com/StreamPi/Server/Main.java'
+++ b/src/main/java/com/StreamPi/Server/Main.java
@@ -1,10 +1,18 @@
/*
-Main.java
+Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macropad
+Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
-First class started when the app runs.
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
-Written by Debayan Sutradhar (@rnayabed)
- */
+Written by : Debayan Sutradhar (rnayabed)
+*/
package com.StreamPi.Server;
@@ -13,24 +21,19 @@ import com.StreamPi.Server.Controller.Co
import com.StreamPi.Server.Info.ServerInfo;
import javafx.application.Application;
-import javafx.application.HostServices;
import javafx.scene.Scene;
-import javafx.scene.image.Image;
import javafx.stage.Stage;
public class Main extends Application {
- public void start(Stage stage) {
- Controller d = new Controller(); //Starts new dash instance
- Scene s = new Scene(d); //Starts new scene instance from dash
- stage.setScene(s); //Init Scene
- d.setHostServices(getHostServices());
- d.init();
- }
+ /**
+ * First method to be called
+ * This method first parses all the available command line arguments passed.
+ * Then a new instance of Controller is created, and then initialised.
+ */
+ public void start(Stage stage) {
- public static void main(String[] args)
- {
- for(String eachArg : args)
+ for(String eachArg : getParameters().getRaw())
{
String[] r = eachArg.split("=");
if(r[0].equals("-DStreamPi.startupRunnerFileName"))
@@ -38,8 +41,22 @@ public class Main extends Application {
else if(r[0].equals("-DStreamPi.startupMode"))
ServerInfo.getInstance().setStartMinimised(r[1].equals("min"));
}
-
-
+
+
+ Controller d = new Controller();
+ Scene s = new Scene(d);
+ stage.setScene(s);
+ d.setHostServices(getHostServices());
+ d.init();
+ }
+
+ /**
+ * This is a fallback. Called in some JVMs.
+ * This method just sends the command line arguments to JavaFX Application
+ */
+ public static void main(String[] args)
+ {
+
launch(args);
}
}