Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(460)

Unified Diff: net/dbus/dbus.h

Issue 7413004: Uploading for backup... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/dbus/dbus.h
diff --git a/net/dbus/dbus.h b/net/dbus/dbus.h
new file mode 100644
index 0000000000000000000000000000000000000000..d3b4d9246d5f16b47092c12aa8c4c4fca0aba021
--- /dev/null
+++ b/net/dbus/dbus.h
@@ -0,0 +1,199 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_DBUS_DBUS_H_
+#define NET_DBUS_DBUS_H_
+#pragma once
+
+#include <string>
+#include <vector>
+#include <dbus/dbus.h>
+
+#include "base/callback.h"
+#include "base/values.h"
+
+namespace net {
+namespace dbus {
+
+class ObjectProxy;
+
+// ...
+class Bus {
+ public:
+ enum Type {
+ SESSION = DBUS_BUS_SESSION,
+ SYSTEM = DBUS_BUS_SYSTEM,
+ };
+
+ Bus(Type type);
+ ~Bus();
+
+ ObjectProxy* GetObjectProxy(const std::string& service_name,
+ const std::string& object_path);
+
+
+ private:
+ friend class ObjectProxy;
+ DBusConnection* connection() { return connection_; }
+
+ // This needs to be delayed until the first method call.
+ //
+ bool Init();
+
+ int type_;
+ DBusConnection* connection_;
+ DISALLOW_COPY_AND_ASSIGN(Bus);
+};
+
+class MessageBuilder;
+class MessageReader;
+
+class Message {
+ public:
+ Message();
+ ~Message();
+
+ DBusMessage* raw_message() { return raw_message_; }
+ // transfer...
+ void reset_raw_message(DBusMessage* raw_message);
+
+ private:
+ DBusMessage* raw_message_;
+ DISALLOW_COPY_AND_ASSIGN(Message);
+};
+
+class MethodCall : public Message {
+ public:
+ MethodCall();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MethodCall);
+};
+
+class Response : public Message {
+ public:
+ Response();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Response);
+};
+
+class MessageBuilder {
+ public:
+ MessageBuilder(Message* message);
+ ~MessageBuilder();
+
+ void AppendByte(uint8 value);
+ void AppendBool(bool value);
+ void AppendInt16(int16 value);
+ void AppendUint16(uint16 value);
+ void AppendInt32(int32 value);
+ void AppendUint32(uint32 value);
+ void AppendInt64(int64 value);
+ void AppendUint64(uint64 value);
+ void AppendDouble(double value);
+ void AppendString(const std::string& value);
+ void AppendObjectPath(const std::string& value);
+ // Add support for ARRAY, STRUCT, DICT_ENTRY, VARIANT as needed.
+
+ private:
+ Message* message_;
+ DBusMessageIter raw_message_iter_;
+
+ DISALLOW_COPY_AND_ASSIGN(MessageBuilder);
+};
+
+class MessageReader {
+ public:
+ MessageReader(Message* message);
+ ~MessageReader();
+ //
+ // while (reader.HasMore())
+ // reader.PopString(&foo);
+ bool HasMore();
+
+ bool PopByte(uint8* value);
+ bool PopBool(bool* value);
+ bool PopInt16(int16* value);
+ bool PopUint16(uint16* value);
+ bool PopInt32(int32* value);
+ bool PopUint32(uint32* value);
+ bool PopInt64(int64* value);
+ bool PopUint64(uint64* value);
+ bool PopDouble(double* value);
+ bool PopString(std::string* value);
+ bool PopObjectPath(std::string* value);
+ // Add support for dbus_message_iter_get_fixed_array() when needed.
+
+ // ...
+ bool PopArray(MessageReader* sub_reader);
+ bool PopStruct(MessageReader* sub_reader);
+ bool PopDictEntry(MessageReader* sub_reader);
+ bool PopVariant(MessageReader* sub_reader);
+
+ // ...
+ bool PopArrayOfObjectPaths(std::vector<std::string>* object_paths);
+
+ bool PopVariantOfByte(uint8* value);
+ bool PopVariantOfBool(bool* value);
+ bool PopVariantOfInt16(int16* value);
+ bool PopVariantOfUint16(uint16* value);
+ bool PopVariantOfInt32(int32* value);
+ bool PopVariantOfUint32(uint32* value);
+ bool PopVariantOfInt64(int64* value);
+ bool PopVariantOfUint64(uint64* value);
+ bool PopVariantOfDouble(double* value);
+ bool PopVariantOfString(std::string* value);
+ bool PopVariantOfObjectPath(std::string* value);
+
+ private:
+ bool CheckType(int dbus_type);
+ bool PopBasic(int dbus_type, void *value);
+ bool PopContainer(int dbus_type, MessageReader* sub_reader);
+ bool PopVariantOfBasic(int dbus_type, void* value);
+
+
+ Message* message_;
+ DBusMessageIter raw_message_iter_;
+
+ DISALLOW_COPY_AND_ASSIGN(MessageReader);
+};
+
+class ObjectProxy {
+ public:
+ ~ObjectProxy();
+
+ typedef base::Callback<void(Response*)> ResponseCallback;
+
+ // request is mutable as ....
+ bool CallMethodSync(const std::string interface_name,
+ const std::string method_name,
+ MethodCall* request,
+ Response* response);
+
+ // TODO(satorux): Implement this.
+ // request is mutable as ....
+ bool CallMethodAsync(const std::string interface_name,
+ const std::string method_name,
+ MethodCall* request,
+ ResponseCallback callback);
+
+ private:
+ friend class Bus;
+
+ ObjectProxy(Bus* bus,
+ const std::string& service_name,
+ const std::string& object_path);
+
+ Bus* bus_;
+ std::string service_name_;
+ std::string object_path_;
+
+ DISALLOW_COPY_AND_ASSIGN(ObjectProxy);
+};
+
+} // namespace dbus
+} // namespace net
+
+#endif // NET_DBUS_DBUS_H_

Powered by Google App Engine
This is Rietveld 408576698