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 <cctype> 26014be0bfSNan Zhou #include <sdbusplus/bus.hpp> 27014be0bfSNan Zhou #include <sdbusplus/server/manager.hpp> 28f4682712SMarri Devender Rao #include <sdeventplus/event.hpp> 290aa0d114SJayanth Othayoth #include <string> 30014be0bfSNan Zhou #include <utility> 310aa0d114SJayanth Othayoth 32cf06ccdcSNan Zhou inline std::string capitalize(const std::string& s) 33cfbc8dc8SJayanth Othayoth { 34cf06ccdcSNan Zhou std::string res = s; 35cf06ccdcSNan Zhou if (!res.empty()) 36cf06ccdcSNan Zhou { 37cf06ccdcSNan Zhou res[0] = std::toupper(res[0]); 38cf06ccdcSNan Zhou } 39cf06ccdcSNan Zhou return res; 40cfbc8dc8SJayanth Othayoth } 41cfbc8dc8SJayanth Othayoth 420aa0d114SJayanth Othayoth int main(int argc, char** argv) 430aa0d114SJayanth Othayoth { 447047be67SNan Zhou phosphor::certs::Arguments arguments; 457047be67SNan Zhou if (phosphor::certs::processArguments(argc, argv, arguments) != 0) 460aa0d114SJayanth Othayoth { 477047be67SNan Zhou std::exit(EXIT_FAILURE); 480aa0d114SJayanth Othayoth } 490aa0d114SJayanth Othayoth 50cfbc8dc8SJayanth Othayoth auto bus = sdbusplus::bus::new_default(); 517047be67SNan Zhou auto objPath = std::string(objectNamePrefix) + '/' + arguments.typeStr + 527047be67SNan Zhou '/' + arguments.endpoint; 536ceec40bSMarri Devender Rao // Add sdbusplus ObjectManager 54*b3dbfb37SPatrick Williams sdbusplus::server::manager_t objManager(bus, objPath.c_str()); 556ceec40bSMarri Devender Rao 56f4682712SMarri Devender Rao // Get default event loop 57f4682712SMarri Devender Rao auto event = sdeventplus::Event::get_default(); 58f4682712SMarri Devender Rao 59f4682712SMarri Devender Rao // Attach the bus to sd_event to service user requests 60f4682712SMarri Devender Rao bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); 617047be67SNan Zhou phosphor::certs::Manager manager( 627047be67SNan Zhou bus, event, objPath.c_str(), 637047be67SNan Zhou phosphor::certs::stringToCertificateType(arguments.typeStr), 647047be67SNan Zhou arguments.unit, arguments.path); 65cfbc8dc8SJayanth Othayoth 66cfbc8dc8SJayanth Othayoth // Adjusting Interface name as per std convention 677047be67SNan Zhou auto busName = std::string(busNamePrefix) + '.' + 687047be67SNan Zhou capitalize(arguments.typeStr) + '.' + 697047be67SNan Zhou capitalize(arguments.endpoint); 70cfbc8dc8SJayanth Othayoth bus.request_name(busName.c_str()); 71f4682712SMarri Devender Rao event.loop(); 720aa0d114SJayanth Othayoth return 0; 730aa0d114SJayanth Othayoth } 74