Don't build a new connection if it already exists
There was also a lot of unneeded overhead in Connection::new() to get the path to compare against, so split that out into a settings struct
This commit is contained in:
@@ -34,11 +34,11 @@ impl AsRef<dyn telepathy::Connection + 'static> for std::rc::Rc<Connection> {
|
||||
impl telepathy::Connection for Connection {
|
||||
// In connect(), we start the threads that drive the deltachat context
|
||||
fn connect(&self) -> Result<(), MethodErr> {
|
||||
println!("Connection<{}>::connect()", self.id);
|
||||
println!("Connection<{}>::connect()", self.id());
|
||||
|
||||
let inbox_ctx = self.ctx.clone();
|
||||
let state = self.state.clone();
|
||||
let id = self.id.clone();
|
||||
let id = self.id();
|
||||
let _inbox_thread = thread::spawn(move || {
|
||||
while *state.read().unwrap() != ConnState::Disconnected {
|
||||
dc::job::perform_inbox_jobs(&inbox_ctx.read().unwrap());
|
||||
@@ -56,7 +56,7 @@ impl telepathy::Connection for Connection {
|
||||
|
||||
let smtp_ctx = self.ctx.clone();
|
||||
let state = self.state.clone();
|
||||
let id = self.id.clone();
|
||||
let id = self.id();
|
||||
let _smtp_thread = thread::spawn(move || {
|
||||
while *state.read().unwrap() != ConnState::Disconnected {
|
||||
dc::job::perform_smtp_jobs(&smtp_ctx.read().unwrap());
|
||||
@@ -70,7 +70,7 @@ impl telepathy::Connection for Connection {
|
||||
|
||||
let mvbox_ctx = self.ctx.clone();
|
||||
let state = self.state.clone();
|
||||
let id = self.id.clone();
|
||||
let id = self.id();
|
||||
let _mvbox_thread = thread::spawn(move || {
|
||||
while *state.read().unwrap() != ConnState::Disconnected {
|
||||
dc::job::perform_mvbox_fetch(&mvbox_ctx.read().unwrap());
|
||||
@@ -84,7 +84,7 @@ impl telepathy::Connection for Connection {
|
||||
|
||||
let sentbox_ctx = self.ctx.clone();
|
||||
let state = self.state.clone();
|
||||
let id = self.id.clone();
|
||||
let id = self.id();
|
||||
let _sentbox_thread = thread::spawn(move || {
|
||||
while *state.read().unwrap() != ConnState::Disconnected {
|
||||
dc::job::perform_sentbox_fetch(&sentbox_ctx.read().unwrap());
|
||||
@@ -121,7 +121,7 @@ impl telepathy::Connection for Connection {
|
||||
}
|
||||
|
||||
fn disconnect(&self) -> Result<(), MethodErr> {
|
||||
println!("Connection<{}>::disconnect()", self.id);
|
||||
println!("Connection<{}>::disconnect()", self.id());
|
||||
let ctx = self.ctx.read().unwrap();
|
||||
|
||||
let state = self.state.clone();
|
||||
@@ -140,37 +140,37 @@ impl telepathy::Connection for Connection {
|
||||
}
|
||||
|
||||
fn interfaces(&self) -> Result<Vec<String>, MethodErr> {
|
||||
println!("Connection<{}>::interfaces()", self.id);
|
||||
println!("Connection<{}>::interfaces()", self.id());
|
||||
|
||||
self.get_interfaces()
|
||||
}
|
||||
|
||||
fn get_interfaces(&self) -> Result<Vec<String>, MethodErr> {
|
||||
println!("Connection<{}>::get_interfaces()", self.id);
|
||||
println!("Connection<{}>::get_interfaces()", self.id());
|
||||
|
||||
Ok(connection_interfaces())
|
||||
}
|
||||
|
||||
fn get_protocol(&self) -> Result<String, MethodErr> {
|
||||
println!("Connection<{}>::get_protocol()", self.id);
|
||||
println!("Connection<{}>::get_protocol()", self.id());
|
||||
|
||||
Ok(crate::padfoot::PROTO_NAME.to_string())
|
||||
}
|
||||
|
||||
fn self_handle(&self) -> Result<u32, MethodErr> {
|
||||
println!("Connection<{}>::self_handle()", self.id);
|
||||
println!("Connection<{}>::self_handle()", self.id());
|
||||
|
||||
self.get_self_handle()
|
||||
}
|
||||
|
||||
fn get_self_handle(&self) -> Result<u32, MethodErr> {
|
||||
println!("Connection<{}>::get_self_handle()", self.id);
|
||||
println!("Connection<{}>::get_self_handle()", self.id());
|
||||
|
||||
Ok(dc::constants::DC_CONTACT_ID_SELF)
|
||||
}
|
||||
|
||||
fn status(&self) -> Result<u32, MethodErr> {
|
||||
println!("Connection<{}>::status()", self.id);
|
||||
println!("Connection<{}>::status()", self.id());
|
||||
|
||||
self.get_status()
|
||||
}
|
||||
@@ -185,7 +185,9 @@ impl telepathy::Connection for Connection {
|
||||
fn hold_handles(&self, handle_type: u32, handles: Vec<u32>) -> Result<(), MethodErr> {
|
||||
println!(
|
||||
"Connection<{}>::hold_handles({}, {:?})",
|
||||
self.id, handle_type, handles
|
||||
self.id(),
|
||||
handle_type,
|
||||
handles
|
||||
);
|
||||
|
||||
// Since HasImmortalHandles is true, this doesn't need to do anything
|
||||
@@ -199,20 +201,24 @@ impl telepathy::Connection for Connection {
|
||||
) -> Result<Vec<String>, MethodErr> {
|
||||
println!(
|
||||
"Connection<{}>::inspect_handles({}, {:?})",
|
||||
self.id, handle_type, handles
|
||||
self.id(),
|
||||
handle_type,
|
||||
handles
|
||||
);
|
||||
Err(MethodErr::no_arg()) // FIXME: should be NotImplemented?
|
||||
}
|
||||
|
||||
fn list_channels(&self) -> Result<Vec<(dbus::Path<'static>, String, u32, u32)>, MethodErr> {
|
||||
println!("Connection<{}>::list_channels()", self.id);
|
||||
println!("Connection<{}>::list_channels()", self.id());
|
||||
Err(MethodErr::no_arg()) // FIXME: should be NotImplemented?
|
||||
}
|
||||
|
||||
fn release_handles(&self, handle_type: u32, handles: Vec<u32>) -> Result<(), MethodErr> {
|
||||
println!(
|
||||
"Connection<{}>::release_handles({}, {:?})",
|
||||
self.id, handle_type, handles
|
||||
self.id(),
|
||||
handle_type,
|
||||
handles
|
||||
);
|
||||
|
||||
// Since HasImmortalHandles is true, we don't need to do anything
|
||||
@@ -228,7 +234,11 @@ impl telepathy::Connection for Connection {
|
||||
) -> Result<dbus::Path<'static>, MethodErr> {
|
||||
println!(
|
||||
"Connection<{}>::request_channel({}, {}, {}, {})",
|
||||
self.id, type_, handle_type, handle, suppress_handler
|
||||
self.id(),
|
||||
type_,
|
||||
handle_type,
|
||||
handle,
|
||||
suppress_handler
|
||||
);
|
||||
Err(MethodErr::no_arg()) // FIXME: should be NotImplemented?
|
||||
}
|
||||
@@ -240,26 +250,33 @@ impl telepathy::Connection for Connection {
|
||||
) -> Result<Vec<u32>, MethodErr> {
|
||||
println!(
|
||||
"Connection<{}>::request_handles({}, {:?})",
|
||||
self.id, handle_type, identifiers
|
||||
self.id(),
|
||||
handle_type,
|
||||
identifiers
|
||||
);
|
||||
Err(MethodErr::no_arg()) // FIXME: should be NotImplemented?
|
||||
}
|
||||
|
||||
fn add_client_interest(&self, tokens: Vec<&str>) -> Result<(), MethodErr> {
|
||||
println!("Connection<{}>::add_client_interest({:?})", self.id, tokens);
|
||||
println!(
|
||||
"Connection<{}>::add_client_interest({:?})",
|
||||
self.id(),
|
||||
tokens
|
||||
);
|
||||
Err(MethodErr::no_arg()) // FIXME: should be NotImplemented?
|
||||
}
|
||||
|
||||
fn remove_client_interest(&self, tokens: Vec<&str>) -> Result<(), MethodErr> {
|
||||
println!(
|
||||
"Connection<{}>::remove_client_interest({:?})",
|
||||
self.id, tokens
|
||||
self.id(),
|
||||
tokens
|
||||
);
|
||||
Err(MethodErr::no_arg()) // FIXME: should be NotImplemented?
|
||||
}
|
||||
|
||||
fn self_id(&self) -> Result<String, MethodErr> {
|
||||
println!("Connection<{}>::self_id()", self.id);
|
||||
println!("Connection<{}>::self_id()", self.id());
|
||||
|
||||
let contact = match dc::contact::Contact::get_by_id(
|
||||
&self.ctx.read().unwrap(),
|
||||
@@ -276,7 +293,7 @@ impl telepathy::Connection for Connection {
|
||||
}
|
||||
|
||||
fn has_immortal_handles(&self) -> Result<bool, MethodErr> {
|
||||
println!("Connection<{}>::has_immortal_handles()", self.id);
|
||||
println!("Connection<{}>::has_immortal_handles()", self.id());
|
||||
|
||||
Ok(true)
|
||||
}
|
||||
|
Reference in New Issue
Block a user