Back to index

unity  6.0.0
Introspectable.h
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2010 Canonical Ltd
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 3 as
00007  * published by the Free Software Foundation.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  *
00017  * Authored by: Alex Launi <alex.launi@canonical.com>
00018  */
00019 
00020 #ifndef _INTROSPECTABLE_H
00021 #define _INTROSPECTABLE_H
00022 
00023 #include <glib.h>
00024 #include <list>
00025 #include <string>
00026 
00027 namespace unity
00028 {
00029 namespace debug
00030 {
00031 class Introspectable
00032 {
00033 public:
00034   typedef std::list<Introspectable*> IntrospectableList;
00035 
00036   Introspectable();
00037   virtual ~Introspectable();
00038   GVariant* Introspect();
00039   virtual std::string GetName() const = 0;
00040   void AddChild(Introspectable* child);
00041   void RemoveChild(Introspectable* child);
00042   virtual void AddProperties(GVariantBuilder* builder) = 0;
00043   virtual IntrospectableList GetIntrospectableChildren();
00044   guint64 GetIntrospectionId() const;
00045 
00046 protected:
00049   virtual std::string GetChildsName() const;
00050 
00051   /*
00052    * AddProperties should be implemented as such ...
00053    * void ClassFoo::AddProperties (GVariantBuilder *builder)
00054    * {
00055    *  unity::variant::BuilderWrapper wrapper(builder);
00056    *  wrapper.add("label", some_value);
00057    * }
00058    * That's all. Just add a bunch of key-value properties to the builder.
00059    */
00060 
00061 private:
00062   std::list<Introspectable*> _children;
00063   std::list<Introspectable*> _parents;
00064   guint64 _id;
00065 };
00066 }
00067 }
00068 #endif