1 //******************************************************************
3 // Copyright 2014 Intel Corporation.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 // OICMiddle.cpp : OIC demo application for Minnowboard
27 #include "OICMiddle.h"
28 #include "WrapResource.h"
31 #include "LineInput.h"
32 #include "RestInput.h"
34 class Middle middle; // one and only
38 m_useLineInput(false),
39 m_useRestInput(false),
60 void Middle::run(int argc, char* argv[])
62 parseCommandLineOptions(argc, argv);
66 if (m_appType & AT_Client) {
67 m_client = new MiddleClient();
71 m_lineInput = new LineInput(m_client);
73 if (m_appType & AT_Server) {
74 m_server = new MiddleServer();
79 m_server = new MiddleServer();
82 m_restInput = new RestInput(m_lineInput);
87 m_lineInput->setServer(m_server);
96 void Middle::startPlatform()
99 //std::string ipaddr = INADDR_ANY;
100 std::string ipaddr = "0.0.0.0";
102 PlatformConfig cfg { ServiceType::InProc, ModeType::Both,
103 ipaddr, port, QualityOfService::LowQos};
105 OC::OCPlatform::Configure(cfg);
108 void Middle::provideHelp()
110 static const char usage[] = "\nUsage: IOCMiddle args\n"
111 " where args may include any of these:\n"
112 "\t-client Run OIC client\n"
113 "\t-server Run OIC server\n"
114 "\t-both Run OIC client and server\n"
115 "\t-console Run console line interpreter\n"
116 "\t-rest Run ReST server\n"
117 "\t-hue addr Enable Hue resources on bridge at addr\n"
118 "\t-help Show Usage again\n"
119 "Any combination of the above is okay.\n\n";
123 bool Middle::parseCommandLineOptions(int argc, char *argv[])
127 for (int i = 1; i < argc; i++) {
128 if (argv[i] == string("-server")) {
129 middle.m_appType = AT_Server; any = true;
130 } else if (argv[i] == string("-client")) {
131 middle.m_appType = AT_Client; any = true;
132 } else if (argv[i] == string("-both")) {
133 middle.m_appType = AT_Both; any = true;
134 } else if (argv[i] == string("-console")) {
135 middle.m_useLineInput = true; any = true;
136 } else if (argv[i] == string("-rest")) {
137 middle.m_useRestInput = true; any = true;
138 } else if (argv[i] == string("-hue")) {
139 if (i + 1 < argc && argv[i + 1][0] != '-') {
140 m_hueAddr = argv[++i];
143 } else if (argv[i] == string("-help")) {
147 std::cerr << "Not enough or invalid arguments, please try again.\n";
156 int main(int argc, char* argv[])
158 middle.run(argc, argv);