From aef1c47206949bee61d0547bc6850ccc46f413e9 Mon Sep 17 00:00:00 2001 From: Shivang Vijay Date: Sun, 6 Aug 2023 00:41:24 +0530 Subject: [PATCH 1/5] Added more comments in code and remove unwanted comments from the code --- .vscode/settings.json | 6 ++++++ concore.hpp | 16 ++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..4db3e9a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "chrono": "cpp", + "thread": "cpp" + } +} \ No newline at end of file diff --git a/concore.hpp b/concore.hpp index 02bb36a..b74ddd7 100644 --- a/concore.hpp +++ b/concore.hpp @@ -38,8 +38,8 @@ class Concore{ char* sharedData_create; char* sharedData_get; // File sharing:- 0, Shared Memory:- 1 - int communication_iport = 0; - int communication_oport = 0; + int communication_iport = 0; // iport refers to input port + int communication_oport = 0; // oport refers to input port public: double delay = 1; @@ -58,17 +58,22 @@ class Concore{ oport = mapParser("concore.oport"); std::map::iterator it_iport = iport.begin(); std::map::iterator it_oport = oport.begin(); - int iport_number = ExtractNumeric(it_iport->first); + int iport_number = ExtractNumeric(it_iport->first); int oport_number = ExtractNumeric(it_oport->first); + // if iport_number and oport_number is equal to -1 then it refers to File Method, + // otherwise it refers to Shared Memory and the number represent the unique key. + if(oport_number != -1) { + // oport_number is not equal to -1 so refers to SM and value is key. communication_oport = 1; this->createSharedMemory(oport_number); } if(iport_number != -1) { + // iport_number is not equal to -1 so refers to SM and value is key. communication_iport = 1; this->getSharedMemory(iport_number); } @@ -112,6 +117,7 @@ class Concore{ if (numDigits == 1) { + // this case is to avoid shared memory when there is just 0 or any negative value in front of edge. if (std::stoi(numberString) <= 0) { return -1; @@ -348,7 +354,6 @@ class Concore{ if (sharedData_get && sharedData_get[0] != '\0') { std::string message(sharedData_get, strnlen(sharedData_get, 256)); ins = message; - // std::cout << "Received message: " << message << " ins " << ins.length() << std::endl; } else { @@ -367,7 +372,6 @@ class Concore{ this_thread::sleep_for(timespan); try{ if(shmId_get != -1) { - std::cout << "in read while\n"; std::string message(sharedData_get, strnlen(sharedData_get, 256)); ins = message; retrycount++; @@ -379,7 +383,7 @@ class Concore{ } //observed retry count in C++ from various tests is approx 80. catch(...){ - cout<<"Read error"; + std::cout << "Read error" << std::endl; } } s += ins; From 284f66aa2f332f48152c77dfb41121595a042742 Mon Sep 17 00:00:00 2001 From: Shivang Vijay Date: Sun, 6 Aug 2023 00:44:08 +0530 Subject: [PATCH 2/5] Remove .vscode config file --- .vscode/settings.json | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 4db3e9a..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "files.associations": { - "chrono": "cpp", - "thread": "cpp" - } -} \ No newline at end of file From 8153892d3b4a42a813a617c6c22847e8fb64b6b4 Mon Sep 17 00:00:00 2001 From: Harshal Rembhotkar Date: Sun, 31 Mar 2024 12:24:54 +0530 Subject: [PATCH 3/5] created a concoredocker.java - equivalent of concoredocker.py --- concoredocker.java | 149 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 concoredocker.java diff --git a/concoredocker.java b/concoredocker.java new file mode 100644 index 0000000..dde521c --- /dev/null +++ b/concoredocker.java @@ -0,0 +1,149 @@ +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; + +public class concoredocker { + private static Map iport = new HashMap<>(); + private static Map oport = new HashMap<>(); + private static String s = ""; + private static String olds = ""; + private static int delay = 1; + private static int retrycount = 0; + private static String inpath = "/in"; + private static String outpath = "/out"; + private static Map params = new HashMap<>(); + private static int maxtime; + + public static void main(String[] args) { + try { + iport = parseFile("concore.iport"); + } catch (IOException e) { + e.printStackTrace(); + } + try { + oport = parseFile("concore.oport"); + } catch (IOException e) { + e.printStackTrace(); + } + + try { + String sparams = new String(Files.readAllBytes(Paths.get(inpath + "1/concore.params"))); + if (sparams.charAt(0) == '"') { // windows keeps "" need to remove + sparams = sparams.substring(1); + sparams = sparams.substring(0, sparams.indexOf('"')); + } + if (!sparams.equals("{")) { + System.out.println("converting sparams: " + sparams); + sparams = "{'" + sparams.replaceAll(",", ",'").replaceAll("=", "':").replaceAll(" ", "") + "}"; + System.out.println("converted sparams: " + sparams); + } + try { + params = literalEval(sparams); + } catch (Exception e) { + System.out.println("bad params: " + sparams); + } + } catch (IOException e) { + params = new HashMap<>(); + } + + defaultMaxTime(100); + } + + private static Map parseFile(String filename) throws IOException { + String content = new String(Files.readAllBytes(Paths.get(filename))); + return literalEval(content); + } + + private static void defaultMaxTime(int defaultValue) { + try { + String content = new String(Files.readAllBytes(Paths.get(inpath + "1/concore.maxtime"))); + maxtime = literalEval(content).size(); + } catch (IOException e) { + maxtime = defaultValue; + } + } + + private static void unchanged() { + if (olds.equals(s)) { + s = ""; + } else { + olds = s; + } + } + + private static Object tryParam(String n, Object i) { + if (params.containsKey(n)) { + return params.get(n); + } else { + return i; + } + } + + private static Object read(int port, String name, String initstr) { + try { + String ins = new String(Files.readAllBytes(Paths.get(inpath + port + "/" + name))); + while (ins.length() == 0) { + Thread.sleep(delay); + ins = new String(Files.readAllBytes(Paths.get(inpath + port + "/" + name))); + retrycount++; + } + s += ins; + Object[] inval = new Map[] { literalEval(ins) }; + int simtime = Math.max((int) inval[0], 0); // assuming simtime is an integer + return inval[1]; + } catch (IOException | InterruptedException e) { + return initstr; + } + } + + private static void write(int port, String name, Object val, int delta) { + try { + String path = outpath + port + "/" + name; + StringBuilder content = new StringBuilder(); + if (val instanceof String) { + Thread.sleep(2 * delay); + } else if (!(val instanceof Object[])) { + System.out.println("mywrite must have list or str"); + System.exit(1); + } + if (val instanceof Object[]) { + Object[] arrayVal = (Object[]) val; + content.append("[") + .append(maxtime + delta) + .append(",") + .append(arrayVal[0]); + for (int i = 1; i < arrayVal.length; i++) { + content.append(",") + .append(arrayVal[i]); + } + content.append("]"); + } else { + content.append(val); + } + Files.write(Paths.get(path), content.toString().getBytes()); + } catch (IOException | InterruptedException e) { + System.out.println("skipping" + outpath + port + "/" + name); + } + } + + private static Object[] initVal(String simtimeVal) { + int simtime = 0; + Object[] val = new Object[] {}; + try { + Object[] arrayVal = new Map[] { literalEval(simtimeVal) }; + simtime = (int) arrayVal[0]; // assuming simtime is an integer + val = new Object[arrayVal.length - 1]; + System.arraycopy(arrayVal, 1, val, 0, val.length); + } catch (Exception e) { + e.printStackTrace(); + } + return val; + } + + private static Map literalEval(String s) { + + return new HashMap<>(); + } +} From 652a5e819616f3fb888400a58e9fe52c101d72a9 Mon Sep 17 00:00:00 2001 From: Harshal Rembhotkar Date: Thu, 11 Apr 2024 20:24:09 +0530 Subject: [PATCH 4/5] Created a Dockerfile : file supports java language --- Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7e46ecb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM openjdk:latest +COPY . /src +WORKDIR /src + From 40124c3b2d285fda95f1d93318e243fc3455c52b Mon Sep 17 00:00:00 2001 From: Harshal Rembhotkar Date: Thu, 11 Apr 2024 20:39:25 +0530 Subject: [PATCH 5/5] Rename Dockerfile to Dockerfile.java --- Dockerfile => Dockerfile.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Dockerfile => Dockerfile.java (100%) diff --git a/Dockerfile b/Dockerfile.java similarity index 100% rename from Dockerfile rename to Dockerfile.java