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
VALA_REQUIRED=0.30.0
LIBVALA_REQUIRED=0.30
GEE_REQUIRED=0.10.5
GIO_REQUIRED=2.22
SOUP_REQUIRED=2.44.2
JSON_REQUIRED=0.16.2
@ -104,9 +103,6 @@ PKG_CHECK_MODULES([GLIB],
# Check for vala
VALAC_CHECK
# Check for libgee
PKG_CHECK_MODULES([GEE], [gee-0.8 >= $GEE_REQUIRED])
# Check for GIO
PKG_CHECK_MODULES([GIO], [gio-2.0 >= $GIO_REQUIRED])

View File

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

View File

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

View File

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

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.
*/
public Gee.HashMap<string, int?> event_levels {
public HashTable<string, int?> event_levels {
get {
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.
*/
public Gee.HashMap<string, int?> user_levels {
public HashTable<string, int?> user_levels {
get {
return _user_levels;
}
}
private Gee.HashMap<string, int?> _event_levels =
new Gee.HashMap<string, int?>();
private HashTable<string, int?> _event_levels =
new HashTable<string, int?>(str_hash, str_equal);
private Gee.HashMap<string, int?> _user_levels =
new Gee.HashMap<string, int?>();
private HashTable<string, int?> _user_levels =
new HashTable<string, int?>(str_hash, str_equal);
protected override void
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) {
_event_levels.clear();
_event_levels.remove_all();
node.get_object().foreach_member((obj, event_name, event_node) => {
_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) {
_user_levels.clear();
_user_levels.remove_all();
node.get_object().foreach_member((obj, user_id, user_node) => {
_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);
user_node.set_object(user_obj);
foreach (var entry in _user_levels.entries) {
user_obj.set_int_member(entry.key, entry.value);
}
_user_levels.foreach(
(key, value) => {
user_obj.set_int_member(key, value);
});
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);
events_node.set_object(events_obj);
foreach (var entry in _event_levels.entries) {
events_obj.set_int_member(entry.key, entry.value);
}
_event_levels.foreach(
(key, value) => {
events_obj.set_int_member(key, value);
});
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
URL: http://gergely.polonkai.eu/matrix-glib-sdk
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@
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 ulong _event_timeout = 30000;
private string? _last_sync_token;
private Gee.HashMap<string, Profile> _user_global_profiles =
new Gee.HashMap<string, Profile>();
private Gee.HashMap<string, Presence> _user_global_presence =
new Gee.HashMap<string, Presence>();
private Gee.HashMap<string, Room> _rooms =
new Gee.HashMap<string, Room>();
private HashTable<string, Profile> _user_global_profiles =
new HashTable<string, Profile>(str_hash, str_equal);
private HashTable<string, Presence> _user_global_presence =
new HashTable<string, Presence>(str_hash, str_equal);
private HashTable<string, Room> _rooms =
new HashTable<string, Room>(str_hash, str_equal);
private ulong _last_txn_id = 0;
public
@ -211,13 +211,15 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
room.clear_user_levels();
room.clear_event_levels();
foreach (var entry in levt.user_levels.entries) {
room.set_user_level(entry.key, entry.value);
}
levt.user_levels.foreach(
(key, value) => {
room.set_user_level(key, value);
});
foreach (var entry in levt.event_levels.entries) {
room.set_event_level(entry.key, entry.value);
}
levt.event_levels.foreach(
(key, value) => {
room.set_event_level(key, value);
});
} else if (evt is Matrix.Event.RoomTopic) {
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)
throws Matrix.Error
{
foreach (var entry in _rooms.entries) {
var room = entry.value;
Room? room_found = _rooms.find(
(key, room) => {
if (room.canonical_alias == room_alias) {
return room;
return true;
}
if (room_alias in room.aliases) {
return room;
return true;
}
return false;
});
if (room_found != null) {
return room_found;
}
throw new Matrix.Error.UNAVAILABLE(

View File

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

View File

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