[fractal] API: move stuff to the root of the backend module
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] API: move stuff to the root of the backend module
- Date: Tue, 30 Jun 2020 07:43:24 +0000 (UTC)
commit 5057f910d66af0fc815540fbed368b344c7cdf66
Author: Alejandro DomÃnguez <adomu net-c com>
Date: Wed Jun 24 09:12:42 2020 +0200
API: move stuff to the root of the backend module
fractal-gtk/src/appop/room.rs | 5 +-
fractal-matrix-api/src/backend/media.rs | 2 +-
fractal-matrix-api/src/backend/mod.rs | 100 +++++++++++++++++++++++++++++--
fractal-matrix-api/src/backend/room.rs | 8 ++-
fractal-matrix-api/src/backend/types.rs | 102 --------------------------------
fractal-matrix-api/src/backend/user.rs | 2 +-
fractal-matrix-api/src/meson.build | 1 -
7 files changed, 106 insertions(+), 114 deletions(-)
---
diff --git a/fractal-gtk/src/appop/room.rs b/fractal-gtk/src/appop/room.rs
index 3bc8e1ef..e6ae6d84 100644
--- a/fractal-gtk/src/appop/room.rs
+++ b/fractal-gtk/src/appop/room.rs
@@ -14,7 +14,6 @@ use crate::app::dispatch_error;
use crate::app::App;
use crate::appop::AppOp;
-use crate::backend;
use crate::backend::BKResponse;
use fractal_api::util::cache_dir_path;
@@ -394,9 +393,9 @@ impl AppOp {
.map_or(String::new(), |gstr| gstr.to_string());
// Since the switcher
let privacy = if private.get_active() {
- backend::RoomType::Private
+ room::RoomType::Private
} else {
- backend::RoomType::Public
+ room::RoomType::Public
};
let internal_id = RoomId::new(&login_data.server_url.to_string())
diff --git a/fractal-matrix-api/src/backend/media.rs b/fractal-matrix-api/src/backend/media.rs
index b99eb926..f41ca378 100644
--- a/fractal-matrix-api/src/backend/media.rs
+++ b/fractal-matrix-api/src/backend/media.rs
@@ -18,7 +18,7 @@ use crate::r0::message::get_message_events::Parameters as GetMessagesEventsParam
use crate::r0::message::get_message_events::Response as GetMessagesEventsResponse;
use crate::types::Message;
-use super::types::ThreadPool;
+use super::ThreadPool;
pub fn get_thumb_async(
thread_pool: ThreadPool,
diff --git a/fractal-matrix-api/src/backend/mod.rs b/fractal-matrix-api/src/backend/mod.rs
index 1e9a4ebc..d77c58d4 100644
--- a/fractal-matrix-api/src/backend/mod.rs
+++ b/fractal-matrix-api/src/backend/mod.rs
@@ -1,11 +1,103 @@
+use ruma_identifiers::RoomId;
+use std::sync::{Arc, Condvar, Mutex};
+use std::thread;
+
+use crate::error::Error;
+
pub mod directory;
pub mod media;
pub mod register;
pub mod room;
pub mod sync;
-mod types;
pub mod user;
-pub use self::types::BKResponse;
-pub use self::types::RoomType;
-pub use self::types::ThreadPool;
+#[derive(Debug)]
+pub enum BKResponse {
+ //errors
+ LoginError(Error),
+ GuestLoginError(Error),
+ SendTypingError(Error),
+ SetRoomError(Error),
+ InviteError(Error),
+ ChangeLanguageError(Error),
+ NameError(Error),
+ AvatarError(Error),
+ MarkedAsReadError(Error),
+ UserSearchError(Error),
+ LogoutError(Error),
+ LeaveRoomError(Error),
+ DirectoryProtocolsError(Error),
+ RoomMembersError(Error),
+ AddedToFavError(Error),
+ GetThreePIDError(Error),
+ AddThreePIDError(Error),
+ SubmitPhoneTokenError(Error),
+ SetUserNameError(Error),
+ ChangePasswordError(Error),
+ AccountDestructionError(Error),
+ DeleteThreePIDError(Error),
+ GetTokenPhoneError(Error),
+ GetTokenEmailError(Error),
+ SetRoomNameError(Error),
+ SetRoomTopicError(Error),
+ SetUserAvatarError(Error),
+ SetRoomAvatarError(Error),
+ RoomMessagesToError(Error),
+ MediaError(Error),
+ SentMsgRedactionError(Error),
+ JoinRoomError(Error),
+ DirectorySearchError(Error),
+ NewRoomError(Error, RoomId),
+ RoomDetailError(Error),
+ RoomAvatarError(Error),
+ SentMsgError(Error),
+ AttachedFileError(Error),
+ RoomsError(Error),
+ UpdateRoomsError(Error),
+ RoomMessagesError(Error),
+ RoomElementError(Error),
+ SyncError(Error, u64),
+}
+
+#[derive(Clone, Debug)]
+pub struct ThreadPool {
+ thread_count: Arc<(Mutex<u8>, Condvar)>,
+ limit: u8,
+}
+
+impl ThreadPool {
+ pub fn new(limit: u8) -> Self {
+ ThreadPool {
+ thread_count: Arc::new((Mutex::new(0), Condvar::new())),
+ limit,
+ }
+ }
+
+ pub fn run<F>(&self, func: F)
+ where
+ F: FnOnce() + Send + 'static,
+ {
+ let thread_count = self.thread_count.clone();
+ let limit = self.limit;
+ thread::spawn(move || {
+ // waiting, less than {limit} threads at the same time
+ let &(ref num, ref cvar) = &*thread_count;
+ {
+ let mut start = num.lock().unwrap();
+ while *start >= limit {
+ start = cvar.wait(start).unwrap()
+ }
+ *start += 1;
+ }
+
+ func();
+
+ // freeing the cvar for new threads
+ {
+ let mut counter = num.lock().unwrap();
+ *counter -= 1;
+ }
+ cvar.notify_one();
+ });
+ }
+}
diff --git a/fractal-matrix-api/src/backend/room.rs b/fractal-matrix-api/src/backend/room.rs
index c29e98f0..065d514f 100644
--- a/fractal-matrix-api/src/backend/room.rs
+++ b/fractal-matrix-api/src/backend/room.rs
@@ -18,8 +18,6 @@ use crate::util::get_prev_batch_from;
use crate::util::ContentType;
use crate::util::HTTP_CLIENT;
-use crate::backend::types::RoomType;
-
use crate::r0::config::get_global_account_data::request as get_global_account_data;
use crate::r0::config::get_global_account_data::Parameters as GetGlobalAccountDataParameters;
use crate::r0::config::set_global_account_data::request as set_global_account_data;
@@ -401,6 +399,12 @@ pub fn upload_file(
.map_err(Into::into)
}
+#[derive(Debug, Clone, Copy)]
+pub enum RoomType {
+ Public,
+ Private,
+}
+
pub fn new_room(
base: Url,
access_token: AccessToken,
diff --git a/fractal-matrix-api/src/backend/user.rs b/fractal-matrix-api/src/backend/user.rs
index a3772489..10236686 100644
--- a/fractal-matrix-api/src/backend/user.rs
+++ b/fractal-matrix-api/src/backend/user.rs
@@ -2,7 +2,7 @@ use ruma_identifiers::UserId;
use std::fs;
use url::Url;
-use crate::backend::types::ThreadPool;
+use crate::backend::ThreadPool;
use crate::cache::CacheMap;
use crate::error::Error;
use crate::util::get_user_avatar;
diff --git a/fractal-matrix-api/src/meson.build b/fractal-matrix-api/src/meson.build
index 87bbb88b..29b9bc74 100644
--- a/fractal-matrix-api/src/meson.build
+++ b/fractal-matrix-api/src/meson.build
@@ -5,7 +5,6 @@ api_sources = files(
'backend/register.rs',
'backend/room.rs',
'backend/sync.rs',
- 'backend/types.rs',
'backend/user.rs',
'identity/r0/association/msisdn/submit_token.rs',
'identity/r0/association/msisdn.rs',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]