| /* |
| // Copyright (c) 2019 Intel Corporation |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| */ |
| #include "post_code.hpp" |
| |
| #include <getopt.h> |
| |
| int main(int argc, char* argv[]) |
| { |
| PostCodeDataHolder* postcodeDataHolderObj = |
| postcodeDataHolderObj->getInstance(); |
| |
| int arg; |
| int optIndex = 0; |
| int ret = 0; |
| |
| std::string intfName; |
| |
| static struct option longOpts[] = {{"host", required_argument, 0, 'h'}, |
| {0, 0, 0, 0}}; |
| |
| while ((arg = getopt_long(argc, argv, "h:", longOpts, &optIndex)) != -1) |
| { |
| switch (arg) |
| { |
| case 'h': |
| postcodeDataHolderObj->node = std::stoi(optarg); |
| break; |
| default: |
| break; |
| } |
| } |
| |
| phosphor::logging::log<phosphor::logging::level::INFO>( |
| "Start post code manager service..."); |
| |
| sd_event* event = nullptr; |
| ret = sd_event_default(&event); |
| if (ret < 0) |
| { |
| phosphor::logging::log<phosphor::logging::level::ERR>( |
| "Error creating a default sd_event handler"); |
| return ret; |
| } |
| EventPtr eventP{event}; |
| event = nullptr; |
| |
| sdbusplus::bus::bus bus = sdbusplus::bus::new_default(); |
| sdbusplus::server::manager_t m{bus, DBUS_OBJECT_NAME}; |
| |
| if (postcodeDataHolderObj->node == 0) |
| { |
| intfName = DBUS_INTF_NAME; |
| } |
| else |
| { |
| intfName = DBUS_INTF_NAME + std::to_string(postcodeDataHolderObj->node); |
| } |
| |
| bus.request_name(intfName.c_str()); |
| |
| PostCode postCode{bus, DBUS_OBJECT_NAME, eventP}; |
| |
| try |
| { |
| bus.attach_event(eventP.get(), SD_EVENT_PRIORITY_NORMAL); |
| ret = sd_event_loop(eventP.get()); |
| if (ret < 0) |
| { |
| phosphor::logging::log<phosphor::logging::level::ERR>( |
| "Error occurred during the sd_event_loop", |
| phosphor::logging::entry("RET=%d", ret)); |
| } |
| } |
| catch (std::exception& e) |
| { |
| phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| return -1; |
| } |
| return 0; |
| } |