# For C++ instrumentation
FIELD_NUMBER=3
+#FIELD_NUMBER=1
# Field lifx_light_bulb
FIELD_0=lifx_light_bulb
#include "Lifxtest.hpp"
#include "LifxLightBulb.cpp"
#include "LabRoom.cpp"
-#include "Iterator.hpp"
-
// External create, destroy, and init functions
extern "C" void* createLifxtest(void** params) {
- // Arguments: IoTSet<void*>* lifx_light_bulb
- //return new Lifxtest((IoTSet<void*>*) params[0]);
+ // Arguments: IoTSet<void*>* lifx_light_bulb, IoTSet<void*>* lab_room, IoTRelation<void*,void*> roomLightRelation
return new Lifxtest((IoTSet<void*>*) params[0], (IoTSet<void*>*) params[1], (IoTRelation<void*,void*>*) params[2]);
}
// Empty constructor (for testing)
Lifxtest::Lifxtest() {
- log.open("Lifxtest_object_cpp.log");
- log << "lifx_light_bulb initialized!" << endl;
-}
-
-
-// Constructor with only 1 IoTSet object (lifx_light_bulb)
-Lifxtest::Lifxtest(IoTSet<void*>* _lifx_light_bulb) {
-
- log.open("Lifxtest_object_cpp.log");
- lifx_light_bulb = _lifx_light_bulb;
- log << "lifx_light_bulb initialized!" << endl;
}
// Constructor with 2 IoTSet and 1 IoTRelation objects
Lifxtest::Lifxtest(IoTSet<void*>* _lifx_light_bulb, IoTSet<void*>* _lab_room, IoTRelation<void*,void*>* _roomLightRelation) {
- log.open("Lifxtest_object_cpp.log");
- lifx_light_bulb = _lifx_light_bulb;
- lab_room = _lab_room;
- roomLightRelation = _roomLightRelation;
- log << "lifx_light_bulb initialized!" << endl;
-}
-
-
-// Constructor with void** argument
-Lifxtest::Lifxtest(void** args) {
-
- log.open("Lifxtest_object_cpp.log");
- lifx_light_bulb = (IoTSet<void*>*) args[0];
- log << "lifx_light_bulb initialized!" << endl;
+ log.open("/home/iotuser/iot2/bin/iotruntime/log/Lifxtest_object_cpp.log");
+ lifx_light_bulb = _lifx_light_bulb;
+ lab_room = _lab_room;
+ roomLightRelation = _roomLightRelation;
+ log << "lifx_light_bulb initialized!" << endl;
}
-
Lifxtest::~Lifxtest() {
}
-
-/*void Lifxtest::init() {
-
- unordered_set<void*>* bulbSet = lifx_light_bulb->values();
- //for (unordered_set<void*>::const_iterator itr = bulbSet->begin(); itr != bulbSet->end(); ++itr) {
- log << "Get into Lifxtest init()!" << endl;
- for (auto itr = bulbSet->begin(); itr != bulbSet->end(); ++itr) {
- log << "Iteration init()!" << endl;
- //LightBulb* lifx = (LightBulb*) *itr;
- LightBulbTest* lifx = (LightBulbTest*) *itr;
- log << "Getting object!" << endl;
- lifx->init();
- log << "Executing init!" << endl;
- this_thread::sleep_for (chrono::milliseconds(1000));
-
- for (int i = 0; i < 10; i++) {
-
- lifx->init();
-// lifx->turnOff();
- //cout << "Turning off!" << endl;
- log << "Turning off!" << endl;
- this_thread::sleep_for (chrono::milliseconds(1000));
-// lifx->turnOn();
- //cout << "Turning on!" << endl;
- log << "Turning on!" << i << endl;
- this_thread::sleep_for (chrono::milliseconds(1000));
- }
-
-*/
-/* for (int i = 2500; i < 9000; i += 100) {
- //cout << "Adjusting Temp: " << i << endl;
- log << "Adjusting Temp: " << i << endl;
- lifx->setTemperature(i);
- this_thread::sleep_for (chrono::milliseconds(100));
- }
-
- for (int i = 9000; i > 2500; i -= 100) {
- //cout << "Adjusting Temp: " << i << endl;
- log << "Adjusting Temp: " << i << endl;
- lifx->setTemperature(i);
- this_thread::sleep_for (chrono::milliseconds(100));
- }
-
- for (int i = 100; i > 0; i -= 10) {
- //cout << "Adjusting Brightness: " << i << endl;
- log << "Adjusting Brightness: " << i << endl;
- lifx->setColor(lifx->getHue(), lifx->getSaturation(), i);
- this_thread::sleep_for (chrono::milliseconds(500));
- }
-
- for (int i = 0; i < 100; i += 10) {
- //cout << "Adjusting Brightness: " << i << endl;
- log << "Adjusting Brightness: " << i << endl;
- lifx->setColor(lifx->getHue(), lifx->getSaturation(), i);
- this_thread::sleep_for (chrono::milliseconds(500));
- }
- lifx->turnOff();
- }
-
- log << "End of iteration.. closing!" << endl;
- log.close();
- //while(true) { } // Testing infinite loop - will need to do "pkill IoTSlave"
-}*/
-
-
void Lifxtest::init() {
unordered_set<void*>* bulbSet = lifx_light_bulb->values();
unordered_set<void*>* roomSet = lab_room->values();
unordered_multimap<void*,void*>* roomLightRel = roomLightRelation->values();
log << "Size of map: " << roomLightRel->size() << endl;
- //for (unordered_set<void*>::const_iterator itr = bulbSet->begin(); itr != bulbSet->end(); ++itr) {
+
for (auto itr = roomSet->begin(); itr != roomSet->end(); ++itr) {
- log << "Getting Room!" << endl;
- //Room* rs = (Room*) *itr;
RoomSmart* rs = (RoomSmart*) *itr;
- log << "Getting Room! ID: " << rs->getRoomID() << endl;
- //auto itrLight = roomLightRel->find(rs);
+ log << "Now turning on lights in room with ID: " << rs->getRoomID() << endl;
+ auto itrLight = roomLightRel->find(rs);
- /*if (itrLight == roomLightRel->end())
- log << "No match!" << endl;
- //while (itrLight != roomLightRel->end()) {
+ if (itrLight == roomLightRel->end())
+ log << "No matching light! - should not get here at all!" << endl;
else {
- //LightBulb* lifx = (LightBulb*) itrLight->second;
log << "Getting LightBulb!" << endl;
LightBulbTest* lifx = (LightBulbTest*) itrLight->second;
log << "Executing init!" << endl;
lifx->init();
for (int i = 0; i < 10; i++) {
lifx->turnOff();
- //cout << "Turning off!" << endl;
log << "Turning off!" << endl;
this_thread::sleep_for (chrono::milliseconds(1000));
lifx->turnOn();
- //cout << "Turning on!" << endl;
log << "Turning on!" << i << endl;
this_thread::sleep_for (chrono::milliseconds(1000));
}
+ /* Note: The bottom part has not yet been heavily tested and
+ this might get the execution stuck at some point.
+ We are suspecting that this is due to the complex interaction
+ of the multiple threads that we have.
for (int i = 2500; i < 9000; i += 100) {
- //cout << "Adjusting Temp: " << i << endl;
log << "Adjusting Temp: " << i << endl;
lifx->setTemperature(i);
this_thread::sleep_for (chrono::milliseconds(100));
}
for (int i = 9000; i > 2500; i -= 100) {
- //cout << "Adjusting Temp: " << i << endl;
log << "Adjusting Temp: " << i << endl;
lifx->setTemperature(i);
this_thread::sleep_for (chrono::milliseconds(100));
}
+
+ double hue = lifx->getHue();
+ double saturation = lifx->getSaturation();
for (int i = 100; i > 0; i -= 10) {
- //cout << "Adjusting Brightness: " << i << endl;
log << "Adjusting Brightness: " << i << endl;
- lifx->setColor(lifx->getHue(), lifx->getSaturation(), i);
+ lifx->setColor(hue, saturation, i);
this_thread::sleep_for (chrono::milliseconds(500));
}
for (int i = 0; i < 100; i += 10) {
- //cout << "Adjusting Brightness: " << i << endl;
log << "Adjusting Brightness: " << i << endl;
- lifx->setColor(lifx->getHue(), lifx->getSaturation(), i);
+ lifx->setColor(hue, saturation, i);
this_thread::sleep_for (chrono::milliseconds(500));
- }
- //++itrLight;
- }*/
+ }*/
+ //lifx->turnOff();
+ }
log << "End of one LightBulb!" << endl << endl;
}
log.close();
//while(true) { } // Testing infinite loop - will need to do "pkill IoTSlave"
}
-
-/*
-int main(int argc, char *argv[])
-{
- // LightBulb #1
- string macAddress1 = "D073D5128E300000";
- string devIPAddress1 = "192.168.2.126";
- IoTDeviceAddress* devAddress1 = new IoTDeviceAddress(devIPAddress1, 12345, 56700, false, false);
- unordered_set<void*>* myset1 = new unordered_set<void*>();
- myset1->insert(devAddress1);
- IoTSet<void*>* setDevAddress1 = new IoTSet<void*>(myset1);
- LifxLightBulb *llb1 = new LifxLightBulb(setDevAddress1, macAddress1);
- //cout << "Generated LifxLightBulb object!" << endl;
-
- // LightBulb #2
- string macAddress2 = "D073D50241DA0000";
- string devIPAddress2 = "192.168.2.232";
- IoTDeviceAddress* devAddress2 = new IoTDeviceAddress(devIPAddress2, 12346, 56700, false, false);
- unordered_set<void*>* myset2 = new unordered_set<void*>();
- myset2->insert(devAddress2);
- IoTSet<void*>* setDevAddress2 = new IoTSet<void*>(myset2);
- LifxLightBulb *llb2 = new LifxLightBulb(setDevAddress2, macAddress2);
-
- // Set of lightbulbs
- unordered_set<void*>* setLb = new unordered_set<void*>();
- setLb->insert(llb1);
- setLb->insert(llb2);
- IoTSet<void*>* lbSet = new IoTSet<void*>(setLb);
-
- // Set of rooms
- LabRoom *lr1 = new LabRoom();
- LabRoom *lr2 = new LabRoom();
- unordered_set<void*>* setLR = new unordered_set<void*>();
- setLR->insert(lr1);
- setLR->insert(lr2);
- IoTSet<void*>* lrSet = new IoTSet<void*>(setLR);
-
- pair<void*,void*>* pair1 = new pair<void*,void*>(lr1, llb1);
- pair<void*,void*>* pair2 = new pair<void*,void*>(lr2, llb2);
- unordered_multimap<void*,void*>* mmap = new unordered_multimap<void*,void*>();
- mmap->insert(*pair1);
- mmap->insert(*pair2);
- IoTRelation<void*,void*>* rlRel = new IoTRelation<void*,void*>(mmap);
-
- //void* args[1];
- //args[0] = (void*) lbSet;
- //Lifxtest *lt = new Lifxtest(args);
- Lifxtest *lt = new Lifxtest(lbSet, lrSet, rlRel);
- lt->init();
-
- //delete llb1;
- //delete llb2;
- delete devAddress1;
- delete devAddress2;
- delete myset1;
- delete myset2;
- delete setDevAddress1;
- delete setDevAddress2;
- delete setLb;
- delete lbSet;
- delete lr1;
- delete lr2;
- delete lrSet;
- delete pair1;
- delete pair2;
-
- return 0;
-}*/
-
-
public:
Lifxtest();
- Lifxtest(IoTSet<void*>* _lifx_light_bulb);
Lifxtest(IoTSet<void*>* _lifx_light_bulb, IoTSet<void*>* _lab_room, IoTRelation<void*,void*>* _roomLightRelation);
Lifxtest(void** args);
~Lifxtest();
using namespace std;
+//LightBulbTest_Stub::LightBulbTest_Stub(int _portSend, int _portRecv, const char* _skeletonAddress, int _rev, bool* _bResult) {
LightBulbTest_Stub::LightBulbTest_Stub(int _portSend, int _portRecv, const char* _skeletonAddress, int _rev, bool* _bResult) {
+
+ int i=0;
+ string file = "LightBulbTest_cpp" + to_string(i) + ".log";
+ while (ifstream(file.c_str())) {
+ i++;
+ file = "LightBulbTest_cpp" + to_string(i) + ".log";
+ }
+ log.open(file);
+ log << "Constructing LightBulbTest_Stub!" << endl;
+ log << "Port send: " << _portSend << endl;
+ log << "Port recv: " << _portRecv << endl;
+ log << "Skeleton addr: " << _skeletonAddress << endl;
+ log << "Rev: " << _rev << endl;
+ log << "Result: " << _bResult << endl;
+
rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev, _bResult);
+ log << "Reached 1!" << endl;
rmiComm->registerStub(objectId, 6, &retValueReceived6);
rmiComm->registerStub(objectId, 3, &retValueReceived3);
rmiComm->registerStub(objectId, 8, &retValueReceived8);
extern "C" void initLightBulbTest_Stub(void* t) {
}
-int main() {
+/*int main() {
+ return 0;
+}*/
+
+int main()
+{
+
+ int send_port = 5010;
+ int recv_port = 5011;
+ //const char* skeletonAddress = "127.0.0.1";
+ const char* skeletonAddress = "localhost";
+ int rev = 0;
+ bool result = false;
+
+ LightBulbTest_Stub *lbs = new LightBulbTest_Stub(send_port, recv_port, skeletonAddress, rev, &result);
+ cout << "Successfully instantiated stub!" << endl;
+ lbs->init();
+ lbs->turnOn();
+ this_thread::sleep_for (chrono::milliseconds(1000));
+ lbs->turnOff();
+ for (int i = 0; i < 2; i++) {
+ lbs->turnOff();
+ cout << "Turning off!" << endl;
+ this_thread::sleep_for (chrono::milliseconds(1000));
+ lbs->turnOn();
+ cout << "Turning on!" << endl;
+ this_thread::sleep_for (chrono::milliseconds(1000));
+ double hue = lbs->getHue();
+ double saturation = lbs->getSaturation();
+ cout << "Hue: " << hue << endl;
+ cout << "Saturation: " << saturation << endl;
+ this_thread::sleep_for (chrono::milliseconds(1000));
+ }
+ //lbs->turnOff();
+ cout << "Done controlling! Exit now!" << endl;
+
+ delete lbs;
+
return 0;
}
#include <mutex>
#include <vector>
#include <set>
+#include <fstream>
#include "IoTRMIComm.hpp"
#include "IoTRMICommClient.hpp"
#include "IoTRMICommServer.hpp"
bool retValueReceived8 = false;
bool retValueReceived7 = false;
bool retValueReceived9 = false;
-
+ ofstream log;
public:
# Light stub .so file will be generated for ARM (Raspberry Pi)
PHONY += so-lightstub
so-lightstub:
- $(G++) $(ARGS) ./LightBulbTest_Stub.cpp $(BASE)/iotjava/iotruntime/cpp/socket/Socket.cpp -o $(BIN_DIR)/Lifxtest/LightBulbTest_Stub.so --std=c++11 -pthread -pg -I$(BASE)/iotjava/iotruntime/cpp/ -I$(BASE)/iotjava/iotruntime/cpp/socket/ -I$(BASE)/iotjava/iotruntime/cpp/setrelation/ -I$(BASE)/iotjava/iotrmi/C++/ -I$(BASE)/benchmarks/virtuals/
+ $(G++) $(ARGS) ./LightBulbTest_Stub.cpp -o $(BIN_DIR)/Lifxtest/LightBulbTest_Stub.so --std=c++11 -pthread -pg -I$(BASE)/iotjava/iotruntime/cpp/ -I$(BASE)/iotjava/iotruntime/cpp/socket/ -I$(BASE)/iotjava/iotruntime/cpp/setrelation/ -I$(BASE)/iotjava/iotrmi/C++/ -I$(BASE)/benchmarks/virtuals/
cp ./Lifxtest.config $(BIN_DIR)/Lifxtest
# Light stub .so file will be generated for ARM (Raspberry Pi) using a cross-compiler
}
int main() {
+
+ /*int send_port = 5010;
+ int recv_port = 5011;
+ const char* skeletonAddress = "localhost";
+ //const char* skeletonAddress = "l92.168.1.198";
+ //const char* skeletonAddress = "127.0.0.1";
+ int rev = 0;
+ bool result = false;
+
+ RoomSmart_Stub *rm = new RoomSmart_Stub(send_port, recv_port, skeletonAddress, rev, &result);
+ cout << "Successfully instantiated stub!" << endl;*/
+
return 0;
}
// External functions to create, destroy and initialize this class object
extern "C" void* createLabRoom(void** params) {
- // Arguments: IoTSet<IoTDeviceAddress*>* _devAddress, string macAddress
return new LabRoom();
}
#ifndef _LABROOM_HPP__
#define _LABROOM_HPP__
#include <iostream>
-#include <fstream>
#include "Room.hpp"
using namespace std;
Room_Skeleton::Room_Skeleton(Room *_mainObj, int _portSend, int _portRecv) {
- // Logging
- int i=0;
- string file = "Room_Skeleton_cpp" + to_string(i) + ".log";
- while (ifstream(file.c_str())) {
- i++;
- file = "Room_Skeleton_cpp" + to_string(i) + ".log";
- }
- log.open(file);
- log << "Port send: " << _portSend << endl;
- log << "Port receive: " << _portRecv << endl;
bool _bResult = false;
mainObj = _mainObj;
rmiComm = new IoTRMICommServer(_portSend, _portRecv, &_bResult);
- log << "Established connection with slave! Wait request invoke now..." << endl;
IoTRMIUtil::mapSkel->insert(make_pair(_mainObj, this));
IoTRMIUtil::mapSkelId->insert(make_pair(_mainObj, objectId));
rmiComm->registerSkeleton(objectId, &methodReceived);
extern "C" void initRoom_Skeleton(void* t) {
}
+
int main() {
return 0;
}
#include "IoTRMICommClient.hpp"
#include "IoTRMICommServer.hpp"
-#include <fstream>
-
using namespace std;
class Room_Skeleton : public Room
// Synchronization variables
bool methodReceived = false;
bool didAlreadyInitWaitInvoke = false;
- ofstream log;
public:
char tmpMacAddress[16];
strcpy(tmpMacAddress, macAddress.c_str());
- //test[0] = (char) strtol(strTest.c_str(), NULL, 16);
for(int i=0; i<16; i=i+2) {
// Take 2 digits and then convert
char tmpMacByte[2];
tmpMacByte[1] = tmpMacAddress[i+1];
bulbMacAddress[i/2] = (char) strtol(tmpMacByte, NULL, 16);
}
- //IoTRMIUtil::printBytes(bulbMacAddress, 8, false);
}
bulbMacAddress[i/2] = (char) strtol(tmpMacByte, NULL, 16);
}
//cout << "MAC address is set. Value: ";
- IoTRMIUtil::printBytes(bulbMacAddress, 8, false);
- // Logging
- int i=0;
- string file = "LifxLightBulb_cpp" + to_string(i) + ".log";
- while (ifstream(file.c_str())) {
- i++;
- file = "LifxLightBulb_cpp" + to_string(i) + ".log";
- }
- log.open(file);
- log << "MAC address is " << macAddress << endl;
// Initialize device address
lb_addresses = _devAddress;
if (didAlreadyInit.exchange(true))
return;
- log << "lb_addresses has: " << lb_addresses->size() << endl;
unordered_set<void*>::const_iterator itr = lb_addresses->begin();
IoTDeviceAddress* deviceAddress = (IoTDeviceAddress*) *itr;
//cout << "Address: " << deviceAddress->getAddress() << endl;
- log << "Address: " << deviceAddress->getAddress() << endl;
// Create IoTUDP socket
communicationSocket = new IoTUDP(deviceAddress);
//cout << "Host address: " << communicationSocket->getHostAddress() << endl;
//cout << "Source port: " << communicationSocket->getSourcePort() << endl;
//cout << "Destination port: " << communicationSocket->getDestinationPort() << endl << endl;
- log << "Host address: " << communicationSocket->getHostAddress() << endl;
- log << "Source port: " << communicationSocket->getSourcePort() << endl;
- log << "Destination port: " << communicationSocket->getDestinationPort() << endl << endl;
// Launch the worker function in a separate thread.
// NOTE: "this" pointer is passed into the detached thread because it does not belong
th1.detach();
//cout << "Initialized LifxLightBulb!" << endl;
- log << "Initialized LifxLightBulb!" << endl;
- log.close();
}
int type = recHeader.getType();
//cout << "Received: " << type << endl;
- log << "Received: " << type << endl;
DeviceStateService* dat = NULL;
switch (type) {
// Need timeout on receives since we are not sure if a packet will be available
// for processing so don't block waiting
llb->communicationSocket->setTimeOut(50000); // In milliseconds
-
llb->turnOff();
int64_t lastSentGetBulbVersionRequest = 0; // time last request sent
char dat[1024];
- llb->log << "Turning off and entering while loop!" << endl;
-
while (true) {
// Check if we got the bulb version yet
// could have requested it but message could have gotten lost (UDP)
cerr << "Invalid parameter values" << endl;
exit(1);
}
-
char packetBytes[42];
-
LifxHeader header;
header.setSize(42);
header.setTagged(false);
delete color;
}
-
-// Functions for the main function
-void onOff(LifxLightBulb *llb) {
-
- for (int i = 0; i < 2; i++) {
- llb->turnOff();
- //cout << "Turning off!" << endl;
- this_thread::sleep_for (chrono::milliseconds(1000));
- llb->turnOn();
- //cout << "Turning on!" << endl;
- this_thread::sleep_for (chrono::milliseconds(1000));
- }
-}
-
-
-void adjustTemp(LifxLightBulb *llb) {
-
- for (int i = 2500; i < 9000; i += 100) {
- //cout << "Adjusting Temp: " << i << endl;
- llb->setTemperature(i);
- this_thread::sleep_for (chrono::milliseconds(100));
- }
- //cout << "Adjusted temperature to 9000!" << endl;
- for (int i = 9000; i > 2500; i -= 100) {
- //cout << "Adjusting Temp: " << i << endl;
- llb->setTemperature(i);
- this_thread::sleep_for (chrono::milliseconds(100));
- }
- //cout << "Adjusted temperature to 2500!" << endl;
-}
-
-
-void adjustBright(LifxLightBulb *llb) {
- for (int i = 100; i > 0; i -= 10) {
- //cout << "Adjusting Brightness: " << i << endl;
- llb->setColor(llb->getHue(), llb->getSaturation(), i);
- this_thread::sleep_for (chrono::milliseconds(100));
- }
- //cout << "Adjusted brightness to 0!" << endl;
- for (int i = 0; i < 100; i += 10) {
- //cout << "Adjusting Brightness: " << i << endl;
- llb->setColor(llb->getHue(), llb->getSaturation(), i);
- this_thread::sleep_for (chrono::milliseconds(100));
- }
- //cout << "Adjusting brightness to 100!" << endl;
-}
-
-
-/*int main(int argc, char *argv[])
-{
- string macAddress1 = "D073D5128E300000";
- //string macAddress = "D073D50241DA0000";
- string devIPAddress1 = "192.168.1.126";
- //string devIPAddress = "192.168.1.232";
- IoTDeviceAddress* devAddress1 = new IoTDeviceAddress(devIPAddress1, 12345, 56700, false, false);
- unordered_set<void*>* myset1 = new unordered_set<void*>();
- myset1->insert(devAddress1);
-
- IoTSet<void*>* setDevAddress1 = new IoTSet<void*>(myset1);
- LifxLightBulb *llb1 = new LifxLightBulb(setDevAddress1, macAddress1);
- cout << "Generated LifxLightBulb object!" << endl;
- llb1->init();
- cout << "Initialized!" << endl;
- llb1->turnOn();
- cout << "Turning on!" << endl;
- onOff(llb1);
-// adjustTemp(llb1);
-// adjustBright(llb1);
- llb1->turnOff();
-
-// delete devAddress1;
-// delete llb1;
-
- return 0;
-}*/
#include "IoTSet.hpp"
#include "IoTUDP.hpp"
#include "IoTDeviceAddress.hpp"
-#include "Iterator.hpp"
// Helper classes for LifxLightBulb
#include "LifxHeader.hpp"
using namespace std;
LightBulb_Skeleton::LightBulb_Skeleton(LightBulb *_mainObj, int _portSend, int _portRecv) {
+
bool _bResult = false;
mainObj = _mainObj;
rmiComm = new IoTRMICommServer(_portSend, _portRecv, &_bResult);
extern "C" void* createLightBulb_Skeleton(void** params) {
// Args: *_mainObj, int _portSend, int _portRecv
- return new LightBulb_Skeleton((LightBulb*) params[0], *((int*) params[0]), *((int*) params[1]));
+ return new LightBulb_Skeleton((LightBulb*) params[0], *((int*) params[1]), *((int*) params[2]));
}
extern "C" void destroyLightBulb_Skeleton(void* t) {
extern "C" void initLightBulb_Skeleton(void* t) {
}
-int main() {
- return 0;
-}
-
// Synchronization variables
bool methodReceived = false;
bool didAlreadyInitWaitInvoke = false;
-
public:
$(JAVAC) $(JFLAGS) LifxLightBulb/*.java
cp LifxLightBulb/LifxLightBulb.config $(BIN_DIR)/iotcode/LifxLightBulb
cd $(BIN_DIR)/iotcode/LifxLightBulb; $(JAR) $(JARFLAGS) LifxLightBulb.jar ../../iotcode/LifxLightBulb/*.class ../../iotcode/interfaces/LightBulb*.class; mkdir tmp; mv LifxLightBulb.class ./tmp; rm -rf *.class; mv ./tmp/* ./; rm -rf ./tmp
-
+
PHONY += camera
camera:
$(JAVAC) $(JFLAGS) AmcrestCamera/*.java
moisture:
$(JAVAC) $(JFLAGS) SpruceSensor/*.java
cp SpruceSensor/SpruceSensor.config $(BIN_DIR)/iotcode/SpruceSensor
- #cd $(BIN_DIR)/iotcode/SpruceSensor; $(JAR) $(JARFLAGS) SpruceSensor.jar ../../iotcode/SpruceSensor/*.class ../../iotcode/interfaces/MoistureSensor*.class ../../iotcode/interfaces/Camera*.class ../../IrrigationController/MotionDetection*.class
cd $(BIN_DIR)/iotcode/SpruceSensor; $(JAR) $(JARFLAGS) SpruceSensor.jar ../../iotcode/SpruceSensor/*.class ../../iotcode/interfaces/MoistureSensor*.class ../../iotcode/interfaces/Camera*.class; mkdir tmp; mv SpruceSensor.class ./tmp; rm -rf *.class; mv ./tmp/* ./; rm -rf ./tmp
PHONY += weathergateway
motion:
$(JAVAC) $(JFLAGS) MotionSensor/*.java
cp MotionSensor/MotionSensor.config $(BIN_DIR)/iotcode/MotionSensor
- #cd $(BIN_DIR)/iotcode/MotionSensor; $(JAR) $(JARFLAGS) MotionSensor.jar ../../iotcode/MotionSensor/*.class ../../iotcode/interfaces/SmartthingsSensor*.class ../../iotcode/interfaces/Camera*.class ../../IrrigationController/MotionDetection*.class
cd $(BIN_DIR)/iotcode/MotionSensor; $(JAR) $(JARFLAGS) MotionSensor.jar ../../iotcode/MotionSensor/*.class ../../iotcode/interfaces/SmartthingsSensor*.class ../../iotcode/interfaces/Camera*.class; mkdir tmp; mv MotionSensor.class ./tmp; rm -rf *.class; mv ./tmp/* ./; rm -rf ./tmp
PHONY += multipurpose
multipurpose:
$(JAVAC) $(JFLAGS) MultipurposeSensor/*.java
cp MultipurposeSensor/MultipurposeSensor.config $(BIN_DIR)/iotcode/MultipurposeSensor
- #cd $(BIN_DIR)/iotcode/MultipurposeSensor; $(JAR) $(JARFLAGS) MultipurposeSensor.jar ../../iotcode/MultipurposeSensor/*.class ../../iotcode/interfaces/SmartthingsSensor*.class ../../iotcode/interfaces/Camera*.class ../../IrrigationController/MotionDetection*.class
cd $(BIN_DIR)/iotcode/MultipurposeSensor; $(JAR) $(JARFLAGS) MultipurposeSensor.jar ../../iotcode/MultipurposeSensor/*.class ../../iotcode/interfaces/SmartthingsSensor*.class ../../iotcode/interfaces/Camera*.class; mkdir tmp; mv MultipurposeSensor.class ./tmp; rm -rf *.class; mv ./tmp/* ./; rm -rf ./tmp
PHONY += waterleak
waterleak:
$(JAVAC) $(JFLAGS) WaterLeakSensor/*.java
cp WaterLeakSensor/WaterLeakSensor.config $(BIN_DIR)/iotcode/WaterLeakSensor
- #cd $(BIN_DIR)/iotcode/WaterLeakSensor; $(JAR) $(JARFLAGS) WaterLeakSensor.jar ../../iotcode/WaterLeakSensor/*.class ../../iotcode/interfaces/SmartthingsSensor*.class ../../iotcode/interfaces/Camera*.class ../../IrrigationController/MotionDetection*.class
cd $(BIN_DIR)/iotcode/WaterLeakSensor; $(JAR) $(JARFLAGS) WaterLeakSensor.jar ../../iotcode/WaterLeakSensor/*.class ../../iotcode/interfaces/SmartthingsSensor*.class ../../iotcode/interfaces/Camera*.class; mkdir tmp; mv WaterLeakSensor.class ./tmp; rm -rf *.class; mv ./tmp/* ./; rm -rf ./tmp
PHONY += doorlock
check-moisture:
$(JAVAC) $(JFLAGS) $(CHECKER_OPT) $(ASTUBS) SpruceSensor/*.java
cp SpruceSensor/SpruceSensor.config $(BIN_DIR)/iotcode/SpruceSensor
- #cd $(BIN_DIR)/iotcode/SpruceSensor; $(JAR) $(JARFLAGS) SpruceSensor.jar ../../iotcode/SpruceSensor/*.class ../../iotcode/interfaces/MoistureSensor*.class ../../iotcode/interfaces/Camera*.class ../../IrrigationController/MotionDetection*.class
cd $(BIN_DIR)/iotcode/SpruceSensor; $(JAR) $(JARFLAGS) SpruceSensor.jar ../../iotcode/SpruceSensor/*.class ../../iotcode/interfaces/MoistureSensor*.class ../../iotcode/interfaces/Camera*.class; mkdir tmp; mv SpruceSensor.class ./tmp; rm -rf *.class; mv ./tmp/* ./; rm -rf ./tmp
PHONY += check-weathergateway
#include <iostream>
#include <vector>
#include <set>
-#include "IoTRMICall.hpp"
#include "IoTRMIObject.hpp"
using namespace std;
#include <sstream>
#include <vector>
#include <set>
-#include "IoTRMICall.hpp"
#include "IoTRMIObject.hpp"
using namespace std;
virtual void setTemperature(int _temperature) = 0;
virtual double getHue() = 0;
virtual int getTemperature() = 0;
-
- // Custom hasher for LightBulbTest iterator
- size_t hash(LightBulbTest const& device) const {
-
- // Use device address for hashing
- std::stringstream ss;
- ss << &device;
- std::hash<std::string> hashVal;
- return hashVal(ss.str());
- }
};
#endif
#include <iostream>
#include <vector>
#include <set>
-#include "IoTRMICall.hpp"
#include "IoTRMIObject.hpp"
using namespace std;
retEl->setNext(NULL);
delete retEl;
// Return just the value
- //cout << "Print bytes inside dequeue: ";
- //IoTRMIUtil::printBytes(*((char**) retVal), *length, false);
- //cout << "Dequeuing: " << *((char**) retVal) << endl;
- //cout << "Dequeuing address: " << std::ref(retVal) << endl;
return retVal;
}
}
+++ /dev/null
-#include <iostream>
-#include <string>
-#include "IoTRMICall.hpp"
-
-using namespace std;
-
-int main(int argc, char *argv[])
-{
- int port = 5010;
- const char* address = "localhost";
- int rev = 0;
- bool bResult = false;
-
- int numRet = 3;
- string retCls[] = { "int", "string", "int" };
- int param1 = 0;
- string param2 = "";
- int param3 = 0;
- void* retObj[] = { ¶m1, ¶m2, ¶m3 };
-
- IoTRMICall *rc = new IoTRMICall(port, address, rev, &bResult);
- char retBytes[] = { 0, 0, 4, -46, 0, 0, 0, 10, 116, 101, 115, 116, 115, 116, 114, 105, 110, 103, 0, 0, 21, 56 };
- rc->getReturnObjects(retBytes, retCls, numRet, retObj);
- cout << "Param1: " << param1 << endl;
- cout << "Param2: " << param2 << endl;
- cout << "Param3: " << param3 << endl;
-
- return 0;
-}
+++ /dev/null
-/** Class IoTRMICall provides methods that the upper
- * layers can use to transport and invoke methods
- * when using IoTSocket, IoTSocketClient and IoTSocketServer.
- * <p>
- * This class serves in the stub part of the RMI
- * communication. It bridges and creates RMI requests to be
- * transferred into the RMI object.
- *
- * @author Rahmadi Trimananda <rtrimana @ uci.edu>
- * @version 1.0
- * @since 2016-10-18
- */
-#ifndef _IOTRMICALL_HPP__
-#define _IOTRMICALL_HPP__
-
-#include <iostream>
-#include <string>
-#include <mutex>
-#include "IoTRMIUtil.hpp"
-#include "IoTSocketClient.hpp"
-
-using namespace std;
-
-mutex mtx;
-
-class IoTRMICall final {
- public:
- IoTRMICall(int _port, const char* _address, int _rev, bool* _bResult);
- ~IoTRMICall();
- // Public methods
- int methodLength(string paramCls[], void* paramObj[], int numParam);
- char* methodToBytes(int objectId, int methId, string paramCls[], void* paramObj[],
- char* method, int numParam);
- void* remoteCall(int objectId, int methodId, string retType, string paramCls[],
- void* paramObj[], int numParam, void* retObj);
- void** getStructObjects(string retType[], int numRet, void* retObj[]);
- void** getReturnObjects(char* retBytes, string retCls[], int numRet, void* retObj[]);
-
- private:
- IoTRMIUtil *rmiUtil;
- IoTSocketClient *rmiClient;
-
- // Private methods
- void getMethodIds(const string methodSign[], const int size);
-};
-
-
-// Constructor
-IoTRMICall::IoTRMICall(int _port, const char* _address, int _rev, bool* _bResult) {
-
- rmiUtil = new IoTRMIUtil();
- if (rmiUtil == NULL) {
- perror("IoTRMICall: IoTRMIUtil isn't initialized!");
- }
- rmiClient = new IoTSocketClient(_port, _address, _rev, _bResult);
- if (rmiClient == NULL) {
- perror("IoTRMICall: IoTSocketClient isn't initialized!");
- }
-}
-
-
-// Destructor
-IoTRMICall::~IoTRMICall() {
-
- // Clean up
- if (rmiUtil != NULL) {
-
- delete rmiUtil;
- rmiUtil = NULL;
- }
- if (rmiClient != NULL) {
-
- fflush(NULL);
- rmiClient->close();
- delete rmiClient;
- rmiClient = NULL;
- }
-}
-
-
-// Calls a method remotely by passing in parameters and getting a return object
-void* IoTRMICall::remoteCall(int objectId, int methodId, string retType, string paramCls[],
- void* paramObj[], int numParam, void* retObj) {
-
- // Critical section that is used by different objects
- lock_guard<mutex> guard(mtx);
- // Send input parameters
- int len = methodLength(paramCls, paramObj, numParam);
- char method[len];
- methodToBytes(objectId, methodId, paramCls, paramObj, method, numParam);
- // Send bytes
- fflush(NULL);
- rmiClient->sendBytes(method, len);
- fflush(NULL);
- // Receive return value and return it to caller
- if (retType.compare("void") == 0)
- // Just make it NULL if it's a void return
- retObj = NULL;
- else {
- int retLen = 0;
- char* retObjBytes = NULL;
- retObjBytes = rmiClient->receiveBytes(retObjBytes, &retLen);
- retObj = IoTRMIUtil::getParamObject(retObj, retType.c_str(), retObjBytes, retLen);
- // Delete received bytes object
- delete[] retObjBytes;
- }
-
- return retObj;
-}
-
-
-// Get a set of return objects (struct)
-void** IoTRMICall::getStructObjects(string retType[], int numRet, void* retObj[]) {
-
- // Critical section that is used by different objects
- lock_guard<mutex> guard(mtx);
- // Receive struct return value and return it to caller
- int retLen = 0;
- char* retObjBytes = NULL;
- // Return size of array of struct
- retObjBytes = rmiClient->receiveBytes(retObjBytes, &retLen);
- retObj = getReturnObjects(retObjBytes, retType, numRet, retObj);
- // Delete received bytes object
- delete[] retObjBytes;
-
- return retObj;
-}
-
-
-// Find the bytes length of a method
-int IoTRMICall::methodLength(string paramCls[], void* paramObj[], int numParam) {
-
- // Get byte arrays and calculate method bytes length
- // Start from the object Id + method Id...
- int methodLen = IoTRMIUtil::OBJECT_ID_LEN + IoTRMIUtil::METHOD_ID_LEN;
- for (int i = 0; i < numParam; i++) {
- // Find the parameter length
- int paramLen = rmiUtil->getTypeSize(paramCls[i]);
- if (paramLen == -1) { // Store the length of the field - indefinite length
- paramLen = rmiUtil->getVarTypeSize(paramCls[i], paramObj[i]);
- // Some space for param length, i.e. 32 bits for integer
- methodLen = methodLen + IoTRMIUtil::PARAM_LEN;
- }
- // Calculate methodLen
- methodLen = methodLen + paramLen;
- }
- return methodLen;
-}
-
-
-// Convert method and its parameters into bytes
-char* IoTRMICall::methodToBytes(int objectId, int methId, string paramCls[],
- void* paramObj[], char* method, int numParam) {
-
- // Get object Id in bytes
- char objId[IoTRMIUtil::OBJECT_ID_LEN];
- IoTRMIUtil::intToByteArray(objectId, objId);
- memcpy(method, objId, IoTRMIUtil::OBJECT_ID_LEN);
- int pos = IoTRMIUtil::OBJECT_ID_LEN;
- // Get method Id in bytes
- char methodId[IoTRMIUtil::METHOD_ID_LEN];
- IoTRMIUtil::intToByteArray(methId, methodId);
- memcpy(method + pos, methodId, IoTRMIUtil::METHOD_ID_LEN);
- pos = pos + IoTRMIUtil::METHOD_ID_LEN;
- // Get byte arrays and calculate method bytes length
- for (int i = 0; i < numParam; i++) {
- // Find the parameter length
- int paramLen = rmiUtil->getTypeSize(paramCls[i]);
- if (paramLen == -1) { // Store the length of the field - indefinite length
- paramLen = rmiUtil->getVarTypeSize(paramCls[i], paramObj[i]);
- // Write the parameter length
- char prmLenBytes[IoTRMIUtil::PARAM_LEN];
- IoTRMIUtil::intToByteArray(paramLen, prmLenBytes);
- memcpy(method + pos, prmLenBytes, IoTRMIUtil::PARAM_LEN);
- pos = pos + IoTRMIUtil::PARAM_LEN;
- }
- // Get array of bytes and put it in the array of array of bytes
- char objBytes[paramLen];
- IoTRMIUtil::getObjectBytes(objBytes, paramObj[i], paramCls[i].c_str());
- memcpy(method + pos, objBytes, paramLen);
- pos = pos + paramLen;
- }
-
- return method;
-}
-
-
-void** IoTRMICall::getReturnObjects(char* retBytes, string retCls[], int numRet, void* retObj[]) {
-
- // Byte scanning position
- int pos = 0;
- for (int i = 0; i < numRet; i++) {
- int retLen = rmiUtil->getTypeSize(retCls[i]);
- // Get the 32-bit field in the byte array to get the actual
- // length (this is a param with indefinite length)
- if (retLen == -1) {
- char bytRetLen[IoTRMIUtil::RETURN_LEN];
- memcpy(bytRetLen, retBytes + pos, IoTRMIUtil::RETURN_LEN);
- pos = pos + IoTRMIUtil::RETURN_LEN;
- int* retLenPtr = IoTRMIUtil::byteArrayToInt(&retLen, bytRetLen);
- retLen = *retLenPtr;
- }
- char retObjBytes[retLen];
- memcpy(retObjBytes, retBytes + pos, retLen);
- pos = pos + retLen;
- retObj[i] = IoTRMIUtil::getParamObject(retObj[i], retCls[i].c_str(), retObjBytes, retLen);
- }
-
- return retObj;
-}
-
-
-#endif
-
-
// Public methods
virtual void sendReturnObj(void* retObj, string type, char* methodBytes) = 0;
virtual void sendReturnObj(void* retObj[], string type[], int numRet, char* methodBytes) = 0;
- int returnLength(void* retObj[], string retCls[], int numRet);
- char* returnToBytes(void* retObj[], string retCls[], char* retBytes, int numRet);
- char* getMethodBytes();
- int getMethodLength();
- int getObjectIdFromMethod();
- static int getObjectId(char* packetBytes);
- static int getMethodId(char* packetBytes);
- static int getPacketType(char* packetBytes);
- void** getMethodParams(string paramCls[], int numParam, void* paramObj[], char* methodBytes);
- void registerSkeleton(int objectId, bool* methodReceived);
- void registerStub(int objectId, int methodId, bool* retValueReceived);
- int getObjectIdCounter();
- void setObjectIdCounter(int objIdCounter);
- void decrementObjectIdCounter();
-
- int methodLength(string paramCls[], void* paramObj[], int numParam);
- char* methodToBytes(int objectId, int methId, string paramCls[], void* paramObj[],
- char* method, int numParam);
+ int returnLength(void* retObj[], string retCls[], int numRet);
+ char* returnToBytes(void* retObj[], string retCls[], char* retBytes, int numRet);
+ char* getMethodBytes();
+ int getMethodLength();
+ int getObjectIdFromMethod();
+ static int getObjectId(char* packetBytes);
+ static int getMethodId(char* packetBytes);
+ static int getPacketType(char* packetBytes);
+ void** getMethodParams(string paramCls[], int numParam, void* paramObj[], char* methodBytes);
+ void registerSkeleton(int objectId, bool* methodReceived);
+ void registerStub(int objectId, int methodId, bool* retValueReceived);
+ int getObjectIdCounter();
+ void setObjectIdCounter(int objIdCounter);
+ void decrementObjectIdCounter();
+
+ int methodLength(string paramCls[], void* paramObj[], int numParam);
+ char* methodToBytes(int objectId, int methId, string paramCls[], void* paramObj[],
+ char* method, int numParam);
virtual void remoteCall(int objectId, int methodId, string paramCls[],
- void* paramObj[], int numParam) = 0;
- void* getReturnValue(string retType, void* retObj);
+ void* paramObj[], int numParam) = 0;
+ void* getReturnValue(string retType, void* retObj);
- void** getStructObjects(string retType[], int numRet, void* retObj[]);
- void** getReturnObjects(char* retBytes, string retCls[], int numRet, void* retObj[]);
+ void** getStructObjects(string retType[], int numRet, void* retObj[]);
+ void** getReturnObjects(char* retBytes, string retCls[], int numRet, void* retObj[]);
protected:
- IoTRMIUtil *rmiUtil;
- char* methodBytes;
- int methodLen;
- char* retValueBytes;
- int retValueLen;
+ IoTRMIUtil *rmiUtil;
+ char* methodBytes;
+ int methodLen;
+ char* retValueBytes;
+ int retValueLen;
ConcurrentLinkedListQueue methodQueue;
ConcurrentLinkedListQueue returnQueue;
- map<int,bool*> mapSkeletonId;
- map<string,bool*> mapStubId;
- int objectIdCounter = std::numeric_limits<int>::max();
+ map<int,bool*> mapSkeletonId;
+ map<string,bool*> mapStubId;
+ int objectIdCounter = std::numeric_limits<int>::max();
private:
// Private methods
void IoTRMIComm::wakeUpThreadOnMethodCall(IoTRMIComm* rmiComm) {
int methLen = 0;
- //cout << "Starting wakeUpThreadOnMethodCall()" << endl;
while(true) {
// Convert back to char*
char* queueHead = rmiComm->methodQueue.deQAndGetLength(&methLen);
void IoTRMIComm::wakeUpThreadOnReturnValue(IoTRMIComm* rmiComm) {
int retLen = 0;
- //cout << "Starting wakeUpThreadOnReturnValue()" << endl;
while(true) {
// Convert back to char*
char* queueHead = rmiComm->returnQueue.deQAndGetLength(&retLen);
void sendReturnObj(void* retObj, string type, char* methodBytes);
void sendReturnObj(void* retObj[], string type[], int numRet, char* methodBytes);
void remoteCall(int objectId, int methodId, string paramCls[], void* paramObj[], int numParam);
- //void waitForPackets();
- //void waitForPackets(IoTRMICommClient* rmiComm);
private:
IoTSocketClient *rmiClientSend;
rmiClientSend = new IoTSocketClient(_portRecv, _address, _rev, _bResult);
thread th1 (&IoTRMICommClient::waitForPackets, this, this);
th1.detach();
-
}
packetBytes = rmiClientRecv->receiveBytes(packetBytes, &packetLen);
fflush(NULL);
if (packetBytes != NULL) { // If there is method bytes
- //IoTRMIUtil::printBytes(packetBytes, packetLen, false);
- //packetBytesPtr = &packetBytes;
int packetType = getPacketType(packetBytes);
if (packetType == IoTRMIUtil::METHOD_TYPE) {
rmiComm->methodQueue.enqueue(packetBytes, packetLen);
void IoTRMICommServer::waitForConnectionOnServerRecv() {
- //cout << "Wait on connection ServerRecv!" << endl;
rmiServerRecv->connect();
- //cout << "Connected on connection ServerRecv!" << endl;
}
void IoTRMICommServer::waitForConnectionOnServerSend() {
- //cout << "Wait on connection ServerSend!" << endl;
rmiServerSend->connect();
- //cout << "Connected on connection ServerSend!" << endl;
}
char* packetBytes = NULL;
int packetLen = 0;
- //cout << "Starting waitForPacketsOnServer()" << endl;
while(true) {
fflush(NULL);
packetBytes = rmiComm->rmiServerRecv->receiveBytes(packetBytes, &packetLen);
fflush(NULL);
if (packetBytes != NULL) { // If there is method bytes
- //IoTRMIUtil::printBytes(packetBytes, packetLen, false);
int packetType = IoTRMIComm::getPacketType(packetBytes);
if (packetType == IoTRMIUtil::METHOD_TYPE) {
rmiComm->methodQueue.enqueue(packetBytes, packetLen);
IoTRMIUtil::getObjectBytes(retObjBytes, retObj, type.c_str());
memcpy(retAllObjBytes + headerLen, retObjBytes, retLen);
fflush(NULL);
- //IoTRMIUtil::printBytes(retAllObjBytes, headerLen+retLen, false);
rmiServerSend->sendBytes(retAllObjBytes, headerLen+retLen);
fflush(NULL);
}
+++ /dev/null
-#include <iostream>
-#include <string>
-#include "IoTRMIObject.hpp"
-
-using namespace std;
-
-int main(int argc, char *argv[])
-{
- int port = 5010;
- bool bResult = false;
- IoTRMIObject *ro = new IoTRMIObject(port, &bResult);
-
- int numRet = 3;
- string retCls[] = { "int", "string", "int" };
- int param1 = 1234;
- string param2 = "teststring";
- int param3 = 5432;
- void* retObj[] = { ¶m1, ¶m2, ¶m3 };
- ro->sendReturnObj(retObj, retCls, numRet);
-
- return 0;
-}
//~IoTRMIUtil();
// Helper functions
- static void printBytes(char* bytes, const int len, const bool hex);
- static int hashCode(string str);
+ static void printBytes(char* bytes, const int len, const bool hex);
+ static int hashCode(string str);
static char* getHashCodeBytes(string methodSign, char* bytes);
- int getTypeSize(string type);
- int getVarTypeSize(string type, void* paramObj);
- static int getArrStringLength(vector<string> arrString);
- static int getByteStringLength(vector<string> arrString);
+ int getTypeSize(string type);
+ int getVarTypeSize(string type, void* paramObj);
+ static int getArrStringLength(vector<string> arrString);
+ static int getByteStringLength(vector<string> arrString);
// Primitives to byte array
static char* byteToByteArray(char c, char* bytes);
std::vector<string> nonPrimCplus (IoTRMITypes::nonPrimitivesCplus,
IoTRMITypes::nonPrimitivesCplus + sizeof(IoTRMITypes::nonPrimitivesCplus)/sizeof(string));
-
// Write into maps
IoTRMITypes::arraysToMap(mapPrimitives, primJava, primCplus);
IoTRMITypes::arraysToMap(mapPrimitiveSizes, primJava, primSizes);
#include <sys/socket.h>
#include <sys/wait.h>
#include <unistd.h>
+#include <mutex>
#include "IoTRMIUtil.hpp"
IoTSocket(int iPort, bool* pResult);
~IoTSocket();
- bool close(); // Close the socket
- bool sendBytes(char* pVals, int _iLen); // Send a set of bytes
- char* receiveBytes(char* pVals, int* len); // Receive a set of bytes
+ bool close(); // Close the socket
+ bool sendBytes(char* pVals, int _iLen); // Send a set of bytes
+ char* receiveBytes(char* pVals, int* len); // Receive a set of bytes
protected:
- int m_iPort; // Port I'm listening on
- int m_iSock; // Socket connection
- struct sockaddr_in m_addrRemote; // Connector's address information
- double* m_pBuffer; // Reuse the same memory for buffer
+ int m_iPort; // Port I'm listening on
+ int m_iSock; // Socket connection
+ struct sockaddr_in m_addrRemote; // Connector's address information
+ double* m_pBuffer; // Reuse the same memory for buffer
private:
- bool receiveAck();
- bool sendAck();
+ bool receiveAck();
+ bool sendAck();
};
return false;
}
- //IoTRMIUtil::printBytes(size, 4, false);
-
if (send(m_iSock, (char *) pVals, iLen, 0) == -1) {
perror("IoTSocket: Send bytes error!");
return false;
// Critical section that is used by different objects
lock_guard<mutex> guard(recvBytesMutex);
- int i = 0;
- int j = 0;
- char* pTemp = NULL;
+ int i = 0;
+ int j = 0;
+ char* pTemp = NULL;
int iTotalBytes = 0;
int iNumBytes = 0;
- bool bEnd = false;
+ bool bEnd = false;
int iTotal = 0;
int iResult = 0;
iResult = recv(m_iSock, size, MSG_LEN_SIZE, 0);
iTotal += iResult;
}
+
if (iResult == -1) {
perror("IoTSocket: Receive size error!");
return NULL;
+++ /dev/null
-#include <iostream>
-#include <string>
-#include "IoTSocketClient.hpp"
-
-using namespace std;
-
-#define SIZE 10 /* how many items per packet */
-#define NUM_PACKS 3 /* number of times we'll do it */
-
-int main(int argc, char *argv[])
-{
- char D[SIZE];
-
- /* if no command line arguments passed, we'll default to
- these two port number */
- int port = 5010;
- int rev = 0;
- bool bResult = false;
-
- fflush(NULL);
- IoTSocketClient mylink(port, "127.0.0.1", rev, &bResult);
-
- if (!bResult)
- {
- printf("Failed to create Client object!\n");
- return 0;
- }
-
- printf("Client, made connection...\n");
- fflush(NULL);
-
- /* put some dummy data in our arrays */
-
- for (int i = 0; i < SIZE; i++)
- {
- D[i] = i;
- }
-
- for (int i = 0; i < NUM_PACKS; i++)
- {
- printf("Client, receiving bytes, iteration %d\n", i);
- fflush(NULL);
- mylink.receiveBytes(D);
- }
-
- char str[50];
- char* str2;
- fflush(NULL);
- str2 = mylink.receiveBytes(str);
- string s(str2);
- cout << "Received text: " << s << endl;
-
- printf("Client, closing connection...\n");
- fflush(NULL);
- mylink.close();
-
- printf("Client, done...\n");
- fflush(NULL);
- return 0;
-}
IoTSocket(iPort, pResult) {
struct hostent* he = NULL;
-
if (pResult)
*pResult = false;
-
if ((he = gethostbyname(pStrHost)) == NULL) {
-
perror("IoTSocketClient: Gethostbyname error!");
return;
}
-
if ((m_iSock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
perror("IoTSocketClient: Socket error!");
memset(&(m_addrRemote.sin_zero), 0, 8);
// Make socket client wait for socket server to be ready
- while (connect(m_iSock, (struct sockaddr *) &m_addrRemote, sizeof(struct sockaddr)) == -1) { }
+ if (connect(m_iSock, (struct sockaddr *) &m_addrRemote, sizeof(struct sockaddr)) == -1) {
+ perror("IoTSocketServer: Accept connection error!");
+ return;
+ }
// Send out request for reversed bits or not
char temp[1];
+++ /dev/null
-#include <iostream>
-#include <string>
-#include "IoTSocketServer.hpp"
-#include "IoTRMIUtil.hpp"
-
-using namespace std;
-
-
-#define SIZE 10 /* how many items per packet */
-#define NUM_PACKS 3 /* number of times we'll do it */
-
-int main(int argc, char *argv[])
-{
- char D[SIZE];
- bool bResult = false;
-
- /* if no command line arguments passed, we'll default to
- these two port number */
- int port = 5010;
-
- fflush(NULL);
-
- IoTSocketServer mylink(port, &bResult);
- if (!bResult)
- {
- printf("Failed to create Server object!\n");
- return 0;
- }
-
- /* put some dummy data in our arrays */
- for (int i = 0,j = 100; i < SIZE; i++, j--)
- {
- //D[i] = i;
- D[i] = j;
- }
- printf("Server, waiting for connection...\n");
- fflush(NULL);
- mylink.connect();
- printf("Server, got a connection...\n");
- fflush(NULL);
-
- char bytes[24];
- mylink.receiveBytes(bytes);
- cout << "Received bytes: ";
- IoTRMIUtil::printBytes(bytes, 24, false);
-
- printf("Server, closing connection...\n");
- fflush(NULL);
- mylink.close();
-
- printf("Server, done...\n");
- fflush(NULL);
- return 0;
-}
class IoTSocketServer final : public IoTSocket
{
- public:
+ public:
IoTSocketServer(int iPort, bool* pResult);
-
- bool connect(); // Accept a new connection
+ bool connect(); // Accept a new connection
protected:
- bool m_bReverse; // Am I reversing byte order or not?
- int m_iListen; // Descriptor we are listening on
- struct sockaddr_in m_addrMe; // My address information
+ bool m_bReverse; // Am I reversing byte order or not?
+ int m_iListen; // Descriptor we are listening on
+ struct sockaddr_in m_addrMe; // My address information
};
IoTSocket(iPort, pResult) {
m_iListen = -1;
-
if (pResult)
*pResult = false;
-
if ((m_iListen = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
perror("IoTSocketServer: Socket error!");
bool IoTSocketServer::connect()
{
socklen_t iSinSize = (socklen_t) sizeof(struct sockaddr_in);
-
if ((m_iSock = accept(m_iListen, (struct sockaddr *) &m_addrRemote, &iSinSize)) == -1)
{
perror("IoTSocketServer: Accept connection error!");
return false;
}
+
// The client sends us an int to indicate if we should
// be reversing byte order on this connection. The client
// is sending 0 or 1, so a reversed 0 still looks
iResult = recv(m_iSock, temp, 1, 0);
iTotal += iResult;
}
+
if (iResult == -1)
{
perror("IoTSocketServer: Receive data error!");
}
int iVal = temp[0];
-
if (iVal == 0)
m_bReverse = false;
else
m_bReverse = true;
-
+
return true;
}
+++ /dev/null
-#include <iostream>
-#include <string>
-#include <cstring>
-#include "IoTRMITypes.hpp"
-
-using namespace std;
-
-
-int main(int argc, char *argv[])
-{
- std::array<int,5> myints;
- std::cout << "size of myints: " << myints.size() << std::endl;
- std::cout << "sizeof(myints): " << sizeof(myints) << std::endl;
-
- int test[5] = { 0 };
- std::memcpy(myints.data(), test, 5);
-
- std::vector<int> test2 (test, test + sizeof(test)/sizeof(int));
-
- string test3[2] = { "test1", "test2" };
- std::vector<string> test4 (test3, test3 + sizeof(test3)/sizeof(string));
- std::cout << "vector[0]: " << test4[0] << std::endl;
-
- std::vector<string> primJava (IoTRMITypes::primitivesJava,
- IoTRMITypes::primitivesJava + sizeof(IoTRMITypes::primitivesJava)/sizeof(string));
- std::vector<string> primCplus (IoTRMITypes::primitivesCplus,
- IoTRMITypes::primitivesCplus + sizeof(IoTRMITypes::primitivesCplus)/sizeof(string));
-
- map<string,string> mymap;
- IoTRMITypes::arraysToMap(mymap, primJava, primCplus);
- for (std::map<string,string>::iterator it=mymap.begin(); it!=mymap.end(); ++it)
- std::cout << it->first << " => " << it->second << '\n';
-
- std::cout << "Result of find: " << mymap.find("Boolean")->second << std::endl;
-
- return 0;
-}
+++ /dev/null
-#ifndef _CALLBACK_HPP__
-#define _CALLBACK_HPP__
-
-#include <iostream>
-
-using namespace std;
-
-class CallBack : public CallBackInterface {
- public:
- CallBack(int _i);
-
- int printInt();
- void setInt(int _i);
- void needCallback(TestClassComplete* tc);
-
- private:
- int intA;
-};
-
-
-// Constructor
-CallBack::CallBack(int _i) {
-
- intA = _i;
-}
-
-
-int CallBack::printInt() {
-
- cout << "Integer: " << intA << endl;
- return intA;
-}
-
-
-void CallBack::setInt(int _i) {
-
- intA = _i;
-}
-
-void CallBack::needCallback(TestClassComplete* tc) {
-
- cout << endl << "Short from TestClass: " << tc->getShort(1234) << endl << endl;
-}
-
-#endif
-
+++ /dev/null
-#ifndef _TESTCLASS_HPP__
-#define _TESTCLASS_HPP__
-
-#include <iostream>
-#include <thread>
-#include <chrono>
-#include "TestClassInterface.hpp"
-#include "CallBackInterfaceWithCallBack.hpp"
-#include "Enum.hpp"
-#include "Struct.hpp"
-
-using namespace std;
-
-class TestClass : public TestClassInterface {
- public:
- TestClass();
- TestClass(int _int, float _float, string _string);
-
- char getByte(char in);
- short getShort(short in);
- int64_t getLong(int64_t in);
- float getFloat(float in);
- double getDouble(double in);
- bool getBoolean(bool in);
- char getChar(char in);
-
- vector<char> getByteArray(vector<char> in);
- vector<short> getShortArray(vector<short> in);
- vector<int64_t> getLongArray(vector<int64_t> in);
- vector<float> getFloatArray(vector<float> in);
- vector<double> getDoubleArray(vector<double> in);
- vector<bool> getBooleanArray(vector<bool> in);
- vector<char> getCharArray(vector<char> in);
-
- vector<char> getByteList(vector<char> in);
- vector<short> getShortList(vector<short> in);
- vector<int64_t> getLongList(vector<int64_t> in);
- vector<float> getFloatList(vector<float> in);
- vector<double> getDoubleList(vector<double> in);
- vector<bool> getBooleanList(vector<bool> in);
- vector<char> getCharList(vector<char> in);
-
- // Callbacks
- void registerCallback(CallBackInterfaceWithCallBack* _cb);
- void registerCallbackArray(vector<CallBackInterfaceWithCallBack*> _cb);
- void registerCallbackList(vector<CallBackInterfaceWithCallBack*> _cb);
- void registerCallbackComplex(int in, vector<CallBackInterfaceWithCallBack*> _cb, double db);
- int callBack();
- vector<Enum> handleCallbackEnum(vector<Enum> en, char c, vector<CallBackInterfaceWithCallBack*> _cb);
-
- // Enum
- Enum handleEnum(Enum en);
- vector<Enum> handleEnumArray(vector<Enum> vecEn);
- vector<Enum> handleEnumList(vector<Enum> vecEn);
- Enum handleEnumComplex(Enum en, int i, char c);
- vector<Enum> handleEnumComplex2(vector<Enum> en, int i, char c);
- vector<Enum> handleEnumTwo(vector<Enum> en1, vector<Enum> en2);
- vector<Enum> handleEnumThree(vector<Enum> en1, vector<Enum> en2, vector<Struct> str1, vector<Struct> str2);
-
- // Struct
- Struct handleStruct(Struct str);
- vector<Struct> handleStructArray(vector<Struct> vecStr);
- vector<Struct> handleStructList(vector<Struct> vecStr);
- Struct handleStructComplex(int in, char c, Struct str);
- vector<Struct> handleStructComplex2(int in, char c, vector<Struct> vecStr);
- vector<Struct> handleStructTwo(vector<Struct> str1, vector<Struct> str2);
- vector<Struct> handleStructThree(vector<Struct> str1, vector<Struct> str2, vector<Struct> str3);
-
- vector<Enum> handleEnumStruct(vector<Enum> en, vector<Struct> str, char c);
- vector<Enum> handleAll(vector<Enum> en, vector<Struct> str, char c, vector<CallBackInterfaceWithCallBack*> _cb);
- vector<Enum> handleAllTwo(vector<Enum> en1, vector<Enum> en2, vector<Struct> str1, vector<Struct> str2, char c,
- vector<CallBackInterfaceWithCallBack*> _cb1, vector<CallBackInterfaceWithCallBack*> _cb2);
-
- int getA();
- void setA(int _int);
- void setB(float _float);
- void setC(string _string);
- string sumArray(vector<string> newA);
- int setAndGetA(int newA);
- int setACAndGetA(string newC, int newA);
-
- private:
- int intA;
- float floatB;
- string stringC;
- vector<CallBackInterfaceWithCallBack*> cbvec;
-};
-
-
-TestClass::TestClass() {
-
- intA = 1;
- floatB = 2;
- stringC = "345";
- // cbvec doesn't need to be initialized again
-}
-
-
-TestClass::TestClass(int _int, float _float, string _string) {
-
- intA = _int;
- floatB = _float;
- stringC = _string;
- // cbvec doesn't need to be initialized again
-}
-
-
-void TestClass::registerCallbackArray(vector<CallBackInterfaceWithCallBack*> _cb) {
-
- for (CallBackInterfaceWithCallBack* cb : _cb) {
- cbvec.push_back(cb);
- cout << "Registering callback object in array!" << endl;
- }
-}
-
-
-void TestClass::registerCallbackList(vector<CallBackInterfaceWithCallBack*> _cb) {
-
- for (CallBackInterfaceWithCallBack* cb : _cb) {
- cbvec.push_back(cb);
- cout << "Registering callback object in list!" << endl;
- }
-}
-
-
-void TestClass::registerCallbackComplex(int in, vector<CallBackInterfaceWithCallBack*> _cb, double db) {
-
- for (CallBackInterfaceWithCallBack* cb : _cb) {
- cbvec.push_back(cb);
- cout << "Registering callback object in list!" << endl;
- }
-
- cout << "Integer: " << in << endl;
- cout << "Double: " << db << endl;
-}
-
-
-void TestClass::registerCallback(CallBackInterfaceWithCallBack* _cb) {
-
- cbvec.push_back(_cb);
- cout << "Registering callback object!" << endl;
-}
-
-
-int TestClass::callBack() {
-
- int sum = 0;
- for (CallBackInterfaceWithCallBack* cb : cbvec) {
- //cout << "Sum: " << sum << endl;
- sum = sum + cb->printInt();
- cb->needCallback(this);
- //cb->needCallback(this);
- TestClass* tc = new TestClass();
- cb->needCallback(tc);
- //cout << "Sum after: " << sum << endl;
- }
- cout << "About to return sum: " << sum << endl;
-
- return sum;
-}
-
-
-// Single variables
-char TestClass::getByte(char in) {
-
- return in;
-}
-
-
-short TestClass::getShort(short in) {
-
- return in;
-}
-
-
-int64_t TestClass::getLong(int64_t in) {
-
- return in;
-}
-
-
-float TestClass::getFloat(float in) {
-
- return in;
-}
-
-
-double TestClass::getDouble(double in) {
-
- return in;
-}
-
-
-bool TestClass::getBoolean(bool in) {
-
- return in;
-}
-
-
-char TestClass::getChar(char in) {
-
- return in;
-}
-
-
-// Arrays
-vector<char> TestClass::getByteArray(vector<char> in) {
-
- return in;
-}
-
-
-vector<short> TestClass::getShortArray(vector<short> in) {
-
- return in;
-}
-
-
-vector<int64_t> TestClass::getLongArray(vector<int64_t> in) {
-
- return in;
-}
-
-
-vector<float> TestClass::getFloatArray(vector<float> in) {
-
- return in;
-}
-
-
-vector<double> TestClass::getDoubleArray(vector<double> in) {
-
- return in;
-}
-
-
-vector<bool> TestClass::getBooleanArray(vector<bool> in) {
-
- return in;
-}
-
-
-vector<char> TestClass::getCharArray(vector<char> in) {
-
- return in;
-}
-
-// List
-vector<char> TestClass::getByteList(vector<char> in) {
-
- return in;
-}
-
-
-vector<short> TestClass::getShortList(vector<short> in) {
-
- return in;
-}
-
-
-vector<int64_t> TestClass::getLongList(vector<int64_t> in) {
-
- return in;
-}
-
-
-vector<float> TestClass::getFloatList(vector<float> in) {
-
- return in;
-}
-
-
-vector<double> TestClass::getDoubleList(vector<double> in) {
-
- return in;
-}
-
-
-vector<bool> TestClass::getBooleanList(vector<bool> in) {
-
- return in;
-}
-
-
-vector<char> TestClass::getCharList(vector<char> in) {
-
- return in;
-}
-
-
-int TestClass::getA() {
-
- return intA;
-}
-
-
-void TestClass::setA(int _int) {
-
- intA = _int;
-}
-
-
-void TestClass::setB(float _float) {
-
- floatB = _float;
-}
-
-
-void TestClass::setC(string _string) {
-
- stringC = _string;
-}
-
-
-// Enum
-Enum TestClass::handleEnum(Enum en) {
-
- cout << "Enum: " << en << endl;
-
- return en;
-}
-
-
-vector<Enum> TestClass::handleEnumArray(vector<Enum> vecEn) {
-
- for (Enum en : vecEn) {
- cout << "Enum: " << en << endl;
- }
-
- return vecEn;
-}
-
-
-vector<Enum> TestClass::handleEnumList(vector<Enum> vecEn) {
-
- for (Enum en : vecEn) {
- cout << "Enum: " << en << endl;
- }
-
- return vecEn;
-}
-
-
-Enum TestClass::handleEnumComplex(Enum en, int i, char c) {
-
- cout << "Enum: " << en << endl;
- cout << "Integer: " << i << endl;
- cout << "Char: " << c << endl;
-
- return en;
-}
-
-
-vector<Enum> TestClass::handleEnumComplex2(vector<Enum> vecEn, int in, char c) {
-
- for (Enum en : vecEn) {
- cout << "Enum: " << en << endl;
- }
- cout << "Integer: " << in << endl;
- cout << "Char: " << c << endl;
-
- return vecEn;
-}
-
-
-vector<Enum> TestClass::handleEnumTwo(vector<Enum> en1, vector<Enum> en2) {
-
- for (Enum en : en1) {
- cout << "Enum1: " << en << endl;
- }
- for (Enum en : en2) {
- cout << "Enum2: " << en << endl;
- }
-
- return en1;
-}
-
-
-vector<Enum> TestClass::handleEnumThree(vector<Enum> en1, vector<Enum> en2, vector<Struct> str1, vector<Struct> str2) {
-
- for (Enum en : en1) {
- cout << "Enum1: " << en << endl;
- }
- for (Enum en : en2) {
- cout << "Enum2: " << en << endl;
- }
-
- return en1;
-}
-
-
-
-// Struct
-Struct TestClass::handleStruct(Struct str) {
-
- cout << "Name: " << str.name << endl;
- cout << "Value: " << str.value << endl;
- cout << "Year: " << str.year << endl;
-
- Struct test;
- test.name = "Anonymous";
- test.value = 1.33;
- test.year = 2016;
- str = test;
-
- return str;
-}
-
-
-vector<Struct> TestClass::handleStructArray(vector<Struct> vecStr) {
-
- for (Struct str : vecStr) {
-
- cout << "Name: " << str.name << endl;
- cout << "Value: " << str.value << endl;
- cout << "Year: " << str.year << endl;
- }
- Struct test;
- test.name = "Anonymous";
- test.value = 1.33;
- test.year = 2016;
- vecStr.push_back(test);
-
- return vecStr;
-}
-
-
-vector<Struct> TestClass::handleStructList(vector<Struct> vecStr) {
-
- for (Struct str : vecStr) {
-
- cout << "Name: " << str.name << endl;
- cout << "Value: " << str.value << endl;
- cout << "Year: " << str.year << endl;
- }
- Struct test;
- test.name = "Trimananda";
- test.value = 1.33;
- test.year = 2016;
- vecStr.push_back(test);
-
- return vecStr;
-}
-
-
-vector<Struct> TestClass::handleStructTwo(vector<Struct> str1, vector<Struct> str2) {
-
- for (Struct str : str1) {
-
- cout << "Name: " << str.name << endl;
- cout << "Value: " << str.value << endl;
- cout << "Year: " << str.year << endl;
- }
-
- return str2;
-}
-
-
-vector<Struct> TestClass::handleStructThree(vector<Struct> str1, vector<Struct> str2, vector<Struct> str3) {
-
- for (Struct str : str1) {
-
- cout << "Name: " << str.name << endl;
- cout << "Value: " << str.value << endl;
- cout << "Year: " << str.year << endl;
- }
-
- return str2;
-}
-
-
-Struct TestClass::handleStructComplex(int in, char c, Struct str) {
-
- cout << "Name: " << str.name << endl;
- cout << "Value: " << str.value << endl;
- cout << "Year: " << str.year << endl;
-
- cout << "Integer: " << in << endl;
- cout << "Char: " << c << endl;
-
- Struct test;
- test.name = "Anonymous";
- test.value = 1.33;
- test.year = 2016;
- str = test;
-
- return str;
-}
-
-
-vector<Struct> TestClass::handleStructComplex2(int in, char c, vector<Struct> vecStr) {
-
- for (Struct str : vecStr) {
- cout << "Name: " << str.name << endl;
- cout << "Value: " << str.value << endl;
- cout << "Year: " << str.year << endl;
- }
-
- cout << "Integer: " << in << endl;
- cout << "Char: " << c << endl;
-
- return vecStr;
-}
-
-
-vector<Enum> TestClass::handleEnumStruct(vector<Enum> en, vector<Struct> str, char c) {
-
- for (Struct st : str) {
- cout << "Name: " << st.name << endl;
- cout << "Value: " << st.value << endl;
- cout << "Year: " << st.year << endl;
- }
-
- cout << "Char: " << c << endl;
-
- return en;
-}
-
-
-vector<Enum> TestClass::handleAll(vector<Enum> en, vector<Struct> str, char c, vector<CallBackInterfaceWithCallBack*> _cb) {
-
- for (CallBackInterfaceWithCallBack* cb : _cb) {
- cbvec.push_back(cb);
- cout << "Registering callback object in array!" << endl;
- }
-
- for (Struct st : str) {
- cout << "Name: " << st.name << endl;
- cout << "Value: " << st.value << endl;
- cout << "Year: " << st.year << endl;
- }
-
- cout << "Char: " << c << endl;
-
- return en;
-}
-
-
-vector<Enum> TestClass::handleAllTwo(vector<Enum> en1, vector<Enum> en2, vector<Struct> str1, vector<Struct> str2, char c,
- vector<CallBackInterfaceWithCallBack*> _cb1, vector<CallBackInterfaceWithCallBack*> _cb2) {
-
- for (CallBackInterfaceWithCallBack* cb : _cb1) {
- cbvec.push_back(cb);
- cout << "Registering callback object in array!" << endl;
- }
-
- for (Struct st : str1) {
- cout << "Name: " << st.name << endl;
- cout << "Value: " << st.value << endl;
- cout << "Year: " << st.year << endl;
- }
-
- cout << "Char: " << c << endl;
-
- return en1;
-}
-
-
-vector<Enum> TestClass::handleCallbackEnum(vector<Enum> en, char c, vector<CallBackInterfaceWithCallBack*> _cb) {
-
- for (CallBackInterfaceWithCallBack* cb : _cb) {
- cbvec.push_back(cb);
- cout << "Registering callback object in array!" << endl;
- }
-
- cout << "Char: " << c << endl;
-
- return en;
-}
-
-
-string TestClass::sumArray(vector<string> newA) {
-
- string sum = "";
- int len = newA.size();
- for(int c = 0; c < len; c++) {
- sum = sum + newA[c];
- }
- return sum;
-}
-
-
-int TestClass::setAndGetA(int newA) {
-
- intA = newA;
- return intA;
-}
-
-
-int TestClass::setACAndGetA(string newC, int newA) {
-
- stringC = newC;
- intA = newA;
- return intA;
-}
-
-#endif
-
+++ /dev/null
-#include <iostream>
-#include <string>
-#include "TestClassComplete_Stub.hpp"
-#include "CallBack.hpp"
-
-using namespace std;
-
-int main(int argc, char *argv[])
-{
-
- int port = 5010;
- const char* address = "localhost";
- //const char* address = "192.168.2.191"; // RPi2
- //const char* skeletonAddress = "128.195.136.170"; // dc-9.calit2.uci.edu
- const char* skeletonAddress = "128.195.204.132";
- const char* callbackAddress = "128.195.204.132"; // dw-2.eecs.uci.edu (this machine)
- //const char* skeletonAddress = "192.168.2.108"; // RPi1
- //const char* callbackAddress = "192.168.2.191"; // RPi2
- int rev = 0;
- bool bResult = false;
- vector<int> ports;
- ports.push_back(12345);
-
- TestClassComplete *tcStub = new TestClassComplete_Stub(port, skeletonAddress, callbackAddress, rev, &bResult, ports);
- /*cout << "==== ENUM ====" << endl;
- Enum en;
- en = APPLE;
- Enum res = tcStub->handleEnum(en);
- cout << "Return value: " << res << endl;
- Enum resComp = tcStub->handleEnumComplex(en, 23, 'c');
- cout << "Return value: " << resComp << endl;
- vector<Enum> vecEn;
- vecEn.push_back(APPLE);
- vecEn.push_back(ORANGE);
- vecEn.push_back(APPLE);
- vecEn.push_back(GRAPE);
- vector<Enum> vecRes = tcStub->handleEnumArray(vecEn);
- for (Enum en : vecRes) {
- cout << "Enum value: " << en << endl;
- }
- vector<Enum> vecRes2 = tcStub->handleEnumList(vecEn);
- for (Enum en : vecRes2) {
- cout << "Enum value: " << en << endl;
- }
- vector<Enum> vecRes3 = tcStub->handleEnumComplex2(vecEn, 23, 'c');
- for (Enum en : vecRes3) {
- cout << "Enum value: " << en << endl;
- }
-
-
- cout << "==== STRUCT ====" << endl;
- Struct str;
- str.name = "Rahmadi";
- str.value = 0.123;
- str.year = 2016;
- Struct resStr = tcStub->handleStruct(str);
- cout << "Name: " << resStr.name << endl;
- cout << "Value:" << resStr.value << endl;
- cout << "Year" << resStr.year << endl;
- Struct resStr2 = tcStub->handleStructComplex(23, 'c', str);
- cout << "Name: " << resStr2.name << endl;
- cout << "Value:" << resStr2.value << endl;
- cout << "Year" << resStr2.year << endl;
- Struct str2;
- str2.name = "Trimananda";
- str2.value = 0.124;
- str2.year = 2017;
- vector<Struct> vecStr;
- vecStr.push_back(str);
- vecStr.push_back(str2);
- vector<Struct> vecRetStr = tcStub->handleStructArray(vecStr);
- for (Struct st : vecRetStr) {
- cout << "Name: " << st.name << endl;
- cout << "Value: " << st.value << endl;
- cout << "Year: " << st.year << endl;
- }
- vector<Struct> vecRetStr2 = tcStub->handleStructList(vecStr);
- for (Struct st : vecRetStr2) {
- cout << "Name: " << st.name << endl;
- cout << "Value: " << st.value << endl;
- cout << "Year: " << st.year << endl;
- }
- vector<Struct> vecRetStr3 = tcStub->handleStructComplex2(23, 'c', vecStr);
- for (Struct st : vecRetStr3) {
- cout << "Name: " << st.name << endl;
- cout << "Value:" << st.value << endl;
- cout << "Year" << st.year << endl;
- }
- vector<Enum> vecRes4 = tcStub->handleEnumStruct(vecEn, vecStr, 'c');
- for (Enum en : vecRes4) {
- cout << "Enum value: " << en << endl;
- }*/
-
- cout << "==== CALLBACK ====" << endl;
- CallBackInterface *cbSingle = new CallBack(2354);
- tcStub->registerCallback(cbSingle);
- cout << "Return value from callback: " << tcStub->callBack() << endl;
- /*CallBackInterface *cb1 = new CallBack(23);
- CallBackInterface *cb2 = new CallBack(33);
- CallBackInterface *cb3 = new CallBack(43);
- vector<CallBackInterface*> cb;
- cb.push_back(cb1);
- cb.push_back(cb2);
- cb.push_back(cb3);
- tcStub->registerCallbackArray(cb);
- cout << "Return value from callback: " << tcStub->callBack() << endl;*/
- /*CallBackInterface *cb4 = new CallBack(53);
- CallBackInterface *cb5 = new CallBack(63);
- CallBackInterface *cb6 = new CallBack(73);
- vector<CallBackInterface*> cblist;
- cblist.push_back(cb4);
- cblist.push_back(cb5);
- cblist.push_back(cb6);*/
-// tcStub->registerCallbackList(cblist);
-// cout << "Return value from callback: " << tcStub->callBack() << endl;
-/* tcStub->registerCallbackComplex(23, cblist, 0.1234);
- cout << "Return value from callback: " << tcStub->callBack() << endl;
- vector<Enum> vecRes5 = tcStub->handleAll(vecEn, vecStr, 'c', cblist);
- for (Enum en : vecRes5) {
- cout << "Enum value: " << en << endl;
- }
-
- vector<Enum> vecRes6 = tcStub->handleCallbackEnum(vecEn, 'c', cblist);
- for (Enum en : vecRes6) {
- cout << "Enum value: " << en << endl;
- }*/
- //vector<Enum> vecRes7 = tcStub->handleAllTwo(vecEn, vecStr, vecStr, vecEn, 'c', cblist, cblist);
- /*vector<Enum> vecRes7 = tcStub->handleAllTwo(vecEn, vecEn, vecStr, vecStr, 'c', cblist, cblist);
- for (Enum en : vecRes7) {
- cout << "Enum value: " << en << endl;
- }
- vector<Enum> vecRes8 = tcStub->handleEnumTwo(vecEn, vecEn);
- for (Enum en : vecRes8) {
- cout << "Enum value: " << en << endl;
- }
- vector<Enum> vecRes9 = tcStub->handleEnumThree(vecEn, vecEn, vecStr, vecStr);
- for (Enum en : vecRes9) {
- cout << "Enum value: " << en << endl;
- }
- vector<Struct> vecRetStr2 = tcStub->handleStructTwo(vecStr, vecStr);
- for (Struct st : vecRetStr2) {
- cout << "Name: " << st.name << endl;
- cout << "Value: " << st.value << endl;
- cout << "Year: " << st.year << endl;
- }
- vector<Struct> vecRetStr3 = tcStub->handleStructThree(vecStr, vecStr, vecStr);
- for (Struct st : vecRetStr3) {
- cout << "Name: " << st.name << endl;
- cout << "Value: " << st.value << endl;
- cout << "Year: " << st.year << endl;
- }*/
-
- return 0;
-}
+++ /dev/null
-#include <iostream>
-#include <string>
-#include "TestClassComplete_Stub.hpp"
-#include "CallBack.hpp"
-
-#include "CallBackInterface_Skeleton.cpp"
-
-using namespace std;
-
-
-TestClassComplete_Stub::TestClassComplete_Stub(int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector<int> _ports) {
- callbackAddress = _callbackAddress;
- ports = _ports;
- rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev, _bResult);
- set0Allowed.insert(-9998);
- //thread th1 (&TestClassComplete_Stub::___initCallBack, this);
- //th1.detach();
- ___regCB();
-}
-
-TestClassComplete_Stub::TestClassComplete_Stub(IoTRMICall* _rmiCall, string _callbackAddress, int _objIdCnt, vector<int> _ports) {
- callbackAddress = _callbackAddress;
- rmiCall = _rmiCall;
- objIdCnt = _objIdCnt;
- set0Allowed.insert(-9998);
- //thread th1 (&TestClassComplete_Stub::___initCallBack, this);
- //th1.detach();
- ___regCB();
-}
-
-TestClassComplete_Stub::~TestClassComplete_Stub() {
- if (rmiCall != NULL) {
- delete rmiCall;
- rmiCall = NULL;
- }
- if (rmiObj != NULL) {
- delete rmiObj;
- rmiObj = NULL;
- }
- for(CallBackInterface* cb : vecCallbackObj) {
- delete cb;
- cb = NULL;
- }
-}
-
-void TestClassComplete_Stub::registerCallback(CallBackInterface* _cb) {
- //CallBackInterface_CallbackSkeleton* skel0 = new CallBackInterface_CallbackSkeleton(_cb, callbackAddress, objIdCnt++);
- CallBackInterface_Skeleton* skel0 = new CallBackInterface_Skeleton(_cb, callbackAddress, objIdCnt++);
- vecCallbackObj.push_back(skel0);
- int ___paramCB0 = 1;
- int methodId = 1;
- string retType = "void";
- int numParam = 1;
- string paramCls[] = { "int" };
- void* paramObj[] = { &___paramCB0 };
- void* retObj = NULL;
- rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
-}
-
-void TestClassComplete_Stub::___regCB() {
- int numParam = 3;
- int methodId = -9999;
- string retType = "void";
- string paramCls[] = { "int*", "String", "int" };
- int rev = 0;
- void* paramObj[] = { &ports, &callbackAddress, &rev };
- void* retObj = NULL;
- rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
-}
-
-short TestClassComplete_Stub::getShort(short in) {
- int methodId = 0;
- string retType = "short";
- int numParam = 1;
- string paramCls[] = { "short" };
- void* paramObj[] = { &in };
- short retVal = 0;
- void* retObj = &retVal;
- rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
- return retVal;
-}
-
-int TestClassComplete_Stub::callBack() {
- int methodId = 2;
- string retType = "int";
- int numParam = 0;
- string paramCls[] = { };
- void* paramObj[] = { };
- int retVal = 0;
- void* retObj = &retVal;
- rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
- return retVal;
-}
-
-
-int main(int argc, char *argv[])
-{
-
- int port = 5010;
- const char* address = "localhost";
- //const char* address = "192.168.2.191"; // RPi2
- //const char* skeletonAddress = "128.195.136.170"; // dc-9.calit2.uci.edu
- const char* skeletonAddress = "128.195.204.132";
- const char* callbackAddress = "128.195.204.132"; // dw-2.eecs.uci.edu (this machine)
- //const char* skeletonAddress = "192.168.2.108"; // RPi1
- //const char* callbackAddress = "192.168.2.191"; // RPi2
- int rev = 0;
- bool bResult = false;
- vector<int> ports;
- ports.push_back(12345);
- ports.push_back(22346);
- //ports.push_back(32344);
- //ports.push_back(43212);
-
- TestClassComplete *tcStub = new TestClassComplete_Stub(port, skeletonAddress, callbackAddress, rev, &bResult, ports);
- cout << "==== CALLBACK ====" << endl;
- CallBackInterface *cbSingle = new CallBack(2354);
- tcStub->registerCallback(cbSingle);
- cout << "Return value from callback: " << tcStub->callBack() << endl;
-
- return 0;
-}
+++ /dev/null
-#include <iostream>
-#include <string>
-#include "TestClassComplete_Stub.hpp"
-#include "CallBack.hpp"
-
-#include "CallBackInterface_Skeleton.cpp"
-
-using namespace std;
-
-
-TestClassComplete_Stub::TestClassComplete_Stub(int _portSend, int _portRecv, const char* _skeletonAddress, int _rev, bool* _bResult) {
- rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev, _bResult);
- rmiComm->registerStub(objectId, 0, &retValueReceived0);
- rmiComm->registerStub(objectId, 2, &retValueReceived2);
- IoTRMIUtil::mapStub->insert(make_pair(objectId, this));
-}
-
-TestClassComplete_Stub::TestClassComplete_Stub(IoTRMIComm* _rmiComm, int _objectId) {
- rmiComm = _rmiComm;
- objectId = _objectId;
- rmiComm->registerStub(objectId, 0, &retValueReceived0);
- rmiComm->registerStub(objectId, 2, &retValueReceived2);
-}
-
-TestClassComplete_Stub::~TestClassComplete_Stub() {
- if (rmiComm != NULL) {
- delete rmiComm;
- rmiComm = NULL;
- }
- for(CallBackInterface* cb : vecCallbackObj) {
- delete cb;
- cb = NULL;
- }
-}
-
-mutex mtxMethodExec1; // TODO: We probably need to correlate this always with class name, e.g. methodExecCallBackInterfaceWithCallBack
-void TestClassComplete_Stub::registerCallback(CallBackInterface* _cb) {
- lock_guard<mutex> guard(mtxMethodExec1);
- int objIdSent = 0;
- auto it = IoTRMIUtil::mapSkel->find(_cb);
- if (it == IoTRMIUtil::mapSkel->end()) { // Not in the map, so new object
- objIdSent = rmiComm->getObjectIdCounter();
- rmiComm->decrementObjectIdCounter();
- CallBackInterface_Skeleton* skel0 = new CallBackInterface_Skeleton(_cb, rmiComm, objIdSent);
- vecCallbackObj.push_back(skel0);
- IoTRMIUtil::mapSkel->insert(make_pair(_cb, skel0));
- IoTRMIUtil::mapSkelId->insert(make_pair(_cb, objIdSent));
- cout << "Create new skeleton for TestClass! ID=" << objIdSent << endl;
- thread th0 (&CallBackInterface_Skeleton::___waitRequestInvokeMethod, std::ref(skel0), std::ref(skel0));
- th0.detach();
- while(!skel0->didInitWaitInvoke());
- } else {
- auto itId = IoTRMIUtil::mapSkelId->find(_cb);
- objIdSent = itId->second;
- cout << "Skeleton exists for TestClass! ID=" << objIdSent << endl;
- }
-
- int ___paramCB0 = objIdSent;
- int methodId = 1;
- string retType = "void";
- int numParam = 1;
- string paramCls[] = { "int" };
- void* paramObj[] = { &___paramCB0 };
- void* retObj = NULL;
- rmiComm->remoteCall(objectId, methodId, paramCls, paramObj, numParam);
-}
-
-mutex mtxMethodExec0; // TODO: We probably need to correlate this always with class name, e.g. methodExecCallBackInterfaceWithCallBack
-short TestClassComplete_Stub::getShort(short in) {
- lock_guard<mutex> guard(mtxMethodExec0);
- cout << "getShort() is called!!!" << endl << endl;
- int methodId = 0;
- string retType = "short";
- int numParam = 1;
- string paramCls[] = { "short" };
- void* paramObj[] = { &in };
- short retVal = 0;
- void* retObj = &retVal;
- cout << "Calling remote call!" << endl;
- rmiComm->remoteCall(objectId, methodId, paramCls, paramObj, numParam);
- cout << "Finished calling remote call!" << endl;
- // Waiting for return value
- while(!retValueReceived0);
- rmiComm->getReturnValue(retType, retObj);
- //retValueReceived0.exchange(false);
- retValueReceived0 = false;
- didGetReturnBytes.exchange(true);
- cout << "Getting return value for getShort(): " << retVal << endl;
-
- return retVal;
-}
-
-mutex mtxMethodExec2; // TODO: We probably need to correlate this always with class name, e.g. methodExecCallBackInterfaceWithCallBack
-int TestClassComplete_Stub::callBack() {
- lock_guard<mutex> guard(mtxMethodExec2);
- int methodId = 2;
- string retType = "int";
- int numParam = 0;
- string paramCls[] = { };
- void* paramObj[] = { };
- int retVal = 0;
- void* retObj = &retVal;
- rmiComm->remoteCall(objectId, methodId, paramCls, paramObj, numParam);
- // Waiting for return value
- while(!retValueReceived2);
- rmiComm->getReturnValue(retType, retObj);
- //retValueReceived2.exchange(false);
- retValueReceived2 = false;
- didGetReturnBytes.exchange(true);
-
- cout << "Getting return value for callback(): " << retVal << endl;
-
- return retVal;
-}
-
-
-int main(int argc, char *argv[])
-{
-
- int portSend = 5000;
- int portRecv = 6000;
- const char* address = "localhost";
- //const char* address = "192.168.2.191"; // RPi2
- //const char* skeletonAddress = "128.195.136.163"; // dc-2.calit2.uci.edu
- const char* skeletonAddress = "128.195.204.132";
- const char* callbackAddress = "128.195.204.132"; // dw-2.eecs.uci.edu (this machine)
- //const char* skeletonAddress = "192.168.2.108"; // RPi1
- //const char* callbackAddress = "192.168.2.191"; // RPi2
- int rev = 0;
- bool bResult = false;
- //vector<int> ports;
- //ports.push_back(12345);
- //ports.push_back(22346);
- //ports.push_back(32344);
- //ports.push_back(43212);
-
- TestClassComplete *tcStub = new TestClassComplete_Stub(portSend, portRecv, skeletonAddress, rev, &bResult);
- vector<char> in;
- in.push_back(68);
- in.push_back(68);
- vector<char> result = tcStub->getByteArray(in);
- cout << "Test print: " << in[0] << endl;
-
- cout << "Getting return value from getShort(): " << tcStub->getShort(1234) << endl;
-/* //cout << "Getting return value from getShort(): " << tcStub->getShort(4321) << endl;
- //cout << "Getting return value from getShort(): " << tcStub->getShort(5678) << endl;
- cout << "==== CALLBACK ====" << endl;
- CallBackInterface *cbSingle = new CallBack(2354);
- tcStub->registerCallback(cbSingle);
- //tcStub->registerCallback(cbSingle);
- CallBackInterface *cbSingle1 = new CallBack(2646);
- tcStub->registerCallback(cbSingle1);
- CallBackInterface *cbSingle2 = new CallBack(2000);
- tcStub->registerCallback(cbSingle2);
- cout << "Return value from callback: " << tcStub->callBack() << endl;
- //cout << "Return value from callback: " << tcStub->callBack() << endl;
-
- // TODO: we need this while loop at the end to keep the threads running
- while(true);*/
-
- return 0;
-}
+++ /dev/null
-#include <iostream>
-#include <string>
-#include "TestClassInterface_Skeleton.hpp"
-#include "TestClass.hpp"
-
-#include "CallBackInterfaceWithCallBack_Stub.cpp"
-
-using namespace std;
-
-TestClassInterface_Skeleton::TestClassInterface_Skeleton(TestClassInterface *_mainObj, int _portSend, int _portRecv) {
- bool _bResult = false;
- mainObj = _mainObj;
- rmiComm = new IoTRMICommServer(_portSend, _portRecv, &_bResult);
- IoTRMIUtil::mapSkel->insert(make_pair(_mainObj, this));
- IoTRMIUtil::mapSkelId->insert(make_pair(_mainObj, objectId));
- rmiComm->registerSkeleton(objectId, &methodReceived);
- thread th1 (&TestClassInterface_Skeleton::___waitRequestInvokeMethod, this, this);
-// th1.detach();
- th1.join();
-}
-
-TestClassInterface_Skeleton::TestClassInterface_Skeleton(TestClassInterface *_mainObj, IoTRMIComm *_rmiComm, int _objectId) {
- bool _bResult = false;
- mainObj = _mainObj;
- rmiComm = _rmiComm;
- objectId = _objectId;
- rmiComm->registerSkeleton(objectId, &methodReceived);
-}
-
-TestClassInterface_Skeleton::~TestClassInterface_Skeleton() {
- if (rmiComm != NULL) {
- delete rmiComm;
- rmiComm = NULL;
- }
- for(CallBackInterfaceWithCallBack* cb : vecCallbackObj) {
- delete cb;
- cb = NULL;
- }
-}
-
-bool TestClassInterface_Skeleton::didInitWaitInvoke() {
-
- return didAlreadyInitWaitInvoke;
-}
-
-short TestClassInterface_Skeleton::getShort(short in) {
- return mainObj->getShort(in);
-}
-
-void TestClassInterface_Skeleton::registerCallback(CallBackInterfaceWithCallBack* _cb) {
- mainObj->registerCallback(_cb);
-}
-
-int TestClassInterface_Skeleton::callBack() {
- return mainObj->callBack();
-}
-
-void TestClassInterface_Skeleton::___getShort(TestClassInterface_Skeleton* skel) {
- char* localMethodBytes = new char[methodLen];
- memcpy(localMethodBytes, skel->methodBytes, methodLen);
- //cout << "Bytes inside getShort: " << endl;
- //IoTRMIUtil::printBytes(localMethodBytes, methodLen, false);
- didGetMethodBytes.exchange(true);
- string paramCls[] = { "short" };
- int numParam = 1;
- short in;
- void* paramObj[] = { &in };
- skel->rmiComm->getMethodParams(paramCls, numParam, paramObj, localMethodBytes);
- short retVal = getShort(in);
- cout << "Getting return value getShort(): " << retVal << endl;
- void* retObj = &retVal;
- skel->rmiComm->sendReturnObj(retObj, "short", localMethodBytes);
- cout << "Sent return value for getShort()" << endl;
- delete[] localMethodBytes;
-}
-
-void TestClassInterface_Skeleton::___registerCallback(TestClassInterface_Skeleton* skel) {
- char* localMethodBytes = new char[methodLen];
- memcpy(localMethodBytes, skel->methodBytes, methodLen);
- didGetMethodBytes.exchange(true);
- string paramCls[] = { "int" };
- int numParam = 1;
- int numStubs0 = 0;
- void* paramObj[] = { &numStubs0 };
- skel->rmiComm->getMethodParams(paramCls, numParam, paramObj, localMethodBytes);
- // Choosing the right stub
- int objIdRecv = numStubs0;
- CallBackInterfaceWithCallBack* stub0 = NULL;
- auto it = IoTRMIUtil::mapStub->find(objIdRecv);
- if (it == IoTRMIUtil::mapStub->end()) { // Not in the map, so new object
- stub0 = new CallBackInterfaceWithCallBack_Stub(rmiComm, objIdRecv);
- IoTRMIUtil::mapStub->insert(make_pair(objIdRecv, stub0));
- cout << "Create new stub for Callback! ID=" << objIdRecv << endl;
- rmiComm->setObjectIdCounter(objIdRecv);
- rmiComm->decrementObjectIdCounter();
- } else {
- stub0 = (CallBackInterfaceWithCallBack_Stub*) it->second;
- cout << "Stub exists for Callback! ID=" << objIdRecv << endl;
- }
- skel->vecCallbackObj.push_back(stub0);
- skel->registerCallback(stub0);
- delete[] localMethodBytes;
-}
-
-void TestClassInterface_Skeleton::___callBack(TestClassInterface_Skeleton* skel) {
- char* localMethodBytes = new char[methodLen];
- memcpy(localMethodBytes, skel->methodBytes, methodLen);
- didGetMethodBytes.exchange(true);
- string paramCls[] = { };
- int numParam = 0;
- void* paramObj[] = { };
- skel->rmiComm->getMethodParams(paramCls, numParam, paramObj, localMethodBytes);
- int retVal = callBack();
- void* retObj = &retVal;
- skel->rmiComm->sendReturnObj(retObj, "int", localMethodBytes);
- delete[] localMethodBytes;
-}
-
-void TestClassInterface_Skeleton::___waitRequestInvokeMethod(TestClassInterface_Skeleton* skel) {
- cout << "Running loop!" << endl;
- //didAlreadyInitWaitInvoke.exchange(true);
- skel->didAlreadyInitWaitInvoke = true;
- while (true) {
- if (!methodReceived)
- continue;
- skel->methodBytes = skel->rmiComm->getMethodBytes();
- skel->methodLen = skel->rmiComm->getMethodLength();
- cout << endl;
- // TODO: Get method length as well!!!
- //methodReceived.exchange(false);
- methodReceived = false;
- int _objectId = skel->rmiComm->getObjectId(skel->methodBytes);
- int methodId = skel->rmiComm->getMethodId(skel->methodBytes);
- if (_objectId == objectId) {
- if (skel->set0Allowed.find(methodId) == skel->set0Allowed.end()) {
- cerr << "Object with object Id: " << _objectId << " is not allowed to access method: " << methodId << endl;
- return;
- }
- }
- else
- continue;
- switch (methodId) {
- case 0: { thread th0 (&TestClassInterface_Skeleton::___getShort, std::ref(skel), skel); th0.detach(); break; }
- //___getShort(skel); break;
- case 1: { thread th1 (&TestClassInterface_Skeleton::___registerCallback, std::ref(skel), skel); th1.detach(); break; }
- //___registerCallback(skel); break;
- case 2: { thread th2 (&TestClassInterface_Skeleton::___callBack, std::ref(skel), skel); th2.detach(); break; }
- //___callBack(skel); break;
- default:
- cerr << "Method Id " << methodId << " not recognized!" << endl;
- return;
- }
- cout << "Out of switch statement!" << endl;
- }
-}
-
-
-
-int main(int argc, char *argv[])
-{
- // First argument is port number
- /*int port = atoi(argv[1]);
- int argv2 = atoi(argv[2]);
- float argv3 = atof(argv[3]);
- string argv4 = string(argv[4]);
-
- cout << port << endl;
- cout << argv2 << endl;
- cout << argv3 << endl;
- cout << argv4 << endl;*/
-
- int portSend = 5000;
- int portRecv = 6000;
- //TestClassInterface *tc = new TestClass(argv2, argv3, argv4);
- TestClassInterface *tc = new TestClass(123, 2.345, "test");
- //TestClassInterface *tc = new TestClassProfiling();
- TestClassInterface_Skeleton *tcSkel = new TestClassInterface_Skeleton(tc, portSend, portRecv);
-
- //delete tc;
- //delete tcSkel;
- return 0;
-}
+++ /dev/null
-#ifndef _TESTCLASS_HPP__
-#define _TESTCLASS_HPP__
-
-#include <iostream>
-#include <thread>
-#include <chrono>
-#include "TestClassInterface.hpp"
-#include "CallBackInterfaceWithCallBack.hpp"
-#include "Enum.hpp"
-#include "Struct.hpp"
-
-using namespace std;
-
-class TestClassProfiling : public TestClassInterface {
- public:
- TestClassProfiling();
-
- vector<char> getByteArray(vector<char> in);
-
-};
-
-
-TestClassProfiling::TestClassProfiling() {
-
-}
-
-// Arrays
-vector<char> TestClass::getByteArray(vector<char> in) {
-
- return in;
-}
-
-
-#endif
-
+++ /dev/null
-#include <iostream>
-#include <string>
-#include "TestClassInterface_Skeleton.hpp"
-#include "TestClass.hpp"
-
-using namespace std;
-
-int main(int argc, char *argv[])
-{
- TestClassInterface *tc;
- TestClassInterface_Skeleton *tcSkel;
-
- int port = 5010;
- //tc = new TestClass(3, 5.0, "7911");
- tc = new TestClassProfiling();
- string callbackAddress = "128.195.204.132";
- tcSkel = new TestClassInterface_Skeleton(tc, callbackAddress, port);
-
- delete tc;
- delete tcSkel;
- return 0;
-}
+++ /dev/null
-#include <iostream>
-#include <string>
-#include "TestClassComplete_Stub.hpp"
-#include "CallBack.hpp"
-
-using namespace std;
-
-int main(int argc, char *argv[])
-{
-
- int port = 5010;
- const char* address = "localhost";
- //const char* address = "128.195.136.170"; // dc-9.calit2.uci.edu
- int rev = 0;
- bool bResult = false;
- vector<int> ports;
- ports.push_back(12345);
-
- TestClassComplete *tcStub = new TestClassComplete_Stub(port, address, rev, &bResult, ports);
- cout << "==== SINGLE ====" << endl;
- cout << "Return value: " << tcStub->getByte(68) << endl;
- cout << "Return value: " << tcStub->getShort(1234) << endl;
- cout << "Return value: " << tcStub->getLong(12345678) << endl;
- cout << "Return value: " << tcStub->getFloat(12.345) << endl;
- 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;
- vector<char> in1;
- in1.push_back(68);
- in1.push_back(69);
- cout << "Return value: " << tcStub->getByteArray(in1)[0] << ", " << tcStub->getByteArray(in1)[1] << endl;
- vector<short> in2;
- in2.push_back(1234);
- in2.push_back(1235);
- cout << "Return value: " << tcStub->getShortArray(in2)[0] << ", " << tcStub->getShortArray(in2)[1] << endl;
- vector<int64_t> in3;
- in3.push_back(12345678);
- in3.push_back(12356782);
- cout << "Return value: " << tcStub->getLongArray(in3)[0] << ", " << tcStub->getLongArray(in3)[1] << endl;
- vector<float> in4;
- in4.push_back(12.345);
- in4.push_back(12.346);
- cout << "Return value: " << tcStub->getFloatArray(in4)[0] << ", " << tcStub->getFloatArray(in4)[1] << endl;
- vector<double> in5;
- in5.push_back(12345.678);
- in5.push_back(12345.543);
- cout << "Return value: " << tcStub->getDoubleArray(in5)[0] << ", " << tcStub->getDoubleArray(in5)[1] << endl;
- vector<bool> in6;
- in6.push_back(true);
- in6.push_back(false);
- cout << "Return value: " << tcStub->getBooleanArray(in6)[0] << ", " << tcStub->getBooleanArray(in6)[1] << endl;
- vector<char> in7;
- in7.push_back('c');
- in7.push_back('e');
- cout << "Return value: " << tcStub->getCharArray(in7)[0] << ", " << tcStub->getCharArray(in7)[1] << endl;
- cout << "==== VECTOR/LIST ====" << endl;
- vector<char> inl1;
- inl1.push_back(68);
- inl1.push_back(69);
- cout << "Return value: " << tcStub->getByteList(inl1)[0] << ", " << tcStub->getByteList(inl1)[1] << endl;
- vector<short> inl2;
- inl2.push_back(1234);
- inl2.push_back(1235);
- cout << "Return value: " << tcStub->getShortList(inl2)[0] << ", " << tcStub->getShortList(inl2)[1] << endl;
- vector<int64_t> inl3;
- inl3.push_back(12345678);
- inl3.push_back(12356782);
- cout << "Return value: " << tcStub->getLongList(inl3)[0] << ", " << tcStub->getLongList(inl3)[1] << endl;
- vector<float> inl4;
- inl4.push_back(12.345);
- inl4.push_back(12.346);
- cout << "Return value: " << tcStub->getFloatList(inl4)[0] << ", " << tcStub->getFloatList(inl4)[1] << endl;
- vector<double> inl5;
- inl5.push_back(12345.678);
- inl5.push_back(12345.543);
- cout << "Return value: " << tcStub->getDoubleList(inl5)[0] << ", " << tcStub->getDoubleList(inl5)[1] << endl;
- vector<bool> inl6;
- inl6.push_back(true);
- inl6.push_back(false);
- cout << "Return value: " << tcStub->getBooleanList(inl6)[0] << ", " << tcStub->getBooleanList(inl6)[1] << endl;
- vector<char> inl7;
- inl7.push_back('c');
- inl7.push_back('e');
- cout << "Return value: " << tcStub->getCharList(inl7)[0] << ", " << tcStub->getCharList(inl7)[1] << endl;
- cout << "==== ENUM ====" << endl;
- Enum en;
- en = APPLE;
- Enum res = tcStub->handleEnum(en);
- cout << "Return value: " << res << endl;
- vector<Enum> vecEn;
- vecEn.push_back(APPLE);
- vecEn.push_back(ORANGE);
- vecEn.push_back(APPLE);
- vecEn.push_back(GRAPE);
- vector<Enum> vecRes = tcStub->handleEnumArray(vecEn);
- for (Enum en : vecRes) {
- cout << "Enum value: " << en << endl;
- }
- vector<Enum> vecRes2 = tcStub->handleEnumList(vecEn);
- for (Enum en : vecRes2) {
- cout << "Enum value: " << en << endl;
- }
- cout << "==== STRUCT ====" << endl;
- Struct str;
- str.name = "Rahmadi";
- str.value = 0.123;
- str.year = 2016;
- Struct resStr = tcStub->handleStruct(str);
- cout << "Name: " << resStr.name << endl;
- cout << "Value:" << resStr.value << endl;
- cout << "Year" << resStr.year << endl;
- Struct str2;
- str2.name = "Trimananda";
- str2.value = 0.124;
- str2.year = 2017;
- vector<Struct> vecStr;
- vecStr.push_back(str);
- vecStr.push_back(str2);
- vector<Struct> vecRetStr = tcStub->handleStructArray(vecStr);
- for (Struct st : vecRetStr) {
- cout << "Name: " << st.name << endl;
- cout << "Value:" << st.value << endl;
- cout << "Year" << st.year << endl;
- }
- vector<Struct> vecRetStr2 = tcStub->handleStructList(vecStr);
- for (Struct st : vecRetStr2) {
- 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);
- cout << "Return value from callback: " << tcStub->callBack() << endl;
- CallBackInterface *cb1 = new CallBack(23);
- CallBackInterface *cb2 = new CallBack(33);
- CallBackInterface *cb3 = new CallBack(43);
- vector<CallBackInterface*> cb;
- cb.push_back(cb1);
- cb.push_back(cb2);
- cb.push_back(cb3);
- tcStub->registerCallbackArray(cb);
- cout << "Return value from callback: " << tcStub->callBack() << endl;
- CallBackInterface *cb4 = new CallBack(53);
- CallBackInterface *cb5 = new CallBack(63);
- CallBackInterface *cb6 = new CallBack(73);
- vector<CallBackInterface*> cblist;
- cblist.push_back(cb4);
- cblist.push_back(cb5);
- cblist.push_back(cb6);
- tcStub->registerCallbackList(cblist);
- cout << "Return value from callback: " << tcStub->callBack() << endl;
-
- cout << "==== OTHERS ====" << endl;
- cout << "Return value: " << tcStub->getA() << endl;
- cout << "Return value: " << tcStub->setAndGetA(123) << endl;
- cout << "Return value: " << tcStub->setACAndGetA("string", 123) << endl;
- vector<string> input;
- input.push_back("123");
- input.push_back("456");
- input.push_back("987");
-
- cout << "Return value: " << tcStub->sumArray(input) << endl;
-
- return 0;
-}
+++ /dev/null
-#ifndef _CALLBACK_HPP__
-#define _CALLBACK_HPP__
-
-#include <iostream>
-#include "CallBackInterface.hpp"
-
-using namespace std;
-
-class CallBack : public CallBackInterface {
- public:
- //CallBack();
- CallBack(int _i);
- //~CallBack();
-
- int printInt();
- void setInt(int _i);
-
- private:
- int intA;
-};
-
-
-// Constructor
-CallBack::CallBack(int _i) {
-
- intA = _i;
-}
-
-
-int CallBack::printInt() {
-
- cout << "Integer: " << intA << endl;
- return intA;
-}
-
-
-void CallBack::setInt(int _i) {
-
- intA = _i;
-}
-
-#endif
-
+++ /dev/null
-#ifndef _CALLBACKINTERFACE_HPP__
-#define _CALLBACKINTERFACE_HPP__
-
-#include <iostream>
-
-using namespace std;
-
-class CallBackInterface {
- public:
- virtual int printInt() = 0;
- virtual void setInt(int _i) = 0;
-};
-
-#endif
-
+++ /dev/null
-#ifndef _CALLBACK_CBSKELETON_HPP__
-#define _CALLBACK_CBSKELETON_HPP__
-
-#include <iostream>
-#include "CallBackInterface.hpp"
-#include "../IoTRMIObject.hpp"
-
-
-using namespace std;
-
-class CallBack_CBSkeleton : public CallBackInterface {
- public:
- CallBack_CBSkeleton(CallBackInterface* _cb, int _objectId);
- ~CallBack_CBSkeleton();
-
- void invokeMethod(IoTRMIObject* rmiObj);
- int printInt();
- void setInt(int _i);
-
- void ___printInt(IoTRMIObject* rmiObj);
- void ___setInt(IoTRMIObject* rmiObj);
-
- private:
- CallBackInterface *cb;
- int objectId = 0;
-};
-
-
-// Constructor
-CallBack_CBSkeleton::CallBack_CBSkeleton(CallBackInterface* _cb, int _objectId) {
-
- cb = _cb;
- objectId = _objectId;
-}
-
-
-CallBack_CBSkeleton::~CallBack_CBSkeleton() {
-
-}
-
-
-int CallBack_CBSkeleton::printInt() {
-
- return cb->printInt();
-}
-
-
-void CallBack_CBSkeleton::___printInt(IoTRMIObject* rmiObj) {
-
- string paramCls[] = { };
- int numParam = 0;
- void* paramObj[] = { };
- rmiObj->getMethodParams(paramCls, numParam, paramObj);
- int retVal = printInt();
- void* retObj = &retVal;
- rmiObj->sendReturnObj(retObj, "int");
-}
-
-
-void CallBack_CBSkeleton::setInt(int _i) {
-
- cb->setInt(_i);
-}
-
-
-void CallBack_CBSkeleton::___setInt(IoTRMIObject* rmiObj) {
-
- string paramCls[] = { "int" };
- int numParam = 1;
- int param1 = 1;
- void* paramObj[] = { ¶m1 };
- rmiObj->getMethodParams(paramCls, numParam, paramObj);
- setInt(param1);
-}
-
-
-void CallBack_CBSkeleton::invokeMethod(IoTRMIObject* rmiObj) {
-
- int methodId = rmiObj->getMethodId();
-
- switch (methodId) {
- case 0 : ___printInt(rmiObj); break;
- case 1 : ___setInt(rmiObj); break;
- default:
- string error = "Method Id not recognized!";
- throw error;
- }
-}
-
-
-#endif
-
+++ /dev/null
-#ifndef _CALLBACK_CBSTUB_HPP__
-#define _CALLBACK_CBSTUB_HPP__
-
-#include <iostream>
-#include "CallBackInterface.hpp"
-#include "../IoTRMICall.hpp"
-
-using namespace std;
-
-class CallBack_CBStub : public CallBackInterface {
- public:
- CallBack_CBStub();
- CallBack_CBStub(IoTRMICall* _rmiCall, int _objectId);
- ~CallBack_CBStub();
-
- int printInt();
- void setInt(int _i);
-
- private:
-
- IoTRMICall *rmiCall;
- int objectId = 0; // Default value is 0
-};
-
-
-// Constructor
-CallBack_CBStub::CallBack_CBStub() {
-
- rmiCall = NULL;
-}
-
-
-CallBack_CBStub::CallBack_CBStub(IoTRMICall* _rmiCall, int _objectId) {
-
- objectId = _objectId;
- rmiCall = _rmiCall;
-}
-
-
-CallBack_CBStub::~CallBack_CBStub() {
-
- if (rmiCall != NULL) {
- delete rmiCall;
- rmiCall = NULL;
- }
-}
-
-
-int CallBack_CBStub::printInt() {
-
- cout << "Got here in printInt()" << endl;
- int numParam = 0;
- int methodId = 0;
- string retType = "int";
- string paramCls[] = { };
- void* paramObj[] = { };
- int retVal = 0;
- void* retObj = &retVal;
- rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
- return retVal;
-}
-
-
-void CallBack_CBStub::setInt(int _i) {
-
- int numParam = 1;
- int methodId = 1;
- string retType = "void";
- string paramCls[] = { "int" };
- void* paramObj[] = { &_i };
- void* retObj = NULL;
- rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
-}
-
-#endif
-
+++ /dev/null
-#include <iostream>
-#include <string>
-#include "CallBack_Skeleton.hpp"
-
-using namespace std;
-
-int main(int argc, char *argv[])
-{
-
- int port = 5010;
- CallBackInterface *cb = new CallBack(23);
- CallBack_Skeleton *cbSkel = new CallBack_Skeleton(cb, port);
- //cbSkel->waitRequestInvokeMethod();
-
- delete cb;
- delete cbSkel;
- return 0;
-}
+++ /dev/null
-#ifndef _CALLBACK_SKELETON_HPP__
-#define _CALLBACK_SKELETON_HPP__
-
-#include <iostream>
-#include "../IoTRMIObject.hpp"
-#include "CallBack.hpp"
-
-using namespace std;
-
-class CallBack_Skeleton : public CallBackInterface {
- public:
- CallBack_Skeleton(CallBackInterface* _cb, int _port);
- ~CallBack_Skeleton();
-
- void ___waitRequestInvokeMethod();
- int printInt();
- void setInt(int _i);
-
- void ___printInt();
- void ___setInt();
-
- private:
- CallBackInterface *cb;
- IoTRMIObject *rmiObj;
-};
-
-
-// Constructor
-CallBack_Skeleton::CallBack_Skeleton(CallBackInterface* _cb, int _port) {
-
- bool _bResult = false;
- cb = _cb;
- rmiObj = new IoTRMIObject(_port, &_bResult);
- ___waitRequestInvokeMethod();
-}
-
-
-CallBack_Skeleton::~CallBack_Skeleton() {
-
- if (rmiObj != NULL) {
- delete rmiObj;
- rmiObj = NULL;
- }
-}
-
-
-int CallBack_Skeleton::printInt() {
-
- return cb->printInt();
-}
-
-
-void CallBack_Skeleton::___printInt() {
-
- string paramCls[] = { };
- int numParam = 0;
- void* paramObj[] = { };
- rmiObj->getMethodParams(paramCls, numParam, paramObj);
- int retVal = printInt();
- void* retObj = &retVal;
- rmiObj->sendReturnObj(retObj, "int");
-}
-
-
-void CallBack_Skeleton::setInt(int _i) {
-
- cb->setInt(_i);
-}
-
-
-void CallBack_Skeleton::___setInt() {
-
- string paramCls[] = { "int" };
- int numParam = 1;
- int param1 = 1;
- void* paramObj[] = { ¶m1 };
- rmiObj->getMethodParams(paramCls, numParam, paramObj);
- setInt(param1);
-}
-
-
-void CallBack_Skeleton::___waitRequestInvokeMethod() {
-
- // Loop continuously waiting for incoming bytes
- while (true) {
-
- rmiObj->getMethodBytes();
- int methodId = rmiObj->getMethodId();
-
- switch (methodId) {
- case 0 : ___printInt(); break;
- case 1 : ___setInt(); break;
- default:
- string error = "Method Id not recognized!";
- throw error;
- }
- }
-}
-
-
-#endif
-
+++ /dev/null
-#include <iostream>
-#include <string>
-#include "CallBack_Stub.hpp"
-
-using namespace std;
-
-int main(int argc, char *argv[])
-{
-
- int port = 5010;
- const char* address = "localhost";
- int rev = 0;
- bool bResult = false;
-
- CallBackInterface *cbStub = new CallBack_Stub(port, address, rev, &bResult);
- cout << "Return value: " << cbStub->printInt() << endl;
- cbStub->setInt(123);
- cout << "Return value: " << cbStub->printInt() << endl;
-
- delete cbStub;
-
- return 0;
-}
+++ /dev/null
-#ifndef _CALLBACK_STUB_HPP__
-#define _CALLBACK_STUB_HPP__
-
-#include <iostream>
-#include "CallBackInterface.hpp"
-#include "../IoTRMICall.hpp"
-
-using namespace std;
-
-class CallBack_Stub : public CallBackInterface {
- public:
- CallBack_Stub();
- CallBack_Stub(int _port, const char* _address, int _rev, bool* _bResult);
- ~CallBack_Stub();
-
- int printInt();
- void setInt(int _i);
-
- private:
-
- IoTRMICall *rmiCall;
- string address;
- int objectId = 0; // Default value is 0
-};
-
-
-// Constructor
-CallBack_Stub::CallBack_Stub() {
-
- address = "";
- rmiCall = NULL;
-}
-
-
-CallBack_Stub::CallBack_Stub(int _port, const char* _address, int _rev, bool* _bResult) {
-
- address = _address;
- rmiCall = new IoTRMICall(_port, _address, _rev, _bResult);
-}
-
-
-CallBack_Stub::~CallBack_Stub() {
-
- if (rmiCall != NULL) {
- delete rmiCall;
- rmiCall = NULL;
- }
-}
-
-
-int CallBack_Stub::printInt() {
-
- int numParam = 0;
- int methodId = 0;
- string retType = "int";
- string paramCls[] = { };
- void* paramObj[] = { };
- int retVal = 0;
- void* retObj = &retVal;
- rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
- return retVal;
-}
-
-
-void CallBack_Stub::setInt(int _i) {
-
- int numParam = 1;
- int methodId = 1;
- string retType = "void";
- string paramCls[] = { "int" };
- void* paramObj[] = { &_i };
- void* retObj = NULL;
- rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
-}
-
-#endif
+++ /dev/null
-#include <iostream>
-#include <vector>
-#include "EnumC.hpp"
-
-int main(int argc, char *argv[]) {
-
- // Enum to integer
- EnumC en = APPLE;
- int enum1 = (int) en;
- cout << "Enum 1: " << enum1 << endl;
- EnumC en2 = ORANGE;
- int enum2 = (int) en2;
- cout << "Enum 2: " << enum2 << endl;
- EnumC en3 = GRAPE;
- int enum3 = (int) en3;
- cout << "Enum 3: " << enum3 << endl;
-
- // Integer to enum
- cout << "Enum 1: " << (EnumC) enum1 << endl;
- cout << "Enum 2: " << (EnumC) enum2 << endl;
- cout << "Enum 3: " << (EnumC) enum3 << endl;
-
- return 0;
-}
+++ /dev/null
-#ifndef _ENUMC_HPP__
-#define _ENUMC_HPP__
-
-using namespace std;
-
-enum EnumC {
- APPLE,
- ORANGE,
- GRAPE
-} enumC;
-
-/*enum EnumD {
- APPLE,
- ORANGE,
- GRAPE
-};*/
-
-#endif
-
+++ /dev/null
-#include <iostream>
-#include <vector>
-#include "StructC.hpp"
-
-int main(int argc, char *argv[]) {
-
- data testdata;
- testdata.name = "Rahmadi";
- testdata.value = 0.123;
- testdata.year = 2016;
-
- /*cout << "Name: " << testdata.name << endl;
- cout << "Value: " << testdata.value << endl;
- cout << "Year: " << testdata.year << endl;*/
-
- vector<data> dataset;
- data testdata2;
- testdata2.name = "Trimananda";
- testdata2.value = 0.223;
- testdata2.year = 2017;
-
- dataset.push_back(testdata);
- dataset.push_back(testdata2);
-
- for (data dat : dataset) {
-
- cout << "Name: " << dat.name << endl;
- cout << "Value: " << dat.value << endl;
- cout << "Year: " << dat.year << endl;
- }
-
- return 0;
-}
+++ /dev/null
-#ifndef _STRUCTC_HPP__
-#define _STRUCTC_HPP__
-
-using namespace std;
-
-struct data {
- string name;
- float value;
- int year;
-};
-
-#endif
-
+++ /dev/null
-#include <iostream>
-#include <map>
-#include <string>
-#include <chrono>
-#include <thread>
-#include <mutex>
-
-std::map<std::string, std::string> g_pages;
-std::mutex g_pages_mutex;
-
-void save_page(const std::string &url)
-{
- // simulate a long page fetch
- std::this_thread::sleep_for(std::chrono::seconds(2));
- std::string result = "fake content";
-
- std::lock_guard<std::mutex> guard(g_pages_mutex);
- g_pages[url] = result;
-}
-
-int main()
-{
- std::thread t1(save_page, "http://foo");
- std::thread t2(save_page, "http://bar");
- t1.join();
- t2.join();
-
- // safe to access g_pages without lock now, as the threads are joined
- for (const auto &pair : g_pages) {
- std::cout << pair.first << " => " << pair.second << '\n';
- }
-}
\ No newline at end of file
+++ /dev/null
-// mutex example
-#include <iostream> // std::cout
-#include <thread> // std::thread
-#include <mutex> // std::mutex
-
-std::mutex mtx; // mutex for critical section
-
-void print_block (int n, char c) {
- // critical section (exclusive access to std::cout signaled by locking mtx):
- mtx.lock();
- for (int i=0; i<n; ++i) { std::cout << c; }
- std::cout << '\n';
- mtx.unlock();
-}
-
-int main ()
-{
- std::thread th1 (print_block,50,'*');
- std::thread th2 (print_block,50,'$');
-
- th1.join();
- th2.join();
-
- return 0;
-}
\ No newline at end of file
+++ /dev/null
-#include <iostream>
-#include <string>
-#include "TestClass.hpp"
-#include "CallBack.hpp"
-
-using namespace std;
-
-int main(int argc, char *argv[])
-{
-
- TestClassInterface *tc = new TestClass();
- cout << "Return value: " << tc->setAndGetA(123) << endl;
- cout << "Return value: " << tc->setACAndGetA("string", 123) << endl;
- vector<string> input;
- input.push_back("123");
- input.push_back("456");
- input.push_back("987");
- /*vector<int> input;
- input.push_back(123);
- input.push_back(456);
- input.push_back(987);*/
-
- cout << "Return value: " << tc->sumArray(input) << endl;
- delete tc;
-
- vector<CallBackInterface*> test;
- CallBackInterface *cb1 = new CallBack(12);
- CallBackInterface *cb2 = new CallBack(22);
- CallBackInterface *cb3 = new CallBack(32);
- test.push_back(cb1);
- test.push_back(cb2);
- test.push_back(cb3);
- for (CallBackInterface *cb : test) {
- cout << "Test print: " << cb->printInt() << endl;
- }
-
- delete cb1;
- delete cb2;
- delete cb3;
-
- return 0;
-}
+++ /dev/null
-#ifndef _TESTCLASS_HPP__
-#define _TESTCLASS_HPP__
-
-#include <iostream>
-#include <thread>
-#include <chrono>
-#include "TestClassInterface.hpp"
-#include "StructC.hpp"
-
-using namespace std;
-
-class TestClass : public TestClassInterface {
- public:
- TestClass();
- TestClass(int _int, float _float, string _string);
- //~TestClass();
-
- void setA(int _int);
- void setB(float _float);
- void setC(string _string);
- string sumArray(vector<string> newA);
- //int64_t sumArray(vector<int> newA);
- int setAndGetA(int newA);
- int setACAndGetA(string newC, int newA);
- void registerCallback(CallBackInterface* _cb);
- void registerCallback(vector<CallBackInterface*> _cb);
- int callBack();
- vector<data> handleStruct(vector<data> vecData);
- vector<EnumC> handleEnum(vector<EnumC> vecEn);
-
- void thread1();
- void thread2();
-
- private:
- int intA;
- float floatB;
- string stringC;
- CallBackInterface *cb;
- vector<CallBackInterface*> cbvec;
-
-};
-
-
-TestClass::TestClass() {
-
- intA = 1;
- floatB = 2;
- stringC = "345";
- cb = NULL;
- // cbvec doesn't need to be initialized again
-}
-
-
-TestClass::TestClass(int _int, float _float, string _string) {
-
- intA = _int;
- floatB = _float;
- stringC = _string;
- cb = NULL;
- // cbvec doesn't need to be initialized again
-}
-
-
-void TestClass::setA(int _int) {
-
- intA = _int;
-}
-
-
-void TestClass::setB(float _float) {
-
- floatB = _float;
-}
-
-
-void TestClass::setC(string _string) {
-
- stringC = _string;
-}
-
-
-string TestClass::sumArray(vector<string> newA) {
-
- string sum = "";
- int len = newA.size();
- for(int c = 0; c < len; c++) {
- sum = sum + newA[c];
- }
- return sum;
-}
-
-
-/*int64_t TestClass::sumArray(vector<int> newA) {
-
- int64_t sum = 0;
- int len = newA.size();
- for(int c = 0; c < len; c++) {
- sum = sum + newA[c];
- }
- return sum;
-}*/
-
-
-int TestClass::setAndGetA(int newA) {
-
- intA = newA;
- return intA;
-}
-
-
-int TestClass::setACAndGetA(string newC, int newA) {
-
- stringC = newC;
- intA = newA;
- return intA;
-}
-
-
-void TestClass::registerCallback(CallBackInterface* _cb) {
-
- cb = _cb;
-}
-
-
-void TestClass::registerCallback(vector<CallBackInterface*> _cb) {
-
- for (CallBackInterface* cb : _cb) {
- cbvec.push_back(cb);
- cout << "Registering callback object!" << endl;
- }
-}
-
-
-vector<data> TestClass::handleStruct(vector<data> vecData) {
-
- for (data dat : vecData) {
-
- cout << "Name: " << dat.name << endl;
- cout << "Value: " << dat.value << endl;
- cout << "Year: " << dat.year << endl;
- }
- data newData;
- newData.name = "Anonymous";
- newData.value = 1.33;
- newData.year = 2016;
- vecData.push_back(newData);
-
- return vecData;
-}
-
-
-vector<EnumC> TestClass::handleEnum(vector<EnumC> vecEn) {
-
- for (EnumC en : vecEn) {
- cout << "Enum: " << en << endl;
- }
-
- return vecEn;
-}
-
-
-//int TestClass::callBack() {
-// return cb.printInt();
-//}
-
-void TestClass::thread1() {
-
- CallBackInterface* cb = cbvec[0];
- for(int i = 0; i < 10; i++) {
- cb->printInt();
- this_thread::sleep_for(chrono::seconds(1));
- }
-}
-
-void TestClass::thread2() {
-
- CallBackInterface* cb = cbvec[1];
- for(int i = 0; i < 10; i++) {
- cb->printInt();
- this_thread::sleep_for(chrono::seconds(1));
- }
-}
-
-int TestClass::callBack() {
-
- int sum = 0;
- for (CallBackInterface* cb : cbvec) {
- sum = sum + cb->printInt();
- }
-
- return sum;
-/* thread th1 (&TestClass::thread1, this);
- thread th2 (&TestClass::thread2, this);
-
- th1.join();
- th2.join();
-
- return 1;*/
-}
-
-#endif
-
+++ /dev/null
-#ifndef _TESTCLASSINTERFACE_HPP__
-#define _TESTCLASSINTERFACE_HPP__
-
-#include <iostream>
-#include <vector>
-#include "CallBackInterface.hpp"
-#include "StructC.hpp"
-#include "EnumC.hpp"
-
-using namespace std;
-
-class TestClassInterface {
- public:
- virtual void setA(int _int) = 0;
- virtual void setB(float _float) = 0;
- virtual void setC(string _string) = 0;
- virtual string sumArray(vector<string> newA) = 0;
- //virtual int64_t sumArray(vector<int> newA) = 0;
- virtual int setAndGetA(int newA) = 0;
- virtual int setACAndGetA(string newC, int newA) = 0;
- virtual void registerCallback(CallBackInterface* _cb) = 0;
- virtual void registerCallback(vector<CallBackInterface*> _cb) = 0;
- virtual int callBack() = 0;
- virtual vector<data> handleStruct(vector<data> vecData) = 0;
- virtual vector<EnumC> handleEnum(vector<EnumC> vecEn) = 0;
-};
-
-#endif
-
+++ /dev/null
-#include <iostream>
-#include <string>
-#include "TestClass_Skeleton.hpp"
-#include "TestClass.hpp"
-
-using namespace std;
-
-int main(int argc, char *argv[])
-{
- TestClassInterface *tc;
- TestClass_Skeleton *tcSkel;
- try {
- int port = 5010;
- tc = new TestClass(3, 5.0, "7911");
- tcSkel = new TestClass_Skeleton(tc, port);
- } catch(const exception&) {
- return EXIT_FAILURE;
- }
- //tcSkel->waitRequestInvokeMethod();
-
- delete tc;
- delete tcSkel;
- return 0;
-}
+++ /dev/null
-#ifndef _TESTCLASS_SKELETON_HPP__
-#define _TESTCLASS_SKELETON_HPP__
-
-#include <iostream>
-#include <exception>
-#include <set>
-#include "../IoTRMIObject.hpp"
-#include "../IoTRMICall.hpp"
-#include "CallBack_CBStub.hpp"
-#include "TestClassInterface.hpp"
-
-using namespace std;
-
-class TestClass_Skeleton : public TestClassInterface {
- public:
- TestClass_Skeleton(TestClassInterface* _tc, int _port);
- ~TestClass_Skeleton();
-
- void ___waitRequestInvokeMethod();
- void setA(int _int);
- void setB(float _float);
- void setC(string _string);
- string sumArray(vector<string> newA);
- //int64_t sumArray(vector<int> newA);
- int setAndGetA(int newA);
- int setACAndGetA(string newC, int newA);
- void registerCallback(CallBackInterface* _cb);
- void registerCallback(vector<CallBackInterface*> _cb);
- int callBack();
- vector<data> handleStruct(vector<data> vecData);
- vector<EnumC> handleEnum(vector<EnumC> vecEn);
-
- void ___setA();
- void ___setB();
- void ___setC();
- void ___sumArray();
- //int64_t ____sumArray();
- void ___setAndGetA();
- void ___setACAndGetA();
- void ___registerCallback();
- void ____registerCallback();
- // For array of callbacks
- void ___regCB();
- void ___callBack();
- // For array of structs
- int ___structSize();
- void ___handleStruct(int structsize1);
- int ___enumSize();
- void ___handleEnum(int enumsize1);
-
- private:
- TestClassInterface *tc;
- IoTRMIObject *rmiObj;
- // Permission setup
- const static int object0Id = 0;
- //const static int object0Permission[];
- const static set<int> set0Allowed;
-
- IoTRMICall *rmiCall;
- static int objIdCnt;
- vector<CallBackInterface*> vecCBObj;
- //CallBackInterface cbstub;
-};
-
-
-// Permission setup
-//const int TestClass_Skeleton::object0Id = 0;
-//const int TestClass_Skeleton::object0Permission[] = {0, 1, 2, 3, 4, 5};
-const set<int> TestClass_Skeleton::set0Allowed {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
-
-int TestClass_Skeleton::objIdCnt = 0;
-
-
-TestClass_Skeleton::TestClass_Skeleton(TestClassInterface* _tc, int _port) {
-
- bool _bResult = false;
- tc = _tc;
- rmiObj = new IoTRMIObject(_port, &_bResult);
- ___waitRequestInvokeMethod();
-}
-
-
-TestClass_Skeleton::~TestClass_Skeleton() {
-
- if (rmiObj != NULL) {
- delete rmiObj;
- rmiObj = NULL;
- }
- if (rmiCall != NULL) {
- delete rmiCall;
- rmiCall = NULL;
- }
- for(CallBackInterface* cb : vecCBObj) {
- delete cb;
- cb = NULL;
- }
-}
-
-
-void TestClass_Skeleton::setA(int _int) {
-
- tc->setA(_int);
-}
-
-
-void TestClass_Skeleton::___setA() {
-
- string paramCls[] = { "int" };
- int numParam = 1;
- int param1 = 0;
- void* paramObj[] = { ¶m1 };
- rmiObj->getMethodParams(paramCls, numParam, paramObj);
- setA(param1);
-}
-
-
-void TestClass_Skeleton::setB(float _float) {
-
- tc->setB(_float);
-}
-
-
-void TestClass_Skeleton::___setB() {
-
- string paramCls[] = { "float" };
- int numParam = 1;
- float param1 = 0.0;
- void* paramObj[] = { ¶m1 };
- rmiObj->getMethodParams(paramCls, numParam, paramObj);
- setB(param1);
-}
-
-
-void TestClass_Skeleton::setC(string _string) {
-
- tc->setC(_string);
-}
-
-
-void TestClass_Skeleton::___setC() {
-
- string paramCls[] = { "string" };
- int numParam = 1;
- string param1 = "";
- void* paramObj[] = { ¶m1 };
- rmiObj->getMethodParams(paramCls, numParam, paramObj);
- setC(param1);
-}
-
-
-string TestClass_Skeleton::sumArray(vector<string> newA) {
-
- return tc->sumArray(newA);
-}
-
-
-void TestClass_Skeleton::___sumArray() {
-
- string paramCls[] = { "string[]" };
- int numParam = 1;
- vector<string> param1;
- void* paramObj[] = { ¶m1 };
- rmiObj->getMethodParams(paramCls, numParam, paramObj);
- string retVal = sumArray(param1);
- void* retObj = &retVal;
- rmiObj->sendReturnObj(retObj, "string");
-}
-
-
-/*int64_t TestClass_Skeleton::sumArray(vector<int> newA) {
-
- return tc->sumArray(newA);
-}*/
-
-
-/*int64_t TestClass_Skeleton::____sumArray() {
-
-}*/
-
-
-int TestClass_Skeleton::setAndGetA(int newA) {
-
- return tc->setAndGetA(newA);
-}
-
-
-void TestClass_Skeleton::___setAndGetA() {
-
- string paramCls[] = { "int" };
- int numParam = 1;
- int param1 = 0;
- void* paramObj[] = { ¶m1 };
- rmiObj->getMethodParams(paramCls, numParam, paramObj);
- int retVal = setAndGetA(param1);
- void* retObj = &retVal;
- rmiObj->sendReturnObj(retObj, "int");
-}
-
-
-int TestClass_Skeleton::setACAndGetA(string newC, int newA) {
-
- return tc->setACAndGetA(newC, newA);
-}
-
-
-void TestClass_Skeleton::___setACAndGetA() {
-
- string paramCls[] = { "string", "int" };
- int numParam = 2;
- string param1 = "";
- int param2 = 0;
- void* paramObj[] = { ¶m1, ¶m2 };
- rmiObj->getMethodParams(paramCls, numParam, paramObj);
- int retVal = setACAndGetA(param1, param2);
- void* retObj = &retVal;
- rmiObj->sendReturnObj(retObj, "int");
-}
-
-
-void TestClass_Skeleton::registerCallback(CallBackInterface* _cb) {
-
- tc->registerCallback(_cb);
-}
-
-
-void TestClass_Skeleton::___registerCallback() {
-
-}
-
-
-void TestClass_Skeleton::registerCallback(vector<CallBackInterface*> _cb) {
-
- tc->registerCallback(_cb);
-}
-
-
-void TestClass_Skeleton::___regCB() {
-
- string paramCls[] = { "int", "string", "int" };
- int numParam = 3;
- int param1 = 0;
- string param2 = "";
- int param3 = 0;
- void* paramObj[] = { ¶m1, ¶m2, ¶m3 };
- rmiObj->getMethodParams(paramCls, numParam, paramObj);
- // Instantiate IoTRMICall object
- bool bResult = false;
- cout << "Port: " << param1 << endl;
- cout << "Address: " << param2 << endl;
-
- rmiCall = new IoTRMICall(param1, param2.c_str(), param3, &bResult);
-}
-
-
-void TestClass_Skeleton::____registerCallback() {
-
- string paramCls[] = { "int" };
- int numParam = 1;
- int numStubs = 0;
- void* paramObj[] = { &numStubs };
- rmiObj->getMethodParams(paramCls, numParam, paramObj);
- vector<CallBackInterface*> stub;
- for (int objId = 0; objId < numStubs; objId++) {
- CallBackInterface* cb = new CallBack_CBStub(rmiCall, objIdCnt);
- stub.push_back(cb);
- vecCBObj.push_back(cb);
- objIdCnt++;
- }
- registerCallback(stub);
-}
-
-
-int TestClass_Skeleton::callBack() {
-
- tc->callBack();
-}
-
-
-void TestClass_Skeleton::___callBack() {
-
- int retVal = callBack();
- void* retObj = &retVal;
- rmiObj->sendReturnObj(retObj, "int");
-}
-
-
-vector<data> TestClass_Skeleton::handleStruct(vector<data> vecData) {
-
- return tc->handleStruct(vecData);
-}
-
-
-int TestClass_Skeleton::___structSize() {
-
- string paramCls[] = { "int" };
- int numParam = 1;
- int param1 = 0;
- void* paramObj[] = { ¶m1 };
- rmiObj->getMethodParams(paramCls, numParam, paramObj);
- return param1;
-}
-
-
-void TestClass_Skeleton::___handleStruct(int structsize1) {
-
- string paramCls[3*structsize1];
- void* paramObj[3*structsize1];
- int numParam = 3*structsize1;
- // define array of everything
- string param1[structsize1];
- float param2[structsize1];
- int param3[structsize1];
- int pos = 0;
- for(int i=0; i < structsize1; i++) {
- paramCls[pos] = "string";
- paramObj[pos++] = ¶m1[i];
- paramCls[pos] = "float";
- paramObj[pos++] = ¶m2[i];
- paramCls[pos] = "int";
- paramObj[pos++] = ¶m3[i];
- }
- rmiObj->getMethodParams(paramCls, numParam, paramObj);
- vector<data> dat(structsize1);
- pos = 0;
- for (int i=0; i < structsize1; i++) {
- dat[i].name = param1[i];
- dat[i].value = param2[i];
- dat[i].year = param3[i];
- }
- // This is a return value of type vector of struct
- // If no return value, then just "handleStruct(dat)"
- vector<data> retData = handleStruct(dat);
- // Send the length first!
- int retLength = retData.size();
- void* retObj = &retLength;
- rmiObj->sendReturnObj(retObj, "int");
- // Send the actual bytes - struct of 3 members
- int numRetObj = 3*retLength;
- string retCls[numRetObj];
- void* retObj2[numRetObj];
- pos = 0;
- for(int i = 0; i < retLength; i++) {
- retCls[pos] = "string";
- retObj2[pos] = &retData[i].name; pos++;
- retCls[pos] = "float";
- retObj2[pos] = &retData[i].value; pos++;
- retCls[pos] = "int";
- retObj2[pos] = &retData[i].year; pos++;
- }
- rmiObj->sendReturnObj(retObj2, retCls, numRetObj);
-}
-
-
-vector<EnumC> TestClass_Skeleton::handleEnum(vector<EnumC> vecEn) {
-
- return tc->handleEnum(vecEn);
-}
-
-
-int TestClass_Skeleton::___enumSize() {
-
- string paramCls[] = { "int" };
- int numParam = 1;
- int param1 = 0;
- void* paramObj[] = { ¶m1 };
- rmiObj->getMethodParams(paramCls, numParam, paramObj);
- return param1;
-}
-
-
-void TestClass_Skeleton::___handleEnum() {
-
- int numParam = 1;
- string paramCls[] = { "int[]" };
- vector<int> paramInt;
- void* paramObj[] = { ¶mInt };
- // Receive the array of integers
- rmiObj->getMethodParams(paramCls, numParam, paramObj);
- int enumSize1 = paramInt.size();
- vector<EnumC> en(enumSize1);
- for (int i=0; i < enumSize1; i++) {
- en[i] = (EnumC) paramInt[i];
- }
- //handleEnum(en);
- // if void, just "handleEnum(en)"
- // this is when we have return value vector<EnumC>
- vector<EnumC> retEnum = handleEnum(en);
- // Get length first
- int enumSize2 = retEnum.size();
- // Now send the array of integers
- vector<int> retEnumInt(enumSize2);
- for (int i=0; i < enumSize2; i++) {
- retEnumInt[i] = (int) retEnum[i];
- }
- void* retObj = &retEnumInt;
- rmiObj->sendReturnObj(retObj, "int[]");
-}
-
-
-void TestClass_Skeleton::___waitRequestInvokeMethod() {
-
- int structsize1 = 0;
-
- // Loop continuously waiting for incoming bytes
- while (true) {
-
- rmiObj->getMethodBytes();
- int _objectId = rmiObj->getObjectId();
- int methodId = rmiObj->getMethodId();
- if (_objectId == object0Id) {
- // Multiplex based on object Id
- // Complain if the method is not allowed
- if (set0Allowed.find(methodId) == set0Allowed.end()) {
- cerr << "TestClass_Skeleton: This object is not allowed to access method " << methodId << endl;
- //exit(1);
- throw exception();
- }
- // If we have more than 1 object Id...
- //else if (_objectId == object1Id) {
-
- } else {
- cerr << "TestClass_Skeleton: Unrecognizable object Id: " << _objectId << endl;
- throw exception();
- //exit(1);
- }
-
- switch (methodId) {
- case 0: ___setA(); break;
- case 1: ___setB(); break;
- case 2: ___setC(); break;
- case 3: ___sumArray(); break;
- /* case 3: ____sumArray(); break;*/
- case 4: ___setAndGetA(); break;
- case 5: ___setACAndGetA(); break;
- case 6: ___callBack(); break;
- case 7: ___registerCallback(); break;
- case 8: ____registerCallback(); break;
- case 9: ___regCB(); break;
- // Handle struct
- case 10: ___handleStruct(structsize1); break;
- case 11: structsize1 = ___structSize(); break;
- case 12: ___handleEnum(); break;
- default:
- string error = "Method Id not recognized!";
- throw error;
- }
- }
-}
-
-
-#endif
-
+++ /dev/null
-#include <iostream>
-#include <string>
-#include "TestClass_Stub.hpp"
-#include "CallBack.hpp"
-
-using namespace std;
-
-static exception_ptr teptr = nullptr;
-
-int main(int argc, char *argv[])
-{
-
- int port = 5010;
- const char* address = "localhost";
- int rev = 0;
- bool bResult = false;
- vector<int> ports;
- ports.push_back(12345);
- //ports.push_back(13234);
-
- TestClassInterface *tcStub = new TestClass_Stub(port, address, rev, &bResult, ports);
- cout << "Return value: " << tcStub->setAndGetA(123) << endl;
- cout << "Return value: " << tcStub->setACAndGetA("string", 123) << endl;
- vector<string> input;
- input.push_back("123");
- input.push_back("456");
- input.push_back("987");
- /*vector<int> input;
- input.push_back(123);
- input.push_back(456);
- input.push_back(987);*/
-
- cout << "Return value: " << tcStub->sumArray(input) << endl;
-
- CallBackInterface *cb1 = new CallBack(23);
- CallBackInterface *cb2 = new CallBack(33);
- CallBackInterface *cb3 = new CallBack(43);
- vector<CallBackInterface*> cb;
- cb.push_back(cb1);
- cb.push_back(cb2);
- cb.push_back(cb3);
- tcStub->registerCallback(cb);
- CallBackInterface *cb4 = new CallBack(53);
- CallBackInterface *cb5 = new CallBack(63);
- CallBackInterface *cb6 = new CallBack(73);
- vector<CallBackInterface*> cbsec;
- cbsec.push_back(cb4);
- cbsec.push_back(cb5);
- cbsec.push_back(cb6);
- tcStub->registerCallback(cbsec);
- cout << "Return value from callback: " << tcStub->callBack() << endl;
-
- vector<data> dataset;
-
- data testdata;
- testdata.name = "Rahmadi";
- testdata.value = 0.123;
- testdata.year = 2016;
-
- data testdata2;
- testdata2.name = "Trimananda";
- testdata2.value = 0.223;
- testdata2.year = 2017;
-
- dataset.push_back(testdata);
- dataset.push_back(testdata2);
-
- vector<data> result = tcStub->handleStruct(dataset);
- for (data dt : result) {
- cout << dt.name << " ";
- cout << dt.value << " ";
- cout << dt.year << endl;
- }
-
-/* vector<EnumC> vecEn;
- vecEn.push_back(APPLE);
- vecEn.push_back(ORANGE);
- vecEn.push_back(APPLE);
- vecEn.push_back(GRAPE);
- vector<EnumC> vecRes = tcStub->handleEnum(vecEn);
- for (EnumC en : vecRes) {
- cout << "EnumC: " << en << endl;
- }
-
- delete tcStub;
- delete cb1;
- delete cb2;
- delete cb3;*/
-
- return 0;
-}
+++ /dev/null
-#ifndef _TESTCLASS_STUB_HPP__
-#define _TESTCLASS_STUB_HPP__
-
-#include <iostream>
-#include <set>
-#include <thread>
-#include "../IoTRMICall.hpp"
-#include "../IoTRMIObject.hpp"
-#include "TestClassInterface.hpp"
-#include "CallBack_CBSkeleton.hpp"
-#include "StructC.hpp"
-
-using namespace std;
-
-class TestClass_Stub : public TestClassInterface {
- public:
- TestClass_Stub();
- TestClass_Stub(int _port, const char* _address, int _rev, bool* _bResult, vector<int> _ports);
- ~TestClass_Stub();
-
- void setA(int _int);
- void setB(float _float);
- void setC(string _string);
- string sumArray(vector<string> newA);
- //int64_t sumArray(vector<int> newA);
- int setAndGetA(int newA);
- int setACAndGetA(string newC, int newA);
- void registerCallback(CallBackInterface* _cb);
- void registerCallback(vector<CallBackInterface*>_cb);
- int callBack();
- vector<data> handleStruct(vector<data> vecData);
- vector<EnumC> handleEnum(vector<EnumC> vecEn);
- void ____init_CallBack(); // thread
- void ____registerCallBack(); // tell the other side that we are ready
-
- //exception_ptr teptr = nullptr;
-
- private:
- int intA;
- float floatB;
- string stringC;
- //CallBackInterface cb;
- IoTRMICall *rmiCall;
- string address;
- vector<int> ports;
- const static int objectId = 0; // Default value is 0
-
- // Specific for callbacks
- IoTRMIObject *rmiObj;
- vector<CallBackInterface*> vecCBObj;
- static int objIdCnt;
- // Callback permission
- const static set<int> set0Allowed;
-};
-
-
-int TestClass_Stub::objIdCnt = 0;
-
-
-const set<int> TestClass_Stub::set0Allowed { 0, 1 };
-
-
-TestClass_Stub::TestClass_Stub() {
-
- address = "";
- rmiCall = NULL;
-}
-
-
-TestClass_Stub::TestClass_Stub(int _port, const char* _address, int _rev, bool* _bResult, vector<int> _ports) {
-
- address = _address;
- rmiCall = new IoTRMICall(_port, _address, _rev, _bResult);
- ports = _ports;
- // Start thread
- /*if (teptr) {
- try {
- thread th1 (&TestClass_Stub::____init_CallBack, this);
- th1.detach();
- } catch(const exception&) {
- cout << "Got here!" << endl;
- throw exception();
- }
- }*/
- thread th1 (&TestClass_Stub::____init_CallBack, this);
- th1.detach();
- //th1.join();
- ____registerCallBack();
-}
-
-
-TestClass_Stub::~TestClass_Stub() {
-
- if (rmiCall != NULL) {
- delete rmiCall;
- rmiCall = NULL;
- }
- if (rmiObj != NULL) {
- delete rmiObj;
- rmiObj = NULL;
- }
- // Special for callbacks!!!
- for(CallBackInterface* cb : vecCBObj) {
- delete cb;
- cb = NULL;
- }
-}
-
-
-// Callback handler thread
-void TestClass_Stub::____init_CallBack() {
-
- bool bResult = false;
- rmiObj = new IoTRMIObject(ports[0], &bResult);
- while (true) {
- char* method = rmiObj->getMethodBytes();
- int methodId = IoTRMIObject::getMethodId(method);
- // Permission check
- // Complain if the method is not allowed
- if (set0Allowed.find(methodId) == set0Allowed.end()) {
- cerr << "TestClass_Skeleton: This object is not allowed to access method " << methodId << endl;
- exit(-1);
- //throw exception();
- //teptr = current_exception();
- }
- int objId = IoTRMIObject::getObjectId(method);
- if (objId < vecCBObj.size()) { // Check if still within range
- CallBack_CBSkeleton* skel =
- dynamic_cast<CallBack_CBSkeleton*> (vecCBObj.at(objId));
- skel->invokeMethod(rmiObj);
- } else {
- string error = "TestClass_Stub: Illegal object Id: " + to_string(objId);
- throw error;
- }
- }
-}
-
-
-// Notify that callback thread is ready
-void TestClass_Stub::____registerCallBack() {
-
- int numParam = 3;
- int methodId = 9;
- string retType = "void";
- string paramCls[] = { "int", "string", "int" };
- int rev = 0;
- void* paramObj[] = { &ports[0], &address, &rev };
- void* retObj = NULL;
- rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
-}
-
-
-void TestClass_Stub::setA(int _int) {
-
- int numParam = 1;
- int methodId = 0;
- string retType = "void";
- string paramCls[] = { "int" };
- void* paramObj[] = { &_int };
- void* retObj = NULL;
- rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
-}
-
-
-void TestClass_Stub::setB(float _float) {
-
- int numParam = 1;
- int methodId = 1;
- string retType = "void";
- string paramCls[] = { "float" };
- void* paramObj[] = { &_float };
- void* retObj = NULL;
- rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
-}
-
-
-void TestClass_Stub::setC(string _string) {
-
- int numParam = 1;
- int methodId = 2;
- string retType = "void";
- string paramCls[] = { "string" };
- void* paramObj[] = { &_string };
- void* retObj = NULL;
- rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
-}
-
-
-string TestClass_Stub::sumArray(vector<string> newA) {
-
- int numParam = 1;
- int methodId = 3;
- string retType = "string";
- string paramCls[] = { "string[]" };
- void* paramObj[] = { &newA };
- string retVal = "";
- void* retObj = &retVal;
- rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
- return retVal;
-}
-
-
-/*int64_t TestClass_Stub::sumArray(vector<int> newA) {
-
- int numParam = 1;
- string sign = "sumArray(int[])";
- string retType = "long";
- string paramCls[] = { "int[]" };
- void* paramObj[] = { &newA };
- int64_t retVal = 0;
- void* retObj = &retVal;
- rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
- return retVal;
-}*/
-
-
-
-int TestClass_Stub::setAndGetA(int newA) {
-
- int numParam = 1;
- int methodId = 4;
- string retType = "int";
- string paramCls[] = { "int" };
- void* paramObj[] = { &newA };
- int retVal = 0;
- void* retObj = &retVal;
- rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
- return retVal;
-}
-
-
-int TestClass_Stub::setACAndGetA(string newC, int newA) {
-
- int numParam = 2;
- int methodId = 5;
- string retType = "int";
- string paramCls[] = { "string", "int" };
- void* paramObj[] = { &newC, &newA };
- int retVal = 0;
- void* retObj = &retVal;
- rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
- return retVal;
-}
-
-
-void TestClass_Stub::registerCallback(CallBackInterface* _cb) {
-
- //Should implement the callback here
-}
-
-
-void TestClass_Stub::registerCallback(vector<CallBackInterface*> _cb) {
-
- for (CallBackInterface* cb: _cb) {
- CallBack_CBSkeleton* skel = new CallBack_CBSkeleton(cb, objIdCnt++);
- vecCBObj.push_back(skel);
- }
-
- int numParam = 1;
- int methodId = 8;
- string retType = "void";
- string paramCls[] = { "int" };
- int param1 = _cb.size();
- void* paramObj[] = { ¶m1 };
- void* retObj = NULL;
- rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
-}
-
-
-int TestClass_Stub::callBack() {
-
- int numParam = 0;
- int methodId = 6;
- string retType = "int";
- string paramCls[] = { };
- void* paramObj[] = { };
- int retVal = 0;
- void* retObj = &retVal;
- rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
- return retVal;
-}
-
-
-vector<data> TestClass_Stub::handleStruct(vector<data> vecData) {
-
- int numParam = 1;
- int methodId = 11;
- string retType = "void";
- string paramCls[] = { "int" };
- int structsize = vecData.size();
- void* paramObj[] = { &structsize };
- void* retObj = NULL;
- rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
-
- int numParam2 = 3*vecData.size();
- int methodId2 = 10;
- string retType2 = "int";
- string paramCls2[numParam2];
- void* paramObj2[numParam2];
- int pos = 0;
- for(int i = 0; i < vecData.size(); i++) {
- paramCls2[pos] = "string";
- paramObj2[pos] = &vecData[i].name; pos++;
- paramCls2[pos] = "float";
- paramObj2[pos] = &vecData[i].value; pos++;
- paramCls2[pos] = "int";
- paramObj2[pos] = &vecData[i].year; pos++;
- }
- // RETURN STRUCT OBJECT
- // Get length of struct array
- int structsize1 = 0;
- void* retObj2 = { &structsize1 };
- // IF we don't have returned struct objects, then it's just "void* retObj2 = NULL;"
- rmiCall->remoteCall(objectId, methodId2, retType2, paramCls2, paramObj2, numParam2, retObj2);
- cout << "Struct length: " << structsize1 << endl;
-
- // Get the returned objects
- string retCls[3*structsize1];
- void* retObj3[3*structsize1];
- int numRet = 3*structsize1;
- // define array of everything
- string param1[structsize1];
- float param2[structsize1];
- int param3[structsize1];
- pos = 0;
- for(int i=0; i < structsize1; i++) {
- retCls[pos] = "string";
- retObj3[pos++] = ¶m1[i];
- retCls[pos] = "float";
- retObj3[pos++] = ¶m2[i];
- retCls[pos] = "int";
- retObj3[pos++] = ¶m3[i];
- }
- rmiCall->getStructObjects(retCls, numRet, retObj3);
- vector<data> dat(structsize1);
- pos = 0;
- for (int i=0; i < structsize1; i++) {
- dat[i].name = param1[i];
- dat[i].value = param2[i];
- dat[i].year = param3[i];
- }
-
- return dat;
-}
-
-
-vector<EnumC> TestClass_Stub::handleEnum(vector<EnumC> vecEn) {
-
- int numParam = 1;
- int numEl = vecEn.size();
- int methodId = 12;
- string retType = "int[]";
- string paramCls[] = { "int[]" };
- // Need to define this container for integer version of enum
- vector<int> paramInt(numEl);
- for(int i = 0; i < numEl; i++) {
- paramInt[i] = (int) vecEn[i]; // cast enum to integer
- }
- void* paramObj[] = { ¶mInt };
- // if no return value just
- // void* retObj2 = NULL;
- // This is with return value:
- vector<int> retEnumInt;
- void* retObj = &retEnumInt;
- rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
- int enumsize1 = retEnumInt.size();
- vector<EnumC> retVal(enumsize1);
- for (int i=0; i < enumsize1; i++) {
- retVal[i] = (EnumC) retEnumInt[i];
- }
- return retVal;
-}
-
-
-
-#endif