Get rid of libgee

It is said to be a bad idea to use in libraries anyway, but definitely makes porting back to C
harder.
This commit is contained in:
Gergely Polonkai 2017-11-02 07:33:14 +01:00
parent 5bc80a215f
commit 9054fb2a72
9 changed files with 104 additions and 98 deletions

View File

@ -90,7 +90,6 @@ AC_SUBST([MATRIX_GLIB_VERSION], matrix_glib_base_version)
GLIB_REQUIRED=2.40.0 GLIB_REQUIRED=2.40.0
VALA_REQUIRED=0.30.0 VALA_REQUIRED=0.30.0
LIBVALA_REQUIRED=0.30 LIBVALA_REQUIRED=0.30
GEE_REQUIRED=0.10.5
GIO_REQUIRED=2.22 GIO_REQUIRED=2.22
SOUP_REQUIRED=2.44.2 SOUP_REQUIRED=2.44.2
JSON_REQUIRED=0.16.2 JSON_REQUIRED=0.16.2
@ -104,9 +103,6 @@ PKG_CHECK_MODULES([GLIB],
# Check for vala # Check for vala
VALAC_CHECK VALAC_CHECK
# Check for libgee
PKG_CHECK_MODULES([GEE], [gee-0.8 >= $GEE_REQUIRED])
# Check for GIO # Check for GIO
PKG_CHECK_MODULES([GIO], [gio-2.0 >= $GIO_REQUIRED]) PKG_CHECK_MODULES([GIO], [gio-2.0 >= $GIO_REQUIRED])

View File

@ -72,7 +72,6 @@ AM_CPPFLAGS += \
$(GOBJECT_CFLAGS) \ $(GOBJECT_CFLAGS) \
$(SOUP_CFLAGS) \ $(SOUP_CFLAGS) \
$(JSON_CFLAGS) \ $(JSON_CFLAGS) \
$(GEE_CFLAGS) \
$(VALA_CFLAGS) \ $(VALA_CFLAGS) \
$(NULL) $(NULL)
@ -136,7 +135,6 @@ libmatrix_glib_0_0_la_CFLAGS = \
$(GOBJECT_CFLAGS) \ $(GOBJECT_CFLAGS) \
$(SOUP_CFLAGS) \ $(SOUP_CFLAGS) \
$(JSON_CFLAGS) \ $(JSON_CFLAGS) \
$(GEE_CFLAGS) \
$(NULL) $(NULL)
libmatrix_glib_0_0_la_LIBADD = \ libmatrix_glib_0_0_la_LIBADD = \
@ -144,7 +142,6 @@ libmatrix_glib_0_0_la_LIBADD = \
$(GOBJECT_LIBS) \ $(GOBJECT_LIBS) \
$(SOUP_LIBS) \ $(SOUP_LIBS) \
$(JSON_LIBS) \ $(JSON_LIBS) \
$(GEE_LIBS) \
$(NULL) $(NULL)
libmatrix_glib_0_0_la_LDFLAGS = \ libmatrix_glib_0_0_la_LDFLAGS = \

View File

@ -1,4 +1,3 @@
gio-2.0 gio-2.0
Json-1.0 Json-1.0
gee-0.8
libsoup-2.4 libsoup-2.4

View File

@ -30,7 +30,7 @@ public class Matrix.Event.Receipt : Matrix.Event.Base {
string user; string user;
} }
private Gee.HashMap<ReceiptData?, ulong?> _receipt_data = null; private HashTable<ReceiptData?, ulong?> _receipt_data = null;
private static bool private static bool
_rd_equal(ReceiptData k1, ReceiptData k2) _rd_equal(ReceiptData k1, ReceiptData k2)
@ -43,7 +43,7 @@ public class Matrix.Event.Receipt : Matrix.Event.Base {
private void private void
_init_receipt_data() _init_receipt_data()
{ {
_receipt_data = new Gee.HashMap<ReceiptData?, ulong?>(null, (Gee.EqualDataFunc)_rd_equal); _receipt_data = new HashTable<ReceiptData?, ulong?>(null, (EqualFunc)_rd_equal);
} }
protected override void protected override void
@ -90,7 +90,7 @@ public class Matrix.Event.Receipt : Matrix.Event.Base {
to_json(Json.Node json_data) to_json(Json.Node json_data)
throws Matrix.Error throws Matrix.Error
{ {
Json.Node? node; Json.Node? node = null;
if (_room_id == null) { if (_room_id == null) {
throw new Matrix.Error.INCOMPLETE( throw new Matrix.Error.INCOMPLETE(
@ -100,57 +100,63 @@ public class Matrix.Event.Receipt : Matrix.Event.Base {
var root = json_data.get_object(); var root = json_data.get_object();
var content_root = root.get_member("content").get_object(); var content_root = root.get_member("content").get_object();
int i = 0; int i = 0;
Matrix.Error? error = null;
foreach (var entry in _receipt_data.entries) { _receipt_data.foreach(
Json.Object event_object; (key, value) => {
Json.Object type_object; Json.Object event_object;
Json.Object user_object; Json.Object type_object;
Json.Object user_object;
if (entry.key.event_id == null) { if (key.event_id == null) {
throw new Matrix.Error.INCOMPLETE( error = new Matrix.Error.INCOMPLETE(
"Won't generate a m.receipt event with an empty event ID"); "Won't generate a m.receipt event with an empty event ID");
} }
if (entry.key.typ == null) { if (key.typ == null) {
throw new Matrix.Error.INCOMPLETE( error = new Matrix.Error.INCOMPLETE(
"Won't generate a m.receipt event with an empty receipt type"); "Won't generate a m.receipt event with an empty receipt type");
} }
if (entry.key.user == null) { if (key.user == null) {
throw new Matrix.Error.INCOMPLETE( error = new Matrix.Error.INCOMPLETE(
"Won't generate a m.receipt event with an empty user ID"); "Won't generate a m.receipt event with an empty user ID");
} }
i++; i++;
if ((node = content_root.get_member(entry.key.event_id)) == null) { if ((node = content_root.get_member(key.event_id)) == null) {
event_object = new Json.Object(); event_object = new Json.Object();
node = new Json.Node(Json.NodeType.OBJECT); node = new Json.Node(Json.NodeType.OBJECT);
node.set_object(event_object); node.set_object(event_object);
content_root.set_member(entry.key.event_id, node); content_root.set_member(key.event_id, node);
} else { } else {
event_object = node.get_object(); event_object = node.get_object();
} }
if ((node = event_object.get_member(entry.key.typ)) == null) { if ((node = event_object.get_member(key.typ)) == null) {
type_object = new Json.Object(); type_object = new Json.Object();
node = new Json.Node(Json.NodeType.OBJECT); node = new Json.Node(Json.NodeType.OBJECT);
node.set_object(type_object); node.set_object(type_object);
event_object.set_member(entry.key.typ, node); event_object.set_member(key.typ, node);
} else { } else {
type_object = node.get_object(); type_object = node.get_object();
} }
if ((node = type_object.get_member(entry.key.user)) == null) { if ((node = type_object.get_member(key.user)) == null) {
user_object = new Json.Object(); user_object = new Json.Object();
node = new Json.Node(Json.NodeType.OBJECT); node = new Json.Node(Json.NodeType.OBJECT);
node.set_object(user_object); node.set_object(user_object);
type_object.set_member(entry.key.user, node); type_object.set_member(key.user, node);
} else { } else {
user_object = node.get_object(); user_object = node.get_object();
} }
user_object.set_int_member("ts", entry.value); user_object.set_int_member("ts", value);
});
if (error != null) {
throw error;
} }
if (i == 0) { if (i == 0) {

View File

@ -73,7 +73,7 @@ public class Matrix.Event.RoomPowerLevels : Matrix.Event.State {
/** /**
* A hash map to store the required level to send specific events. * A hash map to store the required level to send specific events.
*/ */
public Gee.HashMap<string, int?> event_levels { public HashTable<string, int?> event_levels {
get { get {
return _event_levels; return _event_levels;
} }
@ -82,17 +82,17 @@ public class Matrix.Event.RoomPowerLevels : Matrix.Event.State {
/** /**
* A hash map to store current level for individual users. * A hash map to store current level for individual users.
*/ */
public Gee.HashMap<string, int?> user_levels { public HashTable<string, int?> user_levels {
get { get {
return _user_levels; return _user_levels;
} }
} }
private Gee.HashMap<string, int?> _event_levels = private HashTable<string, int?> _event_levels =
new Gee.HashMap<string, int?>(); new HashTable<string, int?>(str_hash, str_equal);
private Gee.HashMap<string, int?> _user_levels = private HashTable<string, int?> _user_levels =
new Gee.HashMap<string, int?>(); new HashTable<string, int?>(str_hash, str_equal);
protected override void protected override void
from_json(Json.Node json_data) from_json(Json.Node json_data)
@ -147,7 +147,7 @@ public class Matrix.Event.RoomPowerLevels : Matrix.Event.State {
} }
if ((node = content_root.get_member("events")) != null) { if ((node = content_root.get_member("events")) != null) {
_event_levels.clear(); _event_levels.remove_all();
node.get_object().foreach_member((obj, event_name, event_node) => { node.get_object().foreach_member((obj, event_name, event_node) => {
_event_levels[event_name] = (int)event_node.get_int(); _event_levels[event_name] = (int)event_node.get_int();
@ -155,7 +155,7 @@ public class Matrix.Event.RoomPowerLevels : Matrix.Event.State {
} }
if ((node = content_root.get_member("users")) != null) { if ((node = content_root.get_member("users")) != null) {
_user_levels.clear(); _user_levels.remove_all();
node.get_object().foreach_member((obj, user_id, user_node) => { node.get_object().foreach_member((obj, user_id, user_node) => {
_user_levels[user_id] = (int)user_node.get_int(); _user_levels[user_id] = (int)user_node.get_int();
@ -197,9 +197,10 @@ public class Matrix.Event.RoomPowerLevels : Matrix.Event.State {
var user_node = new Json.Node(Json.NodeType.OBJECT); var user_node = new Json.Node(Json.NodeType.OBJECT);
user_node.set_object(user_obj); user_node.set_object(user_obj);
foreach (var entry in _user_levels.entries) { _user_levels.foreach(
user_obj.set_int_member(entry.key, entry.value); (key, value) => {
} user_obj.set_int_member(key, value);
});
content_root.set_member("users", user_node); content_root.set_member("users", user_node);
@ -207,9 +208,10 @@ public class Matrix.Event.RoomPowerLevels : Matrix.Event.State {
var events_node = new Json.Node(Json.NodeType.OBJECT); var events_node = new Json.Node(Json.NodeType.OBJECT);
events_node.set_object(events_obj); events_node.set_object(events_obj);
foreach (var entry in _event_levels.entries) { _event_levels.foreach(
events_obj.set_int_member(entry.key, entry.value); (key, value) => {
} events_obj.set_int_member(key, value);
});
content_root.set_member("users", events_node); content_root.set_member("users", events_node);

View File

@ -9,6 +9,6 @@ Name: libmatrix-glib
Description: GObject API for communicating with a Matrix.org Homeserver Description: GObject API for communicating with a Matrix.org Homeserver
URL: http://gergely.polonkai.eu/matrix-glib-sdk URL: http://gergely.polonkai.eu/matrix-glib-sdk
Version: @MATRIX_GLIB_VERSION@ Version: @MATRIX_GLIB_VERSION@
Requires: glib-2.0 gobject-2.0 gee-0.8 gio-2.0 json-glib-1.0 Requires: glib-2.0 gobject-2.0 gio-2.0 json-glib-1.0
Libs: -L${libdir} -lmatrix-glib-@MATRIX_GLIB_API_VERSION@ Libs: -L${libdir} -lmatrix-glib-@MATRIX_GLIB_API_VERSION@
Cflags: -I${includedir}/matrix-glib-@MATRIX_GLIB_API_VERSION@ Cflags: -I${includedir}/matrix-glib-@MATRIX_GLIB_API_VERSION@

View File

@ -24,12 +24,12 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
private bool _polling = false; private bool _polling = false;
private ulong _event_timeout = 30000; private ulong _event_timeout = 30000;
private string? _last_sync_token; private string? _last_sync_token;
private Gee.HashMap<string, Profile> _user_global_profiles = private HashTable<string, Profile> _user_global_profiles =
new Gee.HashMap<string, Profile>(); new HashTable<string, Profile>(str_hash, str_equal);
private Gee.HashMap<string, Presence> _user_global_presence = private HashTable<string, Presence> _user_global_presence =
new Gee.HashMap<string, Presence>(); new HashTable<string, Presence>(str_hash, str_equal);
private Gee.HashMap<string, Room> _rooms = private HashTable<string, Room> _rooms =
new Gee.HashMap<string, Room>(); new HashTable<string, Room>(str_hash, str_equal);
private ulong _last_txn_id = 0; private ulong _last_txn_id = 0;
public public
@ -211,13 +211,15 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
room.clear_user_levels(); room.clear_user_levels();
room.clear_event_levels(); room.clear_event_levels();
foreach (var entry in levt.user_levels.entries) { levt.user_levels.foreach(
room.set_user_level(entry.key, entry.value); (key, value) => {
} room.set_user_level(key, value);
});
foreach (var entry in levt.event_levels.entries) { levt.event_levels.foreach(
room.set_event_level(entry.key, entry.value); (key, value) => {
} room.set_event_level(key, value);
});
} else if (evt is Matrix.Event.RoomTopic) { } else if (evt is Matrix.Event.RoomTopic) {
var tevt = (Matrix.Event.RoomTopic)evt; var tevt = (Matrix.Event.RoomTopic)evt;
@ -501,16 +503,21 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
get_room_by_alias(string room_alias) get_room_by_alias(string room_alias)
throws Matrix.Error throws Matrix.Error
{ {
foreach (var entry in _rooms.entries) { Room? room_found = _rooms.find(
var room = entry.value; (key, room) => {
if (room.canonical_alias == room_alias) {
return true;
}
if (room.canonical_alias == room_alias) { if (room_alias in room.aliases) {
return room; return true;
} }
if (room_alias in room.aliases) { return false;
return room; });
}
if (room_found != null) {
return room_found;
} }
throw new Matrix.Error.UNAVAILABLE( throw new Matrix.Error.UNAVAILABLE(

View File

@ -141,19 +141,19 @@ public class Matrix.Room : GLib.Object {
*/ */
public string[] typing_users { get; set; } public string[] typing_users { get; set; }
private Gee.HashMap<string, int?> _event_levels = private HashTable<string, int?> _event_levels =
new Gee.HashMap<string, int?>(); new HashTable<string, int?>(str_hash, str_equal);
private Gee.HashMap<string, int?> _user_levels = private HashTable<string, int?> _user_levels =
new Gee.HashMap<string, int?>(); new HashTable<string, int?>(str_hash, str_equal);
private struct MemberData { private struct MemberData {
Profile profile; Profile profile;
bool thirdparty; bool thirdparty;
} }
private Gee.HashMap<string, MemberData?> _members = private HashTable<string, MemberData?> _members =
new Gee.HashMap<string, MemberData?>(); new HashTable<string, MemberData?>(str_hash, str_equal);
/** /**
* Create a new Room object. * Create a new Room object.
@ -260,7 +260,7 @@ public class Matrix.Room : GLib.Object {
"No such room member"); "No such room member");
} }
_members.unset(user_id); _members.remove(user_id);
} }
/** /**
@ -270,7 +270,7 @@ public class Matrix.Room : GLib.Object {
public void public void
clear_user_levels() clear_user_levels()
{ {
_user_levels.clear(); _user_levels.remove_all();
} }
/** /**
@ -312,7 +312,7 @@ public class Matrix.Room : GLib.Object {
public void public void
clear_event_levels() clear_event_levels()
{ {
_event_levels.clear(); _event_levels.remove_all();
} }
/** /**

View File

@ -2,7 +2,6 @@ VALA_PKG_LIST = \
--pkg=gio-2.0 \ --pkg=gio-2.0 \
--pkg=json-glib-1.0 \ --pkg=json-glib-1.0 \
--pkg=libsoup-2.4 \ --pkg=libsoup-2.4 \
--pkg=gee-0.8 \
--pkg=c-api \ --pkg=c-api \
--pkg=config \ --pkg=config \
$(NULL) $(NULL)