~nairboon/anarchnet/trunk

« back to all changes in this revision

Viewing changes to an-core/lib/an-core.js

  • Committer: Remo Hertig
  • Date: 2012-07-19 12:51:59 UTC
  • Revision ID: git-v1:80e88f26a9d251159bb6f665131db1d9a0e9fd0e
docĀ storeĀ api

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
var Hook = require('hook.io').Hook,
2
2
    util = require('util'),
3
3
    fs = require('fs'),
 
4
 
4
5
    net = require('net');
5
6
 
6
7
 run_dir = process.env['HOME'] + "/.an";
19
20
  self.on('hook::ready', function() {
20
21
      console.log("hook ready");
21
22
  });
 
23
  self.on("*::ping",function(data, cb) {
 
24
        console.log("ping");
 
25
        cb("pong");
 
26
        self.emit("pong");
 
27
});
22
28
  storage_engines = [];
 
29
  doc_store = null;
23
30
};
24
31
 
25
32
util.inherits(an, Hook);
 
33
an.prototype.documents = function() { return doc_store; }
 
34
 
 
35
an.prototype.add_docstore = function(ds) {
 
36
 doc_store = ds;
 
37
 self.on('*::document.create', function(arg) {
 
38
        console.log("createdoc", arg);
 
39
        var d = doc_store.create(arg.key);
 
40
        console.log("doc", d);
 
41
        arg.cb(null,d);
 
42
});
 
43
}
 
44
 
 
45
 
26
46
 
27
47
an.prototype.register_storage_engine = function(options, callback){
28
48
callback = callback || function() {};
48
68
};
49
69
 
50
70
an.prototype.put = function(options, callback){
51
 
 
 
71
        storage_engines[0].put(options,callback);
52
72
};
53
73
 
54
74
an.prototype.get = function(options, callback){
 
75
        storage_engines[0].get(options,callback);
 
76
};
55
77
 
 
78
an.prototype.remove = function(options, callback){
 
79
        storage_engines[0].remove(options,callback);
56
80
};
57
81