@@ -2,69 +2,65 @@ use jni_toolbox::jni;
22
33use crate :: {
44 errors:: { ConnectionError , ControllerError , RemoteError } ,
5- prelude:: {
6- CodempAsyncReceiver as AsyncReceiver , CodempClient as Client , CodempConfig as Config ,
7- CodempSessionEvent as SessionEvent , CodempUserInfo as UserInfo ,
8- CodempWorkspace as Workspace , CodempWorkspaceIdentifier as WorkspaceIdentifier ,
9- } ,
5+ prelude:: *
106} ;
117
128/// Connect using the given credentials to the default server, and return a [Client] to interact with it.
139#[ jni( package = "mp.code" , class = "Client" ) ]
14- fn connect ( config : Config ) -> Result < Client , ConnectionError > {
15- super :: tokio ( ) . block_on ( Client :: connect ( config) )
10+ fn connect ( config : CodempConfig ) -> Result < CodempClient , ConnectionError > {
11+ super :: tokio ( ) . block_on ( CodempClient :: connect ( config) )
1612}
1713
1814/// Gets the [UserInfo] for the current user.
1915#[ jni( package = "mp.code" , class = "Client" ) ]
20- fn current_user ( client : & mut Client ) -> UserInfo {
16+ fn current_user ( client : & mut CodempClient ) -> CodempUserInfo {
2117 client. current_user ( ) . clone ( )
2218}
2319
2420/// Join a [Workspace] and return a pointer to it.
2521#[ jni( package = "mp.code" , class = "Client" ) ]
2622fn attach_workspace (
27- client : & mut Client ,
23+ client : & mut CodempClient ,
2824 user : String ,
2925 workspace : String ,
30- ) -> Result < Workspace , ConnectionError > {
26+ ) -> Result < CodempWorkspace , ConnectionError > {
3127 super :: tokio ( ) . block_on ( client. attach_workspace ( user, workspace) )
3228}
3329
3430/// Accepts an invitation to a workspace.
3531#[ jni( package = "mp.code" , class = "Client" ) ]
36- fn accept_invite ( client : & mut Client , user : String , workspace : String ) -> Result < ( ) , RemoteError > {
32+ fn accept_invite ( client : & mut CodempClient , user : String , workspace : String ) -> Result < ( ) , RemoteError > {
3733 super :: tokio ( ) . block_on ( client. accept_invite ( user, workspace) )
3834}
3935
4036/// Rejects an invitation to a workspace.
4137#[ jni( package = "mp.code" , class = "Client" ) ]
42- fn reject_invite ( client : & mut Client , user : String , workspace : String ) -> Result < ( ) , RemoteError > {
38+ fn reject_invite ( client : & mut CodempClient , user : String , workspace : String ) -> Result < ( ) , RemoteError > {
4339 super :: tokio ( ) . block_on ( client. reject_invite ( user, workspace) )
4440}
4541
4642/// Quit a joined [Workspace].
4743#[ jni( package = "mp.code" , class = "Client" ) ]
48- fn quit_workspace ( client : & mut Client , user : String , workspace : String ) -> Result < ( ) , RemoteError > {
44+ fn quit_workspace ( client : & mut CodempClient , user : String , workspace : String ) -> Result < ( ) , RemoteError > {
4945 super :: tokio ( ) . block_on ( client. quit_workspace ( user, workspace) )
5046}
5147
5248/// Create a workspace on server, if allowed to.
5349#[ jni( package = "mp.code" , class = "Client" ) ]
54- fn create_workspace ( client : & mut Client , workspace : String ) -> Result < ( ) , RemoteError > {
50+ fn create_workspace ( client : & mut CodempClient , workspace : String ) -> Result < ( ) , RemoteError > {
5551 super :: tokio ( ) . block_on ( client. create_workspace ( workspace) )
5652}
5753
5854/// Delete a workspace on server, if allowed to.
5955#[ jni( package = "mp.code" , class = "Client" ) ]
60- fn delete_workspace ( client : & mut Client , workspace : String ) -> Result < ( ) , RemoteError > {
56+ fn delete_workspace ( client : & mut CodempClient , workspace : String ) -> Result < ( ) , RemoteError > {
6157 super :: tokio ( ) . block_on ( client. delete_workspace ( workspace) )
6258}
6359
6460/// Invite another user to an owned workspace.
6561#[ jni( package = "mp.code" , class = "Client" ) ]
6662fn invite_to_workspace (
67- client : & mut Client ,
63+ client : & mut CodempClient ,
6864 workspace : String ,
6965 user : String ,
7066) -> Result < ( ) , RemoteError > {
@@ -73,57 +69,57 @@ fn invite_to_workspace(
7369
7470/// List owned workspaces.
7571#[ jni( package = "mp.code" , class = "Client" ) ]
76- fn fetch_owned_workspaces ( client : & mut Client ) -> Result < Vec < WorkspaceIdentifier > , RemoteError > {
72+ fn fetch_owned_workspaces ( client : & mut CodempClient ) -> Result < Vec < CodempWorkspaceIdentifier > , RemoteError > {
7773 super :: tokio ( ) . block_on ( client. fetch_owned_workspaces ( ) )
7874}
7975
8076/// List joined workspaces.
8177#[ jni( package = "mp.code" , class = "Client" ) ]
82- fn fetch_joined_workspaces ( client : & mut Client ) -> Result < Vec < WorkspaceIdentifier > , RemoteError > {
78+ fn fetch_joined_workspaces ( client : & mut CodempClient ) -> Result < Vec < CodempWorkspaceIdentifier > , RemoteError > {
8379 super :: tokio ( ) . block_on ( client. fetch_joined_workspaces ( ) )
8480}
8581
8682/// List available workspaces.
8783#[ jni( package = "mp.code" , class = "Client" ) ]
88- fn active_workspaces ( client : & mut Client ) -> Vec < WorkspaceIdentifier > {
84+ fn active_workspaces ( client : & mut CodempClient ) -> Vec < CodempWorkspaceIdentifier > {
8985 client. active_workspaces ( )
9086}
9187
9288/// Leave a [Workspace] and return whether or not the client was in such workspace.
9389#[ jni( package = "mp.code" , class = "Client" ) ]
94- fn leave_workspace ( client : & mut Client , user : String , workspace : String ) -> bool {
90+ fn leave_workspace ( client : & mut CodempClient , user : String , workspace : String ) -> bool {
9591 client. leave_workspace ( user, workspace)
9692}
9793
9894/// Get a [Workspace] by name and returns a pointer to it.
9995#[ jni( package = "mp.code" , class = "Client" ) ]
100- fn get_workspace ( client : & mut Client , user : String , workspace : String ) -> Option < Workspace > {
96+ fn get_workspace ( client : & mut CodempClient , user : String , workspace : String ) -> Option < CodempWorkspace > {
10197 client. get_workspace ( user, workspace)
10298}
10399
104100/// Fetches information about a user.
105101#[ jni( package = "mp.code" , class = "Client" ) ]
106- fn get_user_info ( client : & mut Client , user : String ) -> Result < UserInfo , RemoteError > {
102+ fn get_user_info ( client : & mut CodempClient , user : String ) -> Result < CodempUserInfo , RemoteError > {
107103 super :: tokio ( ) . block_on ( client. get_user_info ( user) )
108104}
109105
110106/// Try to fetch a [TextChange], or return null if there's nothing.
111107#[ jni( package = "mp.code" , class = "Client" ) ]
112- fn try_recv ( client : & mut Client ) -> Result < Option < SessionEvent > , ControllerError > {
108+ fn try_recv ( client : & mut CodempClient ) -> Result < Option < CodempSessionEvent > , ControllerError > {
113109 super :: tokio ( ) . block_on ( client. try_recv ( ) )
114110}
115111
116112/// Block until it receives a [TextChange].
117113#[ jni( package = "mp.code" , class = "Client" ) ]
118- fn recv ( client : & mut Client ) -> Result < SessionEvent , ControllerError > {
114+ fn recv ( client : & mut CodempClient ) -> Result < CodempSessionEvent , ControllerError > {
119115 super :: tokio ( ) . block_on ( client. recv ( ) )
120116}
121117
122118/// Register a callback for client changes.
123119#[ jni( package = "mp.code" , class = "Client" ) ]
124120fn callback < ' local > (
125121 env : & mut jni:: Env < ' local > ,
126- client : & mut Client ,
122+ client : & mut CodempClient ,
127123 cb : jni:: objects:: JObject < ' local > ,
128124) -> Result < ( ) , jni:: errors:: Error > {
129125 if cb. is_null ( ) {
@@ -135,7 +131,7 @@ fn callback<'local>(
135131 let cb_ref = env. new_global_ref ( cb) ?;
136132 let jvm = env. get_java_vm ( ) ?;
137133
138- client. callback ( move |controller : Client | {
134+ client. callback ( move |controller : CodempClient | {
139135 let result: Result < ( ) , jni:: errors:: Error > = jvm. attach_current_thread ( |env| {
140136 env. with_local_frame ( 5 , |env| {
141137 use jni_toolbox:: IntoJavaObject ;
@@ -162,25 +158,25 @@ fn callback<'local>(
162158
163159/// Clear the callback for client changes.
164160#[ jni( package = "mp.code" , class = "Client" ) ]
165- fn clear_callback ( client : & mut Client ) {
161+ fn clear_callback ( client : & mut CodempClient ) {
166162 client. clear_callback ( )
167163}
168164
169165/// Block until there is a new value available.
170166#[ jni( package = "mp.code" , class = "Client" ) ]
171- fn poll ( client : & mut Client ) -> Result < ( ) , ControllerError > {
167+ fn poll ( client : & mut CodempClient ) -> Result < ( ) , ControllerError > {
172168 super :: tokio ( ) . block_on ( client. poll ( ) )
173169}
174170
175171/// Refresh the client's session token.
176172#[ jni( package = "mp.code" , class = "Client" ) ]
177- fn refresh ( client : & mut Client ) -> Result < ( ) , RemoteError > {
173+ fn refresh ( client : & mut CodempClient ) -> Result < ( ) , RemoteError > {
178174 super :: tokio ( ) . block_on ( client. refresh ( ) )
179175}
180176
181177/// Called by the Java GC to drop a [Client].
182178#[ allow( unsafe_code) ]
183179#[ jni( package = "mp.code" , class = "Client" ) ]
184180fn free ( input : jni:: sys:: jlong ) {
185- let _ = unsafe { Box :: from_raw ( input as * mut Client ) } ;
181+ let _ = unsafe { Box :: from_raw ( input as * mut CodempClient ) } ;
186182}
0 commit comments