import java.net.InetSocketAddress;
import java.util.Scanner;
-import org.iotivity.cloud.base.CoapServer;
-import org.iotivity.cloud.base.ResourceManager;
-import org.iotivity.cloud.rdserver.resources.ResourceDirectoryResource;
+import org.iotivity.cloud.base.ServerSystem;
+import org.iotivity.cloud.base.server.CoapServer;
+import org.iotivity.cloud.rdserver.resources.directory.rd.ResourceDirectoryResource;
+import org.iotivity.cloud.rdserver.resources.directory.res.DiscoveryResource;
+import org.iotivity.cloud.rdserver.resources.presence.device.DevicePresenceResource;
+import org.iotivity.cloud.rdserver.resources.presence.resource.ResPresenceResource;
+import org.iotivity.cloud.util.ErrorLogger;
+import org.iotivity.cloud.util.FileLogger;
import org.iotivity.cloud.util.Logger;
public class ResourceDirectoryServer {
public static void main(String[] args) throws Exception {
+ System.setOut(FileLogger.createLoggingProxy(System.out));
System.out.println("-----RD SERVER-----");
- if (args.length != 1) {
- Logger.e("coap server port required");
+ if (args.length != 2) {
+ Logger.e("coap server port and TLS mode required\n"
+ + "ex) 5684 0\n");
return;
}
- ResourceManager resourceManager = null;
+ ErrorLogger.Init();
- CoapServer coapServer = null;
+ ServerSystem serverSystem = new ServerSystem();
- coapServer = new CoapServer();
+ serverSystem.addResource(new ResourceDirectoryResource());
+ serverSystem.addResource(new DiscoveryResource());
+ serverSystem.addResource(new DevicePresenceResource());
+ serverSystem.addResource(new ResPresenceResource());
- resourceManager = new ResourceManager();
+ serverSystem.addServer(new CoapServer(
+ new InetSocketAddress(Integer.parseInt(args[0]))));
- coapServer.addHandler(resourceManager);
+ boolean tlsMode = Integer.parseInt(args[1]) == 1;
- resourceManager.registerResource(new ResourceDirectoryResource());
+ serverSystem.startSystem(tlsMode);
- coapServer
- .startServer(new InetSocketAddress(Integer.parseInt(args[0])));
-
- Scanner in = new Scanner(System.in, "UTF8");
+ Scanner in = new Scanner(System.in);
System.out.println("press 'q' to terminate");
System.out.println("Terminating...");
- coapServer.stopServer();
+ serverSystem.stopSystem();
System.out.println("Terminated");
}