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),
52 void Middle::run(int argc, char* argv[])
54 parseCommandLineOptions(argc, argv);
58 if (m_appType & AT_Client) {
59 m_client = new MiddleClient();
63 m_lineInput = new LineInput(m_client);
65 if (m_appType & AT_Server) {
66 m_server = new MiddleServer();
71 m_server = new MiddleServer();
74 m_restInput = new RestInput(m_lineInput);
79 m_lineInput->setServer(m_server);
88 void Middle::startPlatform()
91 //std::string ipaddr = INADDR_ANY;
92 std::string ipaddr = "0.0.0.0";
94 PlatformConfig cfg { ServiceType::InProc, ModeType::Both,
95 ipaddr, port, QualityOfService::LowQos};
97 OC::OCPlatform::Configure(cfg);
100 void Middle::provideHelp()
102 static const char usage[] = "\nUsage: IOCMiddle args\n"
103 " where args may include any of these:\n"
104 "\t-client Run OIC client\n"
105 "\t-server Run OIC server\n"
106 "\t-both Run OIC client and server\n"
107 "\t-console Run console line interpreter\n"
108 "\t-rest Run ReST server\n"
109 "\t-hue addr Enable Hue resources on bridge at addr\n"
110 "\t-help Show Usage again\n"
111 "Any combination of the above is okay.\n\n";
115 bool Middle::parseCommandLineOptions(int argc, char *argv[])
119 for (int i = 1; i < argc; i++) {
120 if (argv[i] == string("-server")) {
121 middle.m_appType = AT_Server; any = true;
122 } else if (argv[i] == string("-client")) {
123 middle.m_appType = AT_Client; any = true;
124 } else if (argv[i] == string("-both")) {
125 middle.m_appType = AT_Both; any = true;
126 } else if (argv[i] == string("-console")) {
127 middle.m_useLineInput = true; any = true;
128 } else if (argv[i] == string("-rest")) {
129 middle.m_useRestInput = true; any = true;
130 } else if (argv[i] == string("-hue")) {
131 if (i + 1 < argc && argv[i + 1][0] != '-') {
132 m_hueAddr = argv[++i];
135 } else if (argv[i] == string("-help")) {
139 std::cerr << "Not enough or invalid arguments, please try again.\n";
148 int main(int argc, char* argv[])
150 middle.run(argc, argv);