OLD | NEW |
1 {{+bindTo:partials.standard_nacl_article}} | 1 {{+bindTo:partials.standard_nacl_article}} |
2 | 2 |
3 <section id="native-client-modules"> | 3 <section id="native-client-modules"> |
4 <span id="devcycle-native-client-modules"></span><h1 id="native-client-modules">
<span id="devcycle-native-client-modules"></span>Native Client Modules</h1> | 4 <span id="devcycle-native-client-modules"></span><h1 id="native-client-modules">
<span id="devcycle-native-client-modules"></span>Native Client Modules</h1> |
5 <p>This document describes the classes and functions that you need to implement
in | 5 <p>This document describes the classes and functions that you need to implement
in |
6 a Native Client module in order for Chrome to load, initialize, and run it. The | 6 a Native Client module in order for Chrome to load, initialize, and run it. The |
7 requirements are the same regardless of whether or not the module uses PNaCl, | 7 requirements are the same regardless of whether or not the module uses PNaCl, |
8 but depend on whether the module is written in C or C++.</p> | 8 but depend on whether the module is written in C or C++.</p> |
9 <div class="contents local" id="contents" style="display: none"> | 9 <div class="contents local" id="contents" style="display: none"> |
10 <ul class="small-gap"> | 10 <ul class="small-gap"> |
11 <li><a class="reference internal" href="#introduction" id="id2">Introduction</a>
</li> | 11 <li><a class="reference internal" href="#introduction" id="id2">Introduction</a>
</li> |
12 <li><a class="reference internal" href="#writing-modules-in-c" id="id3">Writing
modules in C</a></li> | 12 <li><a class="reference internal" href="#writing-modules-in-c" id="id3">Writing
modules in C</a></li> |
13 <li><a class="reference internal" href="#id1" id="id4">Writing modules in C++</a
></li> | 13 <li><a class="reference internal" href="#id1" id="id4">Writing modules in C++</a
></li> |
14 </ul> | 14 </ul> |
15 | 15 |
16 </div><section id="introduction"> | 16 </div><h2 id="introduction">Introduction</h2> |
17 <h2 id="introduction">Introduction</h2> | |
18 <p>Native Client modules do not have a <code>main()</code> function. When a modu
le loads, | 17 <p>Native Client modules do not have a <code>main()</code> function. When a modu
le loads, |
19 the Native Client runtime calls the code in the module to create an instance and | 18 the Native Client runtime calls the code in the module to create an instance and |
20 initialize the interfaces for the APIs the module uses. This initialization | 19 initialize the interfaces for the APIs the module uses. This initialization |
21 sequence depends on whether the module is written in C or C++ and requires that | 20 sequence depends on whether the module is written in C or C++ and requires that |
22 you implement specific functions in each case.</p> | 21 you implement specific functions in each case.</p> |
23 </section><section id="writing-modules-in-c"> | |
24 <h2 id="writing-modules-in-c">Writing modules in C</h2> | 22 <h2 id="writing-modules-in-c">Writing modules in C</h2> |
25 <p>The C API uses a prefix convention to show whether an interface is implemente
d | 23 <p>The C API uses a prefix convention to show whether an interface is implemente
d |
26 in the browser or in a module. Interfaces starting with <code>PPB_</code> (which
can be | 24 in the browser or in a module. Interfaces starting with <code>PPB_</code> (which
can be |
27 read as “Pepper <em>browser</em>”) are implemented in the browser an
d they are called | 25 read as “Pepper <em>browser</em>”) are implemented in the browser an
d they are called |
28 from your module. Interfaces starting with <code>PPP_</code> (“Pepper <em>
plugin</em>”) are | 26 from your module. Interfaces starting with <code>PPP_</code> (“Pepper <em>
plugin</em>”) are |
29 implemented in the module; they are called from the browser and will execute on | 27 implemented in the module; they are called from the browser and will execute on |
30 the main thread of the module instance.</p> | 28 the main thread of the module instance.</p> |
31 <p>When you implement a Native Client module in C you must include these compone
nts:</p> | 29 <p>When you implement a Native Client module in C you must include these compone
nts:</p> |
32 <ul class="small-gap"> | 30 <ul class="small-gap"> |
33 <li>The functions <code>PPP_InitializeModule</code> and <code>PPP_GetInterface</
code></li> | 31 <li>The functions <code>PPP_InitializeModule</code> and <code>PPP_GetInterface</
code></li> |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 } | 102 } |
105 | 103 |
106 // Define PPP_InitializeModule, the entry point of your module. | 104 // Define PPP_InitializeModule, the entry point of your module. |
107 // Retrieve the API for the browser-side (PPB) interfaces you will use. | 105 // Retrieve the API for the browser-side (PPB) interfaces you will use. |
108 PP_EXPORT int32_t PPP_InitializeModule(PP_Module a_module_id, PPB_GetInterface g
et_browser) { | 106 PP_EXPORT int32_t PPP_InitializeModule(PP_Module a_module_id, PPB_GetInterface g
et_browser) { |
109 ppb_instance_interface = (PPB_Instance*)(get_browser(PPB_INSTANCE_INTERF
ACE)); | 107 ppb_instance_interface = (PPB_Instance*)(get_browser(PPB_INSTANCE_INTERF
ACE)); |
110 ppb_input_event_interface = (PPB_InputEvent*)(get_browser(PPB_INPUT_EVEN
T_INTERFACE)); | 108 ppb_input_event_interface = (PPB_InputEvent*)(get_browser(PPB_INPUT_EVEN
T_INTERFACE)); |
111 return PP_OK; | 109 return PP_OK; |
112 } | 110 } |
113 </pre> | 111 </pre> |
114 </section><section id="id1"> | |
115 <h2 id="id1">Writing modules in C++</h2> | 112 <h2 id="id1">Writing modules in C++</h2> |
116 <p>When you implement a Native Client module in C++ you must include these compo
nents:</p> | 113 <p>When you implement a Native Client module in C++ you must include these compo
nents:</p> |
117 <ul class="small-gap"> | 114 <ul class="small-gap"> |
118 <li>The factory function called <code>CreateModule()</code></li> | 115 <li>The factory function called <code>CreateModule()</code></li> |
119 <li>Code that defines your own Module class (derived from the <code>pp::Module</
code> | 116 <li>Code that defines your own Module class (derived from the <code>pp::Module</
code> |
120 class)</li> | 117 class)</li> |
121 <li>Code that defines your own Instance class (derived from the <code>pp:Instanc
e</code> | 118 <li>Code that defines your own Instance class (derived from the <code>pp:Instanc
e</code> |
122 class)</li> | 119 class)</li> |
123 </ul> | 120 </ul> |
124 <p>In the “Hello tutorial” example (in the <code>getting_started/par
t1</code> directory of | 121 <p>In the “Hello tutorial” example (in the <code>getting_started/par
t1</code> directory of |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 an implementation of the <code>HandleMessage()</code> function. The browser call
s an | 163 an implementation of the <code>HandleMessage()</code> function. The browser call
s an |
167 instance’s <code>HandleMessage()</code> function every time the JavaScript
code in an | 164 instance’s <code>HandleMessage()</code> function every time the JavaScript
code in an |
168 application calls <code>postMessage()</code> to send a message to the instance.
See the | 165 application calls <code>postMessage()</code> to send a message to the instance.
See the |
169 <a class="reference internal" href="/native-client/devguide/coding/message-syste
m.html"><em>Native Client messaging system</em></a> for more information about | 166 <a class="reference internal" href="/native-client/devguide/coding/message-syste
m.html"><em>Native Client messaging system</em></a> for more information about |
170 how to send messages between JavaScript code and Native Client modules.</p> | 167 how to send messages between JavaScript code and Native Client modules.</p> |
171 <p>While the <code>CreateModule()</code> factory function, the <code>Module</cod
e> class, and the | 168 <p>While the <code>CreateModule()</code> factory function, the <code>Module</cod
e> class, and the |
172 <code>Instance</code> class are required for a Native Client application, the co
de | 169 <code>Instance</code> class are required for a Native Client application, the co
de |
173 samples shown above don’t actually do anything. Subsequent documents in th
e | 170 samples shown above don’t actually do anything. Subsequent documents in th
e |
174 Developer’s Guide build on these code samples and add more interesting | 171 Developer’s Guide build on these code samples and add more interesting |
175 functionality.</p> | 172 functionality.</p> |
176 </section></section> | 173 </section> |
177 | 174 |
178 {{/partials.standard_nacl_article}} | 175 {{/partials.standard_nacl_article}} |
OLD | NEW |