3 * Copyright (C)2007-2008 Versabanq Innovations Inc. and contributors.
4 * See the included file named LICENSE for license information.
8 using System
.Collections
;
9 using System
.Collections
.Generic
;
13 // An ISchemaBackend that uses a DBus connection to Versaplex as a backing
16 internal class VxDbusSchema
: ISchemaBackend
20 public static void wvmoniker_register()
22 WvMoniker
<ISchemaBackend
>.register("vx",
23 (string m
, object o
) => new VxDbusSchema(m
));
24 WvMoniker
<ISchemaBackend
>.register("vx",
25 (string m
, object o
) => new VxDbusSchema(m
));
33 public VxDbusSchema(string busurl
)
35 WvUrl url
= new WvUrl(busurl
);
37 if (url
.host
.e() || url
.host
== "session")
38 bus
= WvDbus
.session_bus
;
40 bus
= new WvDbus(wv
.fmt("tcp:host={0},port={1}",
44 // If you've already got a Bus you'd like to use.
45 public VxDbusSchema(WvDbus _bus
)
58 static WvDbusMsg
methodcall(string method
, string signature
)
60 return new WvDbusCall("vx.versaplexd", "/db",
61 "vx.db", method
, signature
);
65 // The ISchema interface
68 // Note: this implementation ignores the sums.
69 public VxSchemaErrors
Put(VxSchema schema
, VxSchemaChecksums sums
,
72 WvDbusMsg call
= methodcall("PutSchema",
73 String
.Format("{0}i", VxSchema
.GetDbusSignature()));
75 WvDbusWriter writer
= new WvDbusWriter();
77 schema
.WriteSchema(writer
);
78 writer
.Write((int)opts
);
79 call
.Body
= writer
.ToArray();
81 WvDbusMsg reply
= bus
.send_and_wait(call
);
82 if (reply
.signature
== VxSchemaErrors
.GetDbusSignature())
83 return new VxSchemaErrors(reply
.iter().pop());
85 reply
.check(VxSchemaErrors
.GetDbusSignature());
89 // Utility API so you can say Get("foo").
90 public VxSchema
Get(params string[] keys
)
92 WvDbusMsg call
= methodcall("GetSchema", "as");
94 WvDbusWriter writer
= new WvDbusWriter();
99 writer
.WriteArray(4, keys
, (w2
, k
) => {
102 call
.Body
= writer
.ToArray();
104 WvDbusMsg reply
= bus
.send_and_wait(call
);
105 reply
.check("a(sssy)");
106 VxSchema schema
= new VxSchema(reply
.iter().pop());
110 public VxSchema
Get(IEnumerable
<string> keys
)
113 keys
= new string[0];
114 return Get(keys
.ToArray());
117 public VxSchemaChecksums
GetChecksums()
119 WvDbusMsg call
= methodcall("GetSchemaChecksums", "");
121 WvDbusMsg reply
= bus
.send_and_wait(call
);
122 reply
.check("a(sat)");
123 VxSchemaChecksums sums
= new VxSchemaChecksums(reply
);
127 public VxSchemaErrors
DropSchema(IEnumerable
<string> keys
)
130 keys
= new string[0];
131 return DropSchema(keys
.ToArray());
134 // A method exported over DBus but not exposed in ISchemaBackend
135 public VxSchemaErrors
DropSchema(params string[] keys
)
137 WvDbusMsg call
= methodcall("DropSchema", "as");
139 WvDbusWriter writer
= new WvDbusWriter();
141 writer
.WriteArray(4, keys
, (w2
, k
) => {
144 call
.Body
= writer
.ToArray();
146 WvDbusMsg reply
= bus
.send_and_wait(call
);
147 if (reply
.signature
== VxSchemaErrors
.GetDbusSignature())
148 return new VxSchemaErrors(reply
.iter().pop());
150 reply
.check(VxSchemaErrors
.GetDbusSignature());
154 public string GetSchemaData(string tablename
, int seqnum
, string where
,
155 Dictionary
<string,string> replaces
, List
<string> skipfields
)
157 WvDbusMsg call
= methodcall("GetSchemaData", "ss");
159 WvDbusWriter writer
= new WvDbusWriter();
164 writer
.Write(tablename
);
166 call
.Body
= writer
.ToArray();
168 WvDbusMsg reply
= bus
.send_and_wait(call
);
170 return reply
.iter().pop();
173 public void PutSchemaData(string tablename
, string text
, int seqnum
)
175 WvDbusMsg call
= methodcall("PutSchemaData", "ss");
177 WvDbusWriter writer
= new WvDbusWriter();
179 writer
.Write(tablename
);
181 call
.Body
= writer
.ToArray();
183 WvDbusMsg reply
= bus
.send_and_wait(call
);