10aa0d114SJayanth Othayoth /**
20aa0d114SJayanth Othayoth * Copyright © 2018 IBM Corporation
30aa0d114SJayanth Othayoth *
40aa0d114SJayanth Othayoth * Licensed under the Apache License, Version 2.0 (the "License");
50aa0d114SJayanth Othayoth * you may not use this file except in compliance with the License.
60aa0d114SJayanth Othayoth * You may obtain a copy of the License at
70aa0d114SJayanth Othayoth *
80aa0d114SJayanth Othayoth * http://www.apache.org/licenses/LICENSE-2.0
90aa0d114SJayanth Othayoth *
100aa0d114SJayanth Othayoth * Unless required by applicable law or agreed to in writing, software
110aa0d114SJayanth Othayoth * distributed under the License is distributed on an "AS IS" BASIS,
120aa0d114SJayanth Othayoth * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130aa0d114SJayanth Othayoth * See the License for the specific language governing permissions and
140aa0d114SJayanth Othayoth * limitations under the License.
150aa0d114SJayanth Othayoth */
160aa0d114SJayanth Othayoth
17cfbc8dc8SJayanth Othayoth #include "config.h"
18cfbc8dc8SJayanth Othayoth
190aa0d114SJayanth Othayoth #include "argument.hpp"
20cf06ccdcSNan Zhou #include "certificate.hpp"
21cfbc8dc8SJayanth Othayoth #include "certs_manager.hpp"
220aa0d114SJayanth Othayoth
23014be0bfSNan Zhou #include <systemd/sd-event.h>
24014be0bfSNan Zhou
25014be0bfSNan Zhou #include <sdbusplus/bus.hpp>
26014be0bfSNan Zhou #include <sdbusplus/server/manager.hpp>
27f4682712SMarri Devender Rao #include <sdeventplus/event.hpp>
28*223e4604SPatrick Williams
29*223e4604SPatrick Williams #include <cctype>
300aa0d114SJayanth Othayoth #include <string>
31014be0bfSNan Zhou #include <utility>
320aa0d114SJayanth Othayoth
capitalize(const std::string & s)33cf06ccdcSNan Zhou inline std::string capitalize(const std::string& s)
34cfbc8dc8SJayanth Othayoth {
35cf06ccdcSNan Zhou std::string res = s;
36cf06ccdcSNan Zhou if (!res.empty())
37cf06ccdcSNan Zhou {
38cf06ccdcSNan Zhou res[0] = std::toupper(res[0]);
39cf06ccdcSNan Zhou }
40cf06ccdcSNan Zhou return res;
41cfbc8dc8SJayanth Othayoth }
42cfbc8dc8SJayanth Othayoth
main(int argc,char ** argv)430aa0d114SJayanth Othayoth int main(int argc, char** argv)
440aa0d114SJayanth Othayoth {
457047be67SNan Zhou phosphor::certs::Arguments arguments;
467047be67SNan Zhou if (phosphor::certs::processArguments(argc, argv, arguments) != 0)
470aa0d114SJayanth Othayoth {
487047be67SNan Zhou std::exit(EXIT_FAILURE);
490aa0d114SJayanth Othayoth }
500aa0d114SJayanth Othayoth
51cfbc8dc8SJayanth Othayoth auto bus = sdbusplus::bus::new_default();
527047be67SNan Zhou auto objPath = std::string(objectNamePrefix) + '/' + arguments.typeStr +
537047be67SNan Zhou '/' + arguments.endpoint;
546ceec40bSMarri Devender Rao // Add sdbusplus ObjectManager
55b3dbfb37SPatrick Williams sdbusplus::server::manager_t objManager(bus, objPath.c_str());
566ceec40bSMarri Devender Rao
57f4682712SMarri Devender Rao // Get default event loop
58f4682712SMarri Devender Rao auto event = sdeventplus::Event::get_default();
59f4682712SMarri Devender Rao
60f4682712SMarri Devender Rao // Attach the bus to sd_event to service user requests
61f4682712SMarri Devender Rao bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
627047be67SNan Zhou phosphor::certs::Manager manager(
637047be67SNan Zhou bus, event, objPath.c_str(),
647047be67SNan Zhou phosphor::certs::stringToCertificateType(arguments.typeStr),
657047be67SNan Zhou arguments.unit, arguments.path);
66cfbc8dc8SJayanth Othayoth
67cfbc8dc8SJayanth Othayoth // Adjusting Interface name as per std convention
687047be67SNan Zhou auto busName = std::string(busNamePrefix) + '.' +
697047be67SNan Zhou capitalize(arguments.typeStr) + '.' +
707047be67SNan Zhou capitalize(arguments.endpoint);
71cfbc8dc8SJayanth Othayoth bus.request_name(busName.c_str());
72f4682712SMarri Devender Rao event.loop();
730aa0d114SJayanth Othayoth return 0;
740aa0d114SJayanth Othayoth }
75