Brad Bishop | 62ece2b | 2016-07-25 09:00:51 -0400 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2016 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #include <string.h> |
| 17 | #include <systemd/sd-bus.h> |
| 18 | #include "mapper.h" |
| 19 | |
| 20 | int mapper_get_service(sd_bus *conn, const char *obj, char **service) |
| 21 | { |
| 22 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 23 | sd_bus_message *request = NULL, *reply = NULL; |
| 24 | const char *tmp; |
| 25 | int r; |
| 26 | |
| 27 | r = sd_bus_message_new_method_call( |
| 28 | conn, |
| 29 | &request, |
| 30 | "org.openbmc.ObjectMapper", |
| 31 | "/org/openbmc/ObjectMapper", |
| 32 | "org.openbmc.ObjectMapper", |
| 33 | "GetObject"); |
| 34 | if (r < 0) |
| 35 | goto exit; |
| 36 | |
| 37 | r = sd_bus_message_append(request, "s", obj); |
| 38 | if (r < 0) |
| 39 | goto exit; |
| 40 | |
| 41 | r = sd_bus_call(conn, request, 0, &error, &reply); |
| 42 | if (r < 0) |
| 43 | goto exit; |
| 44 | |
| 45 | r = sd_bus_message_enter_container(reply, 0, NULL); |
| 46 | if (r < 0) |
| 47 | goto exit; |
| 48 | |
| 49 | r = sd_bus_message_enter_container(reply, 0, NULL); |
| 50 | if (r < 0) |
| 51 | goto exit; |
| 52 | |
| 53 | r = sd_bus_message_read(reply, "s", &tmp); |
| 54 | if (r < 0) |
| 55 | goto exit; |
| 56 | |
| 57 | *service = strdup(tmp); |
| 58 | |
| 59 | exit: |
| 60 | sd_bus_error_free(&error); |
| 61 | sd_bus_message_unref(request); |
| 62 | sd_bus_message_unref(reply); |
| 63 | |
| 64 | return r; |
| 65 | } |