Skip to content

Commit

Permalink
[doc] fix #2 - document how to write an abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasMadsen committed Mar 1, 2012
1 parent 91747b3 commit e4071da
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions README.md
Expand Up @@ -52,7 +52,7 @@ var listener = thintalk({


The `lisenter` object must listen on something. this is done by calling the `.listen` The `lisenter` object must listen on something. this is done by calling the `.listen`
method. The first argument in the `.listen` method specify the layer the other arguments method. The first argument in the `.listen` method specify the layer the other arguments
are send to the layer handler. are send to the layer handler.


Note that you can call listen as many times as you want. Note that you can call listen as many times as you want.


Expand Down Expand Up @@ -88,7 +88,7 @@ lisenter.on('listening', function () {
}); });
``` ```


When a `requester` is connected to the `lisenter` object a `connection` event is emitted: When a `requester` is connected to the `lisenter` object a `connection` event is emitted:


```JavaScript ```JavaScript
lisenter.on('connection', function () { lisenter.on('connection', function () {
Expand All @@ -110,7 +110,7 @@ is found or an errors accoured.
```JavaScript ```JavaScript
lisenter.on('request', function (error, name, args, result) { lisenter.on('request', function (error, name, args, result) {
console.log('The function ' + name + ' was called with the arguments ' + args.join(', ')); console.log('The function ' + name + ' was called with the arguments ' + args.join(', '));

if (error !== null) { if (error !== null) {
console.log('But the function called failed:'); console.log('But the function called failed:');
console.error(error.stack); console.error(error.stack);
Expand Down Expand Up @@ -140,7 +140,7 @@ var requester = thintalk(function (remote) {
``` ```


You connect to the remote by using the `.connect` method. The API is the same with `.listen` the You connect to the remote by using the `.connect` method. The API is the same with `.listen` the
first argument specify the layer and the other arguments are send to the layer handler. first argument specify the layer and the other arguments are send to the layer handler.


To connect to a port using the the TCP layer: To connect to a port using the the TCP layer:


Expand Down Expand Up @@ -195,6 +195,30 @@ requester.on('connect', function (remote) {
}); });
``` ```


## Writeing a layer interface

There are two buildin layers `IPC` and `TCP`, they work very diffrent but use the same
API abstaction to create an RPC interface. You can find the layers in `/lib/layers`, they
are highly documented and should be easy to follow.

The general pattern is that there are three exported constructor functions, there inherts
from a abstraction object. You will find that there is a little diffrence between the buildin
layer and user layers. The buildin layers require an internal `core.js` module however you should
just require the `thinktalk` module. This module will exports `ListenerAbstract`, `CommunicationAbstract`
and `RequesterAbstract` just as the `core.js` module.

You will also need to use the `setLayer` function, this takes 2 arguments the first is the
`layer name` the second is export from the required user layer.

```JavaScript
var layer = require('layer');
var thintalk = require('thintalk');
thintalk.setLayer('layer', layer);
```

You can the use `lisenter.listen('layer', options ...)` and `requester.connect('layer', options ...)`
just as with the `TCP` and `IPC` layer.

##License ##License


**The software is license under "MIT"** **The software is license under "MIT"**
Expand Down

0 comments on commit e4071da

Please sign in to comment.