removed duplicate call to OCBuildIPv4Address OCInitCoAP.
Change-Id: I51ed3ff71997069e375043e37946180223a60141
ret = OC_STACK_ERROR;
goto exit;
}
- OC_LOG_V(INFO, TAG, "Parsed IP Address %d.%d.%d.%d",ipAddr[0],ipAddr[1],ipAddr[2],ipAddr[3]);
- OCBuildIPv4Address(ipAddr[0], ipAddr[1], ipAddr[2], ipAddr[3], port,
- &devAddr);
+ OC_LOG_V(INFO, TAG, "Parsed IP Address %d.%d.%d.%d",
+ ipAddr[0],ipAddr[1],ipAddr[2],ipAddr[3]);
}
OCBuildIPv4Address(ipAddr[0], ipAddr[1], ipAddr[2], ipAddr[3], port,
{
ServiceType::InProc,
ModeType::Client,
- "134.134.161.33",
- 56832,
+ "0.0.0.0",
+ 0,
QualityOfService::NonConfirmable
};
{
ServiceType::InProc,
ModeType::Server,
- "134.134.161.33",
- 56832,
+ "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
+ 0, // Uses randomly available port
QualityOfService::NonConfirmable
};
PlatformConfig cfg {
OC::ServiceType::InProc,
OC::ModeType::Client,
- "192.168.1.10",
- 5683,
+ "0.0.0.0",
+ 0,
OC::QualityOfService::NonConfirmable
};
PlatformConfig cfg {
OC::ServiceType::InProc,
OC::ModeType::Server,
- "134.134.161.33",
- 56832,
+ "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
+ 0, // Uses randomly available port
OC::QualityOfService::NonConfirmable
};
namespace Intel { namespace OCDemo {
auto make_description()
- -> boost::program_options::options_description
+ -> boost::program_options::options_description
{
using std::string;
using std::vector;
desc.add_options()
("nres", po::value<unsigned long>()->default_value(1), "number of resources to use for testing")
- ("host_ip", po::value<string>()->default_value("134.134.161.33"), "IP of host")
- ("host_port", po::value<uint16_t>()->default_value(5683), "port of host")
+ ("host_ip", po::value<string>()->default_value("0.0.0.0"), "IP of host")
+ ("host_port", po::value<uint16_t>()->default_value(0), "port of host")
("interface", po::value<string>()->default_value("eth0"), "network interface name")
("uri", po::value<vector<string>>(), "remote resource URI")
;
{
using namespace std;
- OC::OCPlatform platform({
+ OC::OCPlatform platform({
OC::ServiceType::InProc, // in-process server
OC::ModeType::Client, // client mode
vm["host_ip"].as<string>(), // host
vm["host_port"].as<uint16_t>(), // port
- OC::QualityOfService::NonConfirmable
+ OC::QualityOfService::NonConfirmable
});
vector<string> resource_URIs;
// Find all resources:
resource_URIs.push_back("coap://224.0.1.187/oc/core");
- /* Example of finding specific resources:
+ /* Example of finding specific resources:
const auto& nprops = vm["nres"].as<unsigned long>();
for(unsigned long instance_number = 1;
namespace Intel { namespace OCDemo {
auto make_description()
- -> boost::program_options::options_description
+ -> boost::program_options::options_description
{
using std::string;
std::cout << "JFW: TODO: separate IP/port/etc. for server and client!\n";
desc.add_options()
("nres", po::value<unsigned long>()->default_value(1), "number of resources to use for testing")
- ("host_ip", po::value<string>()->default_value("134.134.161.33"), "IP of host")
- ("host_port", po::value<uint16_t>()->default_value(5683), "port of host")
- ("interface", po::value<string>()->default_value("eth0"), "network interface name")
+ ("host_ip", po::value<string>()->default_value("0.0.0.0"), "IP of host")
+ ("host_port", po::value<uint16_t>()->default_value(0), "port of host")
+ ("interface", po::value<string>()->default_value("eth0"), "network interface name")
("uri", po::value<vector<string>>(), "resource URI")
;
server_t(const boost::program_options::variables_map& vm,
std::shared_ptr<OC::OCPlatform> platform,
atomic<bool>& quit_flag_)
- : m_vm(vm),
+ : m_vm(vm),
m_platform_ptr(platform),
m_platform(*m_platform_ptr),
quit_flag(quit_flag_)
OC::ModeType::Both, // run in client/server mode
vm["host_ip"].as<string>(), // host
vm["host_port"].as<uint16_t>(), // port
- OC::QualityOfService::NonConfirmable
+ OC::QualityOfService::NonConfirmable
});
std::cout << "Ok." << std::endl;
namespace Intel { namespace OCDemo {
auto make_description()
- -> boost::program_options::options_description
+ -> boost::program_options::options_description
{
using std::string;
desc.add_options()
("nres", po::value<unsigned long>()->default_value(1), "number of resources to use for testing")
- ("host_ip", po::value<string>()->default_value("134.134.161.33"), "IP of host")
- ("host_port", po::value<uint16_t>()->default_value(56832), "port of host")
- ("interface", po::value<string>()->default_value("eth0"), "network interface name")
+ ("host_ip", po::value<string>()->default_value("0.0.0.0"), "IP of host")
+ ("host_port", po::value<uint16_t>()->default_value(0), "port of host")
+ ("interface", po::value<string>()->default_value("eth0"), "network interface name")
("uri", po::value<vector<string>>(), "resource URI")
("runtime", po::value<unsigned int>()->default_value(3600), "time in seconds to keep the server alive")
;
std::cout << "Starting platform: " << std::flush;
- OC::OCPlatform platform({
+ OC::OCPlatform platform({
OC::ServiceType::InProc, // in-process server
OC::ModeType::Server, // run in server mode
vm["host_ip"].as<string>(), // host
vm["host_port"].as<uint16_t>(), // port
- OC::QualityOfService::NonConfirmable
+ OC::QualityOfService::NonConfirmable
});
std::cout << "Ok." << std::endl;
hostAddress = resource->host();
std::cout << "\tHost address of the resource: " << hostAddress << std::endl;
- // Get the resource types
+ // Get the resource types
std::cout << "\tList of resource types: " << std::endl;
for(auto &resourceTypes : resource->getResourceTypes())
{
std::cout << "\t\t" << resourceTypes << std::endl;
}
-
+
// Get the resource interfaces
std::cout << "\tList of resource interfaces: " << std::endl;
for(auto &resourceInterfaces : resource->getResourceInterfaces())
{
std::cout << "\t\t" << resourceInterfaces << std::endl;
- }
+ }
if(resourceURI == "/a/light")
{
PlatformConfig cfg {
OC::ServiceType::InProc,
OC::ModeType::Client,
- "192.168.1.10",
- 5683,
+ "0.0.0.0",
+ 0,
OC::QualityOfService::NonConfirmable
};
public:
/// Constructor
- LightResource(): m_state(false), m_power(0), m_lightUri("/a/light"),
+ LightResource(): m_state(false), m_power(0), m_lightUri("/a/light"),
m_lightUri2("/a/light2"),m_lightUri3("/a/light3") {}
/* Note that this does not need to be a member function: for classes you do not have
void createResource(OC::OCPlatform& platform)
{
std::string resourceURI = m_lightUri; // URI of the resource
- std::string resourceTypeName = "core.light"; // resource type name. In this case, it is light
+ std::string resourceTypeName = "core.light"; // resource type name.
std::string resourceInterface = DEFAULT_INTERFACE; // resource interface.
// OCResourceProperty is defined ocstack.h
PlatformConfig cfg {
OC::ServiceType::InProc,
OC::ModeType::Server,
- "134.134.161.33",
- 56832,
+ "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
+ 0, // Uses randomly available port
OC::QualityOfService::NonConfirmable
};
if(eCode == SUCCESS_RESPONSE)
{
std::cout << "GET request was successful" << std::endl;
-
+
std::cout << "\tResource URI: " << rep.getUri() << std::endl;
std::vector<OCRepresentation> children = rep.getChildren();
int color = 0;
oit->getValue("state", state);
oit->getValue("color", color);
-
+
std::cout << "\t\tstate:" << state << std::endl;
std::cout << "\t\tcolor:" << color << std::endl;
}
int speed = 0;
oit->getValue("state", state);
oit->getValue("speed", speed);
-
+
std::cout << "\t\tstate:" << state << std::endl;
std::cout << "\t\tspeed:" << speed << std::endl;
}
std::cout << "Putting room representation..."<<std::endl;
bool state = true;
- int speed = 10;
+ int speed = 10;
rep.setValue("state", state);
rep.setValue("speed", speed);
int color = 0;
oit->getValue("state", state);
oit->getValue("color", color);
-
std::cout << "\t\tstate:" << state << std::endl;
std::cout << "\t\tcolor:" << color << std::endl;
}
int speed = 0;
oit->getValue("state", state);
oit->getValue("speed", speed);
-
std::cout << "\t\tstate:" << state << std::endl;
std::cout << "\t\tspeed:" << speed << std::endl;
}
hostAddress = resource->host();
std::cout << "\tHost address of the resource: " << hostAddress << std::endl;
- // Get the resource types
+ // Get the resource types
std::cout << "\tList of resource types: " << std::endl;
for(auto &resourceTypes : resource->getResourceTypes())
{
std::cout << "\t\t" << resourceTypes << std::endl;
}
-
+
// Get the resource interfaces
std::cout << "\tList of resource interfaces: " << std::endl;
for(auto &resourceInterfaces : resource->getResourceInterfaces())
{
std::cout << "\t\t" << resourceInterfaces << std::endl;
- }
+ }
if(resourceURI == "/a/room")
{
PlatformConfig cfg {
OC::ServiceType::InProc,
OC::ModeType::Client,
- "192.168.1.10",
- 5683,
+ "0.0.0.0",
+ 0,
OC::QualityOfService::NonConfirmable
};
public:
/// Constructor
- RoomResource(): m_lightState(false), m_lightColor(0), m_fanState(false), m_fanSpeed(0)
+ RoomResource(): m_lightState(false), m_lightColor(0), m_fanState(false), m_fanSpeed(0)
{
m_lightUri = "/a/light"; // URI of the resource
m_lightTypes.push_back("core.light"); // resource type name. In this case, it is light
// This will internally create and register the resource.
OCStackResult result = platform.registerResource(
m_roomHandle, m_roomUri, m_roomTypes[0],
- m_roomInterfaces[0], NULL, //entityHandlerRoom,
+ m_roomInterfaces[0], NULL, //entityHandlerRoom,
OC_DISCOVERABLE | OC_OBSERVABLE
);
result = platform.registerResource(
m_lightHandle, m_lightUri, m_lightTypes[0],
- m_lightInterfaces[0], entityHandlerLight,
+ m_lightInterfaces[0], entityHandlerLight,
OC_DISCOVERABLE | OC_OBSERVABLE
);
result = platform.registerResource(
m_fanHandle, m_fanUri, m_fanTypes[0],
- m_fanInterfaces[0], entityHandlerFan,
+ m_fanInterfaces[0], entityHandlerFan,
OC_DISCOVERABLE | OC_OBSERVABLE
);
{
m_lightState = tempState;
m_lightColor= tempColor;
-
+
cout << "\t\t\t\t" << "state: " << m_lightState << endl;
cout << "\t\t\t\t" << "color: " << m_lightColor << endl;
}
}
- OCRepresentation getLightRepresentation()
+ OCRepresentation getLightRepresentation()
{
m_lightRep.setValue("state", m_lightState);
m_lightRep.setValue("color", m_lightColor);
OCRepresentation fan = getFanRepresentation();
children.push_back(fan);
-
+
m_roomRep.setChildren(children);
return m_roomRep;
// Create the instance of the resource class (in this case instance of class 'RoomResource').
RoomResource myRoomResource;
-void entityHandlerRoom(std::shared_ptr<OCResourceRequest> request, std::shared_ptr<OCResourceResponse> response)
+void entityHandlerRoom(std::shared_ptr<OCResourceRequest> request,
+ std::shared_ptr<OCResourceResponse> response)
{
cout << "\tIn Server CPP entity handler:\n";
PlatformConfig cfg {
OC::ServiceType::InProc,
OC::ModeType::Server,
- "192.168.1.10",
- 56832,
+ "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
+ 0, // Uses randomly available port
OC::QualityOfService::NonConfirmable
};
PlatformConfig cfg {
OC::ServiceType::InProc,
OC::ModeType::Client,
- "192.168.1.10",
- 5683,
+ "0.0.0.0",
+ 0,
OC::QualityOfService::NonConfirmable
};
}
void foundResource(std::shared_ptr<OCResource> resource)
- {
+ {
std::cout << "In foundResource" << std::endl;
if(resource && resource->uri() == "/q/foo")
{
std::cout << "Found Resource: "<<std::endl;
std::cout << "\tHost: "<< resource->host()<<std::endl;
std::cout << "\tURI: "<< resource->uri()<<std::endl;
-
- // Get the resource types
+
+ // Get the resource types
std::cout << "\tList of resource types: " << std::endl;
for(auto &resourceTypes : resource->getResourceTypes())
{
std::cout << "\t\t" << resourceTypes << std::endl;
}
-
+
// Get the resource interfaces
std::cout << "\tList of resource interfaces: " << std::endl;
for(auto &resourceInterfaces : resource->getResourceInterfaces())
{
std::cout << "\t\t" << resourceInterfaces << std::endl;
- }
+ }
std::cout<<"Doing a get on q/foo."<<std::endl;
resource->get(QueryParamsMap(), GetCallback(std::bind(&ClientWorker::getResourceInfo, this, std::placeholders::_1, std::placeholders::_2)));
- }
+ }
}
public:
RegisterCallback eh(std::bind(&FooResource::entityHandler, this, std::placeholders::_1, std::placeholders::_2));
OCStackResult result = platform.registerResource(m_resourceHandle, resourceURI, resourceTypeName,
- resourceInterface,
+ resourceInterface,
eh, resourceProperty);
if(OC_STACK_OK != result)
{
else
{
std::cout <<"\t\trequestFlag : UNSUPPORTED: ";
-
+
if(request->getRequestHandlerFlag()==RequestHandlerFlag::InitFlag)
{
std::cout<<"InitFlag"<<std::endl;
PlatformConfig cfg {
OC::ServiceType::InProc,
OC::ModeType::Both,
- "134.134.161.33",
- 56833,
+ "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
+ 0, // Uses randomly available port
OC::QualityOfService::NonConfirmable
};
try
{
OCPlatform platform(cfg);
-
+
if(!fooRes.createResource(platform))
{
return -1;
PlatformConfig cfg {
OC::ServiceType::InProc,
OC::ModeType::Server,
- "134.134.161.33",
- 56832,
+ "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
+ 0, // Uses randomly available port
OC::QualityOfService::NonConfirmable
};
NonConfirmable = OC_NON_CONFIRMABLE
};
+ /**
+ * Data structure to provide the configuration.
+ * ServiceType: indicate InProc or OutOfProc
+ * ModeType : indicate whether we want to do server, client or both
+ * ipAddress : ip address of server.
+ * if you speecifiy 0.0.0.0 : it listens on any interface.
+ * port : port of server.
+ * : if you specifiy 0 : next available random port is used.
+ * : if you specify 5683 : client discovery can work even if they don't specify port.
+ * QoS : Quality of Service : CONFIRMABLE or NON CONFIRMABLE.
+ */
struct PlatformConfig
{
- ServiceType serviceType; // This will indicate whether it is InProc or OutOfProc
- ModeType mode; // This will indicate whether we want to do server, client or both
- std::string ipAddress; // This is the ipAddress of the server to connect to
- uint16_t port; // Port of the server
+ ServiceType serviceType;
+ ModeType mode;
+ std::string ipAddress;
+ uint16_t port;
QualityOfService QoS;