Fixing second bug (C++ skeleton cannot connect to Java's callback socket server)...
authorrtrimana <rtrimana@uci.edu>
Wed, 7 Dec 2016 17:17:58 +0000 (09:17 -0800)
committerrtrimana <rtrimana@uci.edu>
Wed, 7 Dec 2016 17:17:58 +0000 (09:17 -0800)
iotjava/iotpolicy/IoTCompiler.java
iotjava/iotrmi/C++/IoTSocketClient.hpp
iotjava/iotrmi/C++/basics/TestClass_Debug.cpp [new file with mode: 0644]
iotjava/iotrmi/C++/basics/TestClass_Stub.cpp
iotjava/iotrmi/Java/basics/TestClass_Debug.java [new file with mode: 0644]
iotjava/iotrmi/Java/basics/TestClass_Stub.java

index d056fe4..04bf089 100644 (file)
@@ -3138,7 +3138,7 @@ public class IoTCompiler {
                        int newObjectId = getNewIntfaceObjectId(newIntface);
                        println("if (set" + newObjectId + "Allowed.find(methodId) == set" + newObjectId + "Allowed.end()) {");
                        println("cerr << \"Callback object for " + intface + " is not allowed to access method: \" << methodId;");
-                       println("exit(-1);");
+                       println("return;");
                        println("}");
                }
        }
@@ -3164,7 +3164,7 @@ public class IoTCompiler {
                println(" else {");
                println("cerr << \"Illegal object Id: \" << to_string(objId);");
                // TODO: perhaps need to change this into "throw" to make it cleaner (allow stack unfolding)
-               println("exit(-1);");
+               println("return;");
                println("}");
                println("}");
                println("}\n");
@@ -4149,12 +4149,12 @@ public class IoTCompiler {
                        println("if (_objectId == object" + newObjectId + "Id) {");
                        println("if (set" + newObjectId + "Allowed.find(methodId) == set" + newObjectId + "Allowed.end()) {");
                        println("cerr << \"Object with object Id: \" << _objectId << \"  is not allowed to access method: \" << methodId << endl;");
-                       println("exit(-1);");
+                       println("return;");
                        println("}");
                        println("}");
                        println("else {");
                        println("cerr << \"Object Id: \" << _objectId << \" not recognized!\" << endl;");
-                       println("exit(-1);");
+                       println("return;");
                        println("}");
                }
        }
index dd5d377..b69555f 100644 (file)
@@ -49,11 +49,8 @@ IoTSocketClient::IoTSocketClient(int iPort, const char* pStrHost, bool bReverse,
        m_addrRemote.sin_addr           = *((struct in_addr *) he->h_addr); 
        memset(&(m_addrRemote.sin_zero), 0, 8);
 
-       if (connect(m_iSock, (struct sockaddr *) &m_addrRemote, sizeof(struct sockaddr)) == -1) {
-
-               perror("IoTSocketClient: Connect m_iSock error!");
-               return;
-       }
+       // Make socket client wait for socket server to be ready
+       while (connect(m_iSock, (struct sockaddr *) &m_addrRemote, sizeof(struct sockaddr)) == -1) { }
 
        // Send out request for reversed bits or not
        char temp[1];
diff --git a/iotjava/iotrmi/C++/basics/TestClass_Debug.cpp b/iotjava/iotrmi/C++/basics/TestClass_Debug.cpp
new file mode 100644 (file)
index 0000000..8771d55
--- /dev/null
@@ -0,0 +1,23 @@
+#include <iostream>
+#include <string>
+#include "TestClassComplete_Stub.hpp"
+#include "CallBack.hpp"
+#include "IoTRMICall.hpp"
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+
+       int _port = 50044;
+       const char* _address = "localhost";
+       //const char* address = "128.195.136.170";      // dc-9.calit2.uci.edu
+       int _rev = 0;
+       bool bResult = false;
+
+       IoTRMICall *rmiCall = new IoTRMICall(_port, _address, _rev, &bResult);
+       cout << "Successfully connecting!" << endl << endl;
+       delete rmiCall;
+       
+       return 0;
+}
index d3c4e1d..a12c360 100644 (file)
@@ -25,7 +25,7 @@ int main(int argc, char *argv[])
        cout << "Return value: " << tcStub->getDouble(12345.678) << endl;
        cout << "Return value: " << tcStub->getBoolean(true) << endl;
        cout << "Return value: " << tcStub->getChar('c') << endl;
-/*     cout << "==== ARRAY ====" << endl;
+       cout << "==== ARRAY ====" << endl;
        vector<char> in1;
        in1.push_back(68);
        in1.push_back(69);
@@ -128,7 +128,7 @@ int main(int argc, char *argv[])
                cout << "Name: " << st.name << endl;
                cout << "Value:" << st.value << endl;
                cout << "Year" << st.year << endl;
-       }*/
+       }
        cout << "==== CALLBACK ====" << endl;
        CallBackInterface *cbSingle = new CallBack(2354);
        tcStub->registerCallback(cbSingle);
diff --git a/iotjava/iotrmi/Java/basics/TestClass_Debug.java b/iotjava/iotrmi/Java/basics/TestClass_Debug.java
new file mode 100644 (file)
index 0000000..6ab13ea
--- /dev/null
@@ -0,0 +1,23 @@
+import java.util.Arrays;
+import java.util.List;
+import java.util.ArrayList;
+import iotrmi.Java.IoTRMICall;
+import iotruntime.master.CommunicationHandler;
+
+public class TestClass_Debug {
+
+       public static void main(String[] args) throws Exception {
+
+               CommunicationHandler comHan = new CommunicationHandler(true);
+               int numOfPorts = 1;
+               int[] ports = comHan.getCallbackPorts(numOfPorts);
+
+               int _port = 56205;
+               String _address = "localhost";
+               //String address = "128.195.136.170";   // dc-9.calit2.uci.edu
+               int _rev = 0;
+
+               IoTRMICall rmiCall = new IoTRMICall(_port, _address, _rev);
+               System.out.println("Creating a new connection!!!");
+       }
+}
index 7a6b277..01baae6 100644 (file)
@@ -28,7 +28,7 @@ public class TestClass_Stub {
                System.out.println("Return value: " + tcstub.getBoolean(true));
                System.out.println("Return value: " + tcstub.getChar('c'));
 
-/*             System.out.println("==== ARRAY ====");
+               System.out.println("==== ARRAY ====");
                byte[] in1 = { 68, 69 };
                System.out.println("Return value: " + Arrays.toString(tcstub.getByteArray(in1)));
                short[] in2 = { (short)1234, (short)1235 };
@@ -98,7 +98,7 @@ public class TestClass_Stub {
                        System.out.println("Value: " + st.value);
                        System.out.println("Year: " + st.year);
                }
-*/
+
                System.out.println("==== CALLBACKS ====");
                CallBackInterface cbSingle = new CallBack(2354);
                tcstub.registerCallback(cbSingle);