Skip to content
This repository has been archived by the owner on Jul 11, 2021. It is now read-only.

Commit

Permalink
onload timeout is now configurable at the command line
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainhalle committed Jul 1, 2020
1 parent 4665487 commit 1c14c85
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void reset()

protected static InputStream getGrammarStream()
{
if (Main.s_platform == Main.PlatformType.android_native)
if (Main.s_platform == Main.PlatformType.ANDROID_NATIVE)
{
return CornipickleParser.class.getResourceAsStream("cornipickle-android.bnf");
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Server/src/ca/uqac/lif/cornipickle/CssSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protected static List<JsonElement> fetch(List<String> css_expression, JsonMap ro
String el_tag_name = "";
String el_class_name = "";
String el_id_name = "";
if (Main.s_platform == Main.PlatformType.android_native)
if (Main.s_platform == Main.PlatformType.ANDROID_NATIVE)
{

el_tag_name = JsonPath.getString(root, "element");// tagname // // element
Expand Down
23 changes: 23 additions & 0 deletions Source/Server/src/ca/uqac/lif/cornipickle/Interpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public class Interpreter implements Originator<Interpreter,String>

protected final transient CornipickleDeflateSerializer m_serializer;

/**
* The timeout (in ms) to give the time for the page to load
*/
protected int m_timeout = 500;

/**
* A global logger instance to trap exceptions throughout the program
*/
Expand Down Expand Up @@ -80,6 +85,24 @@ public static void main(String[] args) throws IOException, JsonParseException, P
Map<StatementMetadata,Verdict> verdicts = interpreter.getVerdicts();
System.out.println(verdicts);
}

/**
* Sets the timeout (in ms) to give the time for the page to load
* @param timeout The timeout
*/
public void setTimeout(int timeout)
{
m_timeout = timeout;
}

/**
* Gets the timeout (in ms) to give the time for the page to load
* @return The timeout
*/
public int getTimeout()
{
return m_timeout;
}

public void resetHistory()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ public CornipickleServer(String server_name, int port)
registerCallback(new FileCallback(this));
}

/**
* Sets the timeout (in ms) to give the time for the page to load
* @param timeout The timeout
*/
public void setTimeout(int timeout)
{
m_interpreter.setTimeout(timeout);
}

/**
* Sets whether to persist the state of the interpreter between calls
* @param b Set to {@code true} to persist state, {@code false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ protected String generateProbeCode()
probe_code = s_probeCode;
probe_code = probe_code.replace("%%WITNESS_CODE%%", escapeString(s_witnessCode));
probe_code = probe_code.replace("%%SERVER_NAME%%", m_serverName + ":" + m_serverPort);
probe_code = probe_code.replace("%%TIMEOUT%%", m_interpreter.getTimeout() + "");
// Add attributes to include
Set<String> attributes = m_interpreter.getAttributes();
StringBuilder attribute_string = new StringBuilder();
Expand Down
18 changes: 13 additions & 5 deletions Source/Server/src/ca/uqac/lif/cornipickle/server/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public class Main
*/
protected static int s_verbosity = 1;

public enum PlatformType { web, android_native };
public enum PlatformType { WEB, ANDROID_NATIVE };

public static PlatformType s_platform = PlatformType.web;
public static PlatformType s_platform = PlatformType.WEB;

/**
* Main method
Expand Down Expand Up @@ -116,7 +116,7 @@ public void run()

if (c_line.hasOption("version"))
{
stderr.println("(C) 2015-2018 Laboratoire d'informatique formelle");
stderr.println("(C) 2015-2020 Laboratoire d'informatique formelle");
stderr.println("This program comes with ABSOLUTELY NO WARRANTY.");
stderr.println("This is a free software, and you are welcome to redistribute it");
stderr.println("under certain conditions. See the file LICENSE for details.\n");
Expand All @@ -141,7 +141,7 @@ public void run()
}
if(c_line.hasOption("a")){

s_platform=PlatformType.android_native;
s_platform=PlatformType.ANDROID_NATIVE;
}
if (s_verbosity > 0)
{
Expand All @@ -150,6 +150,10 @@ public void run()

// The remaining arguments are the Cornipickle files to read
CornipickleServer server = new CornipickleServer(server_name, server_port);
if (c_line.hasOption("timeout"))
{
server.setTimeout(Integer.parseInt(c_line.get("timeout")));
}
// When called from the command-line (and hence working in stand-alone
// mode), the interpreter persists its state between requests by default
if (!c_line.hasOption("memento"))
Expand Down Expand Up @@ -228,6 +232,10 @@ private static CliParser setupCommandLine()
.withLongName("serve-as")
.withArgument("path")
.withDescription("Serve local folder as path"));
parser.addArgument(new Argument()
.withLongName("timeout")
.withArgument("x")
.withDescription("Set onload timeout to x ms"));
parser.addArgument(new Argument().withShortName("a")
.withLongName("android")
.withDescription("Change platform type to Android"));
Expand All @@ -240,7 +248,7 @@ private static CliParser setupCommandLine()
private static void showHeader(PrintStream out)
{
String platform_type = "A web GUI";
if (s_platform == PlatformType.android_native)
if (s_platform == PlatformType.ANDROID_NATIVE)
{
platform_type = "An Android GUI";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var dynamicProbe = function()
{
cp_probe.preEvaluate();
}
}, 500);
}, %%TIMEOUT%%);
};

//Loads the part of the probe file that doesn't change
Expand Down

0 comments on commit 1c14c85

Please sign in to comment.