path:
root/
examples/
beatdown/
beatdown.vala (
plain)
blob: bc852b5c799549749eb60a95a3f3c0e9efb1dfd7
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
using GLib;
using Catalina;
namespace Beatdown {
Storage storage = null;
int count = 0;
Mutex mutex;
Cond cond;
static void main (string[] args) {
mutex = new Mutex ();
cond = new Cond ();
mutex.lock ();
storage = new Storage ();
storage.use_idle = false;
storage.formatter = new BinaryFormatter ();
storage.transform = new ZlibTransform ();
storage.open_async (".", "beatdown.db", (_, result) => {
try { storage.open_finish (result); }
catch { error ("Could not open storage"); }
debug ("Storage opened");
for (int i = 0; i < 1000; i++) {
Value v = Value (typeof (Person));
var p = new Person ();
p.first_name = "John";
p.last_name = "Doe";
p.website = "http://example.com";
p.email = "example@example.com";
v.set_object (p);
storage.set_value_async (0, "%d".printf (i), -1, v, (_, result) => {
AtomicInt.inc (ref count);
try { storage.set_value_finish (result); }
catch { error ("Could not store value"); }
if (count >= 1000) {
mutex.lock ();
cond.signal ();
mutex.unlock ();
}
});
v.unset ();
}
});
cond.wait (mutex);
mutex.unlock ();
try { storage.close (); } catch { error ("Error closing storage"); }
debug ("Storage closed");
}
public enum Gender {
UNKNOWN,
MALE,
FEMALE,
}
class Person: GLib.Object {
public string first_name { get; set; }
public string last_name { get; set; }
public string website { get; set; }
public string email { get; set; }
public bool married { get; set; }
/* G_TYPE_ENUM and TimeVal serialization not yet supported */
public Gender gender { get; set; }
public TimeVal birth_date { get; set; }
}
}
|