| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_DBUS_DBUS_H_ |
| 6 #define NET_DBUS_DBUS_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 #include <vector> |
| 11 #include <dbus/dbus.h> |
| 12 |
| 13 #include "base/callback.h" |
| 14 #include "base/values.h" |
| 15 |
| 16 namespace net { |
| 17 namespace dbus { |
| 18 |
| 19 class ObjectProxy; |
| 20 |
| 21 // ... |
| 22 class Bus { |
| 23 public: |
| 24 enum Type { |
| 25 SESSION = DBUS_BUS_SESSION, |
| 26 SYSTEM = DBUS_BUS_SYSTEM, |
| 27 }; |
| 28 |
| 29 Bus(Type type); |
| 30 ~Bus(); |
| 31 |
| 32 ObjectProxy* GetObjectProxy(const std::string& service_name, |
| 33 const std::string& object_path); |
| 34 |
| 35 |
| 36 private: |
| 37 friend class ObjectProxy; |
| 38 DBusConnection* connection() { return connection_; } |
| 39 |
| 40 // This needs to be delayed until the first method call. |
| 41 // |
| 42 bool Init(); |
| 43 |
| 44 int type_; |
| 45 DBusConnection* connection_; |
| 46 DISALLOW_COPY_AND_ASSIGN(Bus); |
| 47 }; |
| 48 |
| 49 class MessageBuilder; |
| 50 class MessageReader; |
| 51 |
| 52 class Message { |
| 53 public: |
| 54 Message(); |
| 55 ~Message(); |
| 56 |
| 57 DBusMessage* raw_message() { return raw_message_; } |
| 58 // transfer... |
| 59 void reset_raw_message(DBusMessage* raw_message); |
| 60 |
| 61 private: |
| 62 DBusMessage* raw_message_; |
| 63 DISALLOW_COPY_AND_ASSIGN(Message); |
| 64 }; |
| 65 |
| 66 class MethodCall : public Message { |
| 67 public: |
| 68 MethodCall(); |
| 69 |
| 70 private: |
| 71 DISALLOW_COPY_AND_ASSIGN(MethodCall); |
| 72 }; |
| 73 |
| 74 class Response : public Message { |
| 75 public: |
| 76 Response(); |
| 77 |
| 78 private: |
| 79 DISALLOW_COPY_AND_ASSIGN(Response); |
| 80 }; |
| 81 |
| 82 class MessageBuilder { |
| 83 public: |
| 84 MessageBuilder(Message* message); |
| 85 ~MessageBuilder(); |
| 86 |
| 87 void AppendByte(uint8 value); |
| 88 void AppendBool(bool value); |
| 89 void AppendInt16(int16 value); |
| 90 void AppendUint16(uint16 value); |
| 91 void AppendInt32(int32 value); |
| 92 void AppendUint32(uint32 value); |
| 93 void AppendInt64(int64 value); |
| 94 void AppendUint64(uint64 value); |
| 95 void AppendDouble(double value); |
| 96 void AppendString(const std::string& value); |
| 97 void AppendObjectPath(const std::string& value); |
| 98 // Add support for ARRAY, STRUCT, DICT_ENTRY, VARIANT as needed. |
| 99 |
| 100 private: |
| 101 Message* message_; |
| 102 DBusMessageIter raw_message_iter_; |
| 103 |
| 104 DISALLOW_COPY_AND_ASSIGN(MessageBuilder); |
| 105 }; |
| 106 |
| 107 class MessageReader { |
| 108 public: |
| 109 MessageReader(Message* message); |
| 110 ~MessageReader(); |
| 111 // |
| 112 // while (reader.HasMore()) |
| 113 // reader.PopString(&foo); |
| 114 bool HasMore(); |
| 115 |
| 116 bool PopByte(uint8* value); |
| 117 bool PopBool(bool* value); |
| 118 bool PopInt16(int16* value); |
| 119 bool PopUint16(uint16* value); |
| 120 bool PopInt32(int32* value); |
| 121 bool PopUint32(uint32* value); |
| 122 bool PopInt64(int64* value); |
| 123 bool PopUint64(uint64* value); |
| 124 bool PopDouble(double* value); |
| 125 bool PopString(std::string* value); |
| 126 bool PopObjectPath(std::string* value); |
| 127 // Add support for dbus_message_iter_get_fixed_array() when needed. |
| 128 |
| 129 // ... |
| 130 bool PopArray(MessageReader* sub_reader); |
| 131 bool PopStruct(MessageReader* sub_reader); |
| 132 bool PopDictEntry(MessageReader* sub_reader); |
| 133 bool PopVariant(MessageReader* sub_reader); |
| 134 |
| 135 // ... |
| 136 bool PopArrayOfObjectPaths(std::vector<std::string>* object_paths); |
| 137 |
| 138 bool PopVariantOfByte(uint8* value); |
| 139 bool PopVariantOfBool(bool* value); |
| 140 bool PopVariantOfInt16(int16* value); |
| 141 bool PopVariantOfUint16(uint16* value); |
| 142 bool PopVariantOfInt32(int32* value); |
| 143 bool PopVariantOfUint32(uint32* value); |
| 144 bool PopVariantOfInt64(int64* value); |
| 145 bool PopVariantOfUint64(uint64* value); |
| 146 bool PopVariantOfDouble(double* value); |
| 147 bool PopVariantOfString(std::string* value); |
| 148 bool PopVariantOfObjectPath(std::string* value); |
| 149 |
| 150 private: |
| 151 bool CheckType(int dbus_type); |
| 152 bool PopBasic(int dbus_type, void *value); |
| 153 bool PopContainer(int dbus_type, MessageReader* sub_reader); |
| 154 bool PopVariantOfBasic(int dbus_type, void* value); |
| 155 |
| 156 |
| 157 Message* message_; |
| 158 DBusMessageIter raw_message_iter_; |
| 159 |
| 160 DISALLOW_COPY_AND_ASSIGN(MessageReader); |
| 161 }; |
| 162 |
| 163 class ObjectProxy { |
| 164 public: |
| 165 ~ObjectProxy(); |
| 166 |
| 167 typedef base::Callback<void(Response*)> ResponseCallback; |
| 168 |
| 169 // request is mutable as .... |
| 170 bool CallMethodSync(const std::string interface_name, |
| 171 const std::string method_name, |
| 172 MethodCall* request, |
| 173 Response* response); |
| 174 |
| 175 // TODO(satorux): Implement this. |
| 176 // request is mutable as .... |
| 177 bool CallMethodAsync(const std::string interface_name, |
| 178 const std::string method_name, |
| 179 MethodCall* request, |
| 180 ResponseCallback callback); |
| 181 |
| 182 private: |
| 183 friend class Bus; |
| 184 |
| 185 ObjectProxy(Bus* bus, |
| 186 const std::string& service_name, |
| 187 const std::string& object_path); |
| 188 |
| 189 Bus* bus_; |
| 190 std::string service_name_; |
| 191 std::string object_path_; |
| 192 |
| 193 DISALLOW_COPY_AND_ASSIGN(ObjectProxy); |
| 194 }; |
| 195 |
| 196 } // namespace dbus |
| 197 } // namespace net |
| 198 |
| 199 #endif // NET_DBUS_DBUS_H_ |
| OLD | NEW |