2 * //******************************************************************
4 * // Copyright 2016 Samsung Electronics All Rights Reserved.
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
8 * // Licensed under the Apache License, Version 2.0 (the "License");
9 * // you may not use this file except in compliance with the License.
10 * // You may obtain a copy of the License at
12 * // http://www.apache.org/licenses/LICENSE-2.0
14 * // Unless required by applicable law or agreed to in writing, software
15 * // distributed under the License is distributed on an "AS IS" BASIS,
16 * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * // See the License for the specific language governing permissions and
18 * // limitations under the License.
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 package org.iotivity.cloud.ciserver;
24 import java.net.InetSocketAddress;
25 import java.util.Scanner;
27 import org.iotivity.cloud.base.connector.ConnectorPool;
28 import org.iotivity.cloud.base.server.CoapServer;
29 import org.iotivity.cloud.ciserver.DeviceServerSystem.CoapDevicePool;
30 import org.iotivity.cloud.ciserver.resources.DiResource;
31 import org.iotivity.cloud.ciserver.resources.KeepAliveResource;
32 import org.iotivity.cloud.ciserver.resources.proxy.account.Account;
33 import org.iotivity.cloud.ciserver.resources.proxy.account.AccountSession;
34 import org.iotivity.cloud.ciserver.resources.proxy.account.Acl;
35 import org.iotivity.cloud.ciserver.resources.proxy.account.AclGroup;
36 import org.iotivity.cloud.ciserver.resources.proxy.account.AclInvite;
37 import org.iotivity.cloud.ciserver.resources.proxy.account.Certificate;
38 import org.iotivity.cloud.ciserver.resources.proxy.account.Crl;
39 import org.iotivity.cloud.ciserver.resources.proxy.mq.MessageQueue;
40 import org.iotivity.cloud.ciserver.resources.proxy.rd.DevicePresence;
41 import org.iotivity.cloud.ciserver.resources.proxy.rd.ResourceDirectory;
42 import org.iotivity.cloud.ciserver.resources.proxy.rd.ResourceFind;
43 import org.iotivity.cloud.ciserver.resources.proxy.rd.ResourcePresence;
44 import org.iotivity.cloud.util.Log;
46 public class CloudInterfaceServer {
48 public static void main(String[] args) throws Exception {
51 System.out.println("-----CI SERVER-------");
53 if (args.length != 8) {
54 Log.e("coap server port and RDServer_Address port AccountServer_Address Port MQBroker_Address Port and TLS mode required\n"
55 + "ex) 5683 127.0.0.1 5684 127.0.0.1 5685 127.0.0.1 5686 0\n");
59 boolean tlsMode = Integer.parseInt(args[7]) == 1;
61 ConnectorPool.addConnection("rd",
62 new InetSocketAddress(args[1], Integer.parseInt(args[2])),
64 ConnectorPool.addConnection("account",
65 new InetSocketAddress(args[3], Integer.parseInt(args[4])),
67 ConnectorPool.addConnection("mq",
68 new InetSocketAddress(args[5], Integer.parseInt(args[6])),
71 DeviceServerSystem deviceServer = new DeviceServerSystem();
73 Account acHandler = new Account();
74 AccountSession acSessionHandler = new AccountSession();
75 ResourceDirectory rdHandler = new ResourceDirectory();
76 ResourceFind resHandler = new ResourceFind();
77 ResourcePresence adHandler = new ResourcePresence();
78 DevicePresence prsHandler = new DevicePresence();
79 MessageQueue mqHandler = new MessageQueue();
80 Acl aclHandler = new Acl();
81 AclGroup aclGroupHandler = new AclGroup();
82 Certificate certHandler = new Certificate();
83 AclInvite aclInviteHandler = new AclInvite();
84 Crl crlHandler = new Crl();
85 CoapDevicePool devicePool = deviceServer.getDevicePool();
87 deviceServer.addResource(acHandler);
89 deviceServer.addResource(acSessionHandler);
91 deviceServer.addResource(rdHandler);
93 deviceServer.addResource(resHandler);
95 deviceServer.addResource(adHandler);
97 deviceServer.addResource(prsHandler);
99 deviceServer.addResource(mqHandler);
101 deviceServer.addResource(aclHandler);
103 deviceServer.addResource(aclGroupHandler);
105 deviceServer.addResource(certHandler);
107 deviceServer.addResource(aclInviteHandler);
109 deviceServer.addResource(crlHandler);
111 KeepAliveResource resKeepAlive = new KeepAliveResource(
112 new int[] { 1, 2, 4, 8 });
114 deviceServer.addResource(resKeepAlive);
116 deviceServer.addResource(new DiResource(devicePool));
118 deviceServer.addServer(new CoapServer(
119 new InetSocketAddress(Integer.parseInt(args[0]))));
121 // deviceServer.addServer(new HttpServer(new InetSocketAddress(8080)));
123 deviceServer.startSystem(tlsMode);
125 resKeepAlive.startSessionChecker(3000, 6000);
127 Scanner in = new Scanner(System.in);
129 System.out.println("press 'q' to terminate");
131 while (!in.nextLine().equals("q"));
135 System.out.println("Terminating...");
137 resKeepAlive.stopSessionChecker();
139 deviceServer.stopSystem();
141 System.out.println("Terminated");