11.01.2014 Views

Black-box composition of mismatched software components

Black-box composition of mismatched software components

Black-box composition of mismatched software components

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 5. Evaluating the Cake language 141<br />

values (embed: EphyBaseEmbed,<br />

history : EphyHistory) ←→<br />

{ /∗ ... ∗/ }<br />

(web view: WebKitWebView,<br />

scrolled window: GtkScrolledWindow,<br />

load state: WebKitEmbedLoadState,<br />

loading uri: char [])<br />

Figure 5.15: Associating corresponding objects in Cake<br />

struct WebKitEmbed { // from webkit-embed.h line 56<br />

EphyBaseEmbed parent instance;<br />

/∗< private >∗/<br />

WebKitEmbedPrivate ∗priv;<br />

};<br />

struct WebKitEmbedPrivate // from webkit-embed.c line 65<br />

{<br />

WebKitWebView ∗web view;<br />

GtkScrolledWindow ∗scrolled window;<br />

WebKitEmbedLoadState load state;<br />

char ∗loading uri;<br />

EphyHistory ∗history;<br />

};<br />

Figure 5.16: Subclassing-like containment and pointer-based association in C<br />

a pointer to the subordinate object, but associatively, by maintaining references in the<br />

table implementing the co-object relation (§4.4.1).<br />

Instantiation These rules present a complication: how do we ensure that the Epiphany<br />

client binary, which was compiled to instantiate and manipulate instances <strong>of</strong> some subclass,<br />

will instead instantiate and manipulate this association state using the logic in our<br />

Cake rules? This requires a combination <strong>of</strong> interposing on instantiation <strong>of</strong> state and interposing<br />

onaccess to that state. As <strong>of</strong>teninCake programming, more thanonemix <strong>of</strong> these<br />

two tactics can lead to a viable solution. We can choose not to interpose directly, instead<br />

relying on the behaviour that an EphyBaseEmbed object will be a subobject instantiated<br />

within some enclosing object. The form <strong>of</strong> this enclosing object will be determined by<br />

whatever alternative HTML rendering library the client binary was compiled against (the<br />

Mozilla renderer in our case). Such an object is nevertheless usable—its EphyBaseEmbed<br />

subobject will be used as is, and its extra fields from the containing object will go unused.<br />

5.6.2 Method dispatch<br />

We must next make sure that calling code calls through our dispatch table (created in the<br />

Cake code with an instantiate helper invocation, not shown). In the GObject library, the<br />

dispatch table is located by a complex sequence <strong>of</strong> steps—by library calls which access

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!