⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.10
Server IP:
157.245.101.34
Server:
Linux skvinfotech-website 5.4.0-131-generic #147-Ubuntu SMP Fri Oct 14 17:07:22 UTC 2022 x86_64
Server Software:
Apache/2.4.41 (Ubuntu)
PHP Version:
7.4.33
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
proc
/
self
/
root
/
usr
/
share
/
gtk-doc
/
html
/
gobject
/
View File Name :
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>Implementing interfaces: GObject Reference Manual</title> <meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> <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="howto-interface-prerequisite.html" title="Interface definition prerequisites"> <meta name="generator" content="GTK-Doc V1.32 (XML mode)"> <link rel="stylesheet" href="style.css" type="text/css"> </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="5"><tr valign="middle"> <td width="100%" align="left" class="shortcuts"></td> <td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td> <td><a accesskey="u" href="howto-interface.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td> <td><a accesskey="p" href="howto-interface.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td> <td><a accesskey="n" href="howto-interface-prerequisite.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td> </tr></table> <div class="sect1"> <div class="titlepage"><div><div><h2 class="title" style="clear: both"> <a name="howto-interface-implement"></a>Implementing interfaces</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 final GObject class exactly as in <a class="xref" href="howto-gobject.html#howto-gobject-header" title="Boilerplate header code">the section called “Boilerplate header code”</a>. </p> <p> The second step is to implement <span class="type">ViewerFile</span> by defining it using <code class="function"><a class="link" href="gobject-Type-Information.html#G-DEFINE-TYPE-WITH-CODE:CAPS" title="G_DEFINE_TYPE_WITH_CODE()">G_DEFINE_TYPE_WITH_CODE</a></code> and <code class="function"><a class="link" href="gobject-Type-Information.html#G-IMPLEMENT-INTERFACE:CAPS" title="G_IMPLEMENT_INTERFACE()">G_IMPLEMENT_INTERFACE</a></code> instead of <code class="function"><a class="link" href="gobject-Type-Information.html#G-DEFINE-TYPE:CAPS" title="G_DEFINE_TYPE()">G_DEFINE_TYPE</a></code>: </p> <div class="informalexample"> <table class="listing_frame" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td class="listing_lines" align="right"><pre>1 2 3 4 5</pre></td> <td class="listing_code"><pre class="programlisting"><span class="k">static</span> <span class="kt">void</span> <span class="nf">viewer_file_editable_interface_init</span> <span class="p">(</span><span class="n">ViewerEditableInterface</span> <span class="o">*</span><span class="n">iface</span><span class="p">);</span> <span class="n">G_DEFINE_TYPE_WITH_CODE</span> <span class="p">(</span><span class="n">ViewerFile</span><span class="p">,</span> <span class="n">viewer_file</span><span class="p">,</span> <span class="n">G_TYPE_OBJECT</span><span class="p">,</span> <span class="n">G_IMPLEMENT_INTERFACE</span> <span class="p">(</span><span class="n">VIEWER_TYPE_EDITABLE</span><span class="p">,</span> <span class="n">viewer_file_editable_interface_init</span><span class="p">))</span></pre></td> </tr> </tbody> </table> </div> <p> This definition is very much like all the similar functions seen previously. The only interface-specific code present here is the use of <code class="function"><a class="link" href="gobject-Type-Information.html#G-IMPLEMENT-INTERFACE:CAPS" title="G_IMPLEMENT_INTERFACE()">G_IMPLEMENT_INTERFACE</a></code>. </p> <div class="note"><p>Classes can implement multiple interfaces by using multiple calls to <code class="function"><a class="link" href="gobject-Type-Information.html#G-IMPLEMENT-INTERFACE:CAPS" title="G_IMPLEMENT_INTERFACE()">G_IMPLEMENT_INTERFACE</a></code> inside the call to <code class="function"><a class="link" href="gobject-Type-Information.html#G-DEFINE-TYPE-WITH-CODE:CAPS" title="G_DEFINE_TYPE_WITH_CODE()">G_DEFINE_TYPE_WITH_CODE</a></code> </p></div> <p> <code class="function">viewer_file_editable_interface_init</code>, the interface initialization function: inside it every virtual method of the interface must be assigned to its implementation: </p> <div class="informalexample"> <table class="listing_frame" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td class="listing_lines" align="right"><pre>1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37</pre></td> <td class="listing_code"><pre class="programlisting"><span class="k">static</span> <span class="kt">void</span> <span class="nf">viewer_file_editable_save</span> <span class="p">(</span><span class="n">ViewerFile</span> <span class="o">*</span><span class="n">self</span><span class="p">,</span> <span class="n">GError</span> <span class="o">**</span><span class="n">error</span><span class="p">)</span> <span class="p">{</span> <span class="n">g_print</span> <span class="p">(</span><span class="s">"File implementation of editable interface save method: %s.</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">self</span><span class="o">-></span><span class="n">filename</span><span class="p">);</span> <span class="p">}</span> <span class="k">static</span> <span class="kt">void</span> <span class="nf">viewer_file_editable_undo</span> <span class="p">(</span><span class="n">ViewerFile</span> <span class="o">*</span><span class="n">self</span><span class="p">,</span> <span class="n">guint</span> <span class="n">n_steps</span><span class="p">)</span> <span class="p">{</span> <span class="n">g_print</span> <span class="p">(</span><span class="s">"File implementation of editable interface undo method: %s.</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">self</span><span class="o">-></span><span class="n">filename</span><span class="p">);</span> <span class="p">}</span> <span class="k">static</span> <span class="kt">void</span> <span class="nf">viewer_file_editable_redo</span> <span class="p">(</span><span class="n">ViewerFile</span> <span class="o">*</span><span class="n">self</span><span class="p">,</span> <span class="n">guint</span> <span class="n">n_steps</span><span class="p">)</span> <span class="p">{</span> <span class="n">g_print</span> <span class="p">(</span><span class="s">"File implementation of editable interface redo method: %s.</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">self</span><span class="o">-></span><span class="n">filename</span><span class="p">);</span> <span class="p">}</span> <span class="k">static</span> <span class="kt">void</span> <span class="nf">viewer_file_editable_interface_init</span> <span class="p">(</span><span class="n">ViewerEditableInterface</span> <span class="o">*</span><span class="n">iface</span><span class="p">)</span> <span class="p">{</span> <span class="n">iface</span><span class="o">-></span><span class="n">save</span> <span class="o">=</span> <span class="n">viewer_file_editable_save</span><span class="p">;</span> <span class="n">iface</span><span class="o">-></span><span class="n">undo</span> <span class="o">=</span> <span class="n">viewer_file_editable_undo</span><span class="p">;</span> <span class="n">iface</span><span class="o">-></span><span class="n">redo</span> <span class="o">=</span> <span class="n">viewer_file_editable_redo</span><span class="p">;</span> <span class="p">}</span> <span class="k">static</span> <span class="kt">void</span> <span class="nf">viewer_file_init</span> <span class="p">(</span><span class="n">ViewerFile</span> <span class="o">*</span><span class="n">self</span><span class="p">)</span> <span class="p">{</span> <span class="cm">/* Instance variable initialisation code. */</span> <span class="p">}</span></pre></td> </tr> </tbody> </table> </div> <p> </p> <p> If the object is not of final type, e.g. was declared using <code class="function"><a class="link" href="gobject-Type-Information.html#G-DECLARE-DERIVABLE-TYPE:CAPS" title="G_DECLARE_DERIVABLE_TYPE()">G_DECLARE_DERIVABLE_TYPE</a></code> then <code class="function"><a class="link" href="gobject-Type-Information.html#G-ADD-PRIVATE:CAPS" title="G_ADD_PRIVATE()">G_ADD_PRIVATE</a></code> macro should be added. The private structure should be declared exactly as for a normal derivable object, see <a class="xref" href="howto-gobject-code.html" title="Boilerplate code">the section called “Boilerplate code”</a>. </p> <div class="informalexample"> <table class="listing_frame" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td class="listing_lines" align="right"><pre>1 2 3 4</pre></td> <td class="listing_code"><pre class="programlisting"><span class="n">G_DEFINE_TYPE_WITH_CODE</span> <span class="p">(</span><span class="n">ViewerFile</span><span class="p">,</span> <span class="n">viewer_file</span><span class="p">,</span> <span class="n">G_TYPE_OBJECT</span><span class="p">,</span> <span class="n">G_ADD_PRIVATE</span> <span class="p">(</span><span class="n">ViewerFile</span><span class="p">)</span> <span class="n">G_IMPLEMENT_INTERFACE</span> <span class="p">(</span><span class="n">VIEWER_TYPE_EDITABLE</span><span class="p">,</span> <span class="n">viewer_file_editable_interface_init</span><span class="p">))</span></pre></td> </tr> </tbody> </table> </div> <p> </p> </div> <div class="footer"> <hr>Generated by GTK-Doc V1.32</div> </body> </html>