Change some method names

main
Laurent Pelecq 2 years ago
parent 73b2531c4f
commit 4f9f0fe9dc

@ -20,9 +20,13 @@ Example
------- -------
```rust ```rust
use ssip_client::{new_default_fifo_client, ClientName}; use ssip_client::{new_default_fifo_client, ClientName, OK_CLIENT_NAME_SET};
let mut client = new_default_fifo_client(&ClientName::new("joe", "hello"), None)?;
let msg_id = client.say_line("hello")?; let mut client = new_default_fifo_client(None)?;
client
.open(ClientName::new("joe", "hello"))?
.check_status(OK_CLIENT_NAME_SET)?;
let msg_id = client.speak()?.send_line("hello")?.receive_message_id()?;
client.quit()?; client.quit()?;
``` ```

@ -15,7 +15,7 @@ fn main() -> ClientResult<()> {
for event in &events { for event in &events {
if event.token() == token && event.is_writable() { if event.token() == token && event.is_writable() {
println!("opening client"); println!("opening client");
match client.open(ClientName::new("joe", "hello")) { match client.set_client_name(ClientName::new("joe", "hello")) {
Ok(()) => { Ok(()) => {
is_opened = true; is_opened = true;
break; break;

@ -1,10 +1,10 @@
use ssip_client::{new_default_fifo_client, ClientName, ClientResult, OK_CLIENT_NAME_SET}; use ssip_client::{new_default_fifo_client, ClientName, ClientResult};
fn main() -> ClientResult<()> { fn main() -> ClientResult<()> {
let mut client = new_default_fifo_client(None)?; let mut client = new_default_fifo_client(None)?;
client client
.open(ClientName::new("joe", "hello"))? .set_client_name(ClientName::new("joe", "hello"))?
.check_status(OK_CLIENT_NAME_SET)?; .check_client_name_set()?;
let msg_id = client.speak()?.send_line("hello")?.receive_message_id()?; let msg_id = client.speak()?.send_line("hello")?.receive_message_id()?;
println!("message: {}", msg_id); println!("message: {}", msg_id);
client.quit()?; client.quit()?;

@ -1,6 +1,5 @@
use ssip_client::{ use ssip_client::{
ClientName, ClientResult, SynthesisVoice, OK_CLIENT_NAME_SET, OK_OUTPUT_MODULES_LIST_SENT, ClientName, ClientResult, SynthesisVoice, OK_OUTPUT_MODULES_LIST_SENT, OK_VOICES_LIST_SENT,
OK_VOICES_LIST_SENT,
}; };
fn voice_to_string(voice: &SynthesisVoice) -> String { fn voice_to_string(voice: &SynthesisVoice) -> String {
@ -23,8 +22,8 @@ fn print_list(title: &str, values: &[String]) {
fn main() -> ClientResult<()> { fn main() -> ClientResult<()> {
let mut client = ssip_client::new_default_fifo_client(None)?; let mut client = ssip_client::new_default_fifo_client(None)?;
client client
.open(ClientName::new("joe", "list"))? .set_client_name(ClientName::new("joe", "list"))?
.check_status(OK_CLIENT_NAME_SET)?; .check_client_name_set()?;
const OUTPUT_MODULE_TITLE: &str = "output modules"; const OUTPUT_MODULE_TITLE: &str = "output modules";
let modules = client let modules = client

@ -1,10 +1,10 @@
use ssip_client::{ClientName, ClientResult, EventType, NotificationType, OK_CLIENT_NAME_SET}; use ssip_client::{ClientName, ClientResult, EventType, NotificationType};
fn main() -> ClientResult<()> { fn main() -> ClientResult<()> {
let mut client = ssip_client::new_default_fifo_client(None)?; let mut client = ssip_client::new_default_fifo_client(None)?;
client client
.open(ClientName::new("joe", "notifications"))? .set_client_name(ClientName::new("joe", "notifications"))?
.check_status(OK_CLIENT_NAME_SET)?; .check_client_name_set()?;
client.enable_notification(NotificationType::All).unwrap(); client.enable_notification(NotificationType::All).unwrap();
let msg_id = client.speak()?.send_line("hello")?.receive_message_id()?; let msg_id = client.speak()?.send_line("hello")?.receive_message_id()?;
println!("message: {}", msg_id); println!("message: {}", msg_id);

@ -11,7 +11,7 @@ use std::io::{self, Read, Write};
use std::str::FromStr; use std::str::FromStr;
use thiserror::Error as ThisError; use thiserror::Error as ThisError;
use crate::constants::{OK_MESSAGE_QUEUED, OK_VOICES_LIST_SENT}; use crate::constants::*;
use crate::protocol::{send_lines, write_lines}; use crate::protocol::{send_lines, write_lines};
use crate::types::{ use crate::types::{
CapitalLettersRecognitionMode, ClientScope, Event, KeyName, MessageId, MessageScope, CapitalLettersRecognitionMode, ClientScope, Event, KeyName, MessageId, MessageScope,
@ -189,6 +189,7 @@ impl<S: Read + Write + Source> Client<S> {
}) })
} }
/// Return the only string in the list or an error if there is no line or too many.
fn parse_single_value(lines: &[String]) -> ClientResult<String> { fn parse_single_value(lines: &[String]) -> ClientResult<String> {
match lines.len() { match lines.len() {
0 => Err(ClientError::NoLine), 0 => Err(ClientError::NoLine),
@ -197,7 +198,8 @@ impl<S: Read + Write + Source> Client<S> {
} }
} }
pub fn open(&mut self, client_name: ClientName) -> ClientResult<&mut Client<S>> { /// Set the client name. It must be the first call on startup.
pub fn set_client_name(&mut self, client_name: ClientName) -> ClientResult<&mut Client<S>> {
send_lines( send_lines(
&mut self.output, &mut self.output,
&[format!( &[format!(
@ -535,6 +537,12 @@ impl<S: Read + Write + Source> Client<S> {
}) })
} }
/// Check the result of `set_client_name`.
pub fn check_client_name_set(&mut self) -> ClientResult<&mut Client<S>> {
self.check_status(OK_CLIENT_NAME_SET)
}
/// Register the socket for polling.
#[cfg(feature = "metal-io")] #[cfg(feature = "metal-io")]
pub fn register(&mut self, poll: &mio::Poll, token: mio::Token) -> ClientResult<()> { pub fn register(&mut self, poll: &mio::Poll, token: mio::Token) -> ClientResult<()> {
poll.registry().register( poll.registry().register(

@ -19,8 +19,8 @@
//! use ssip_client::{new_default_fifo_client, ClientName, OK_CLIENT_NAME_SET}; //! use ssip_client::{new_default_fifo_client, ClientName, OK_CLIENT_NAME_SET};
//! let mut client = new_default_fifo_client(None)?; //! let mut client = new_default_fifo_client(None)?;
//! client //! client
//! .open(ClientName::new("joe", "hello"))? //! .set_client_name(ClientName::new("joe", "hello"))?
//! .check_status(OK_CLIENT_NAME_SET)?; //! .check_client_name_set()?;
//! let msg_id = client.speak()?.send_line("hello")?.receive_message_id()?; //! let msg_id = client.speak()?.send_line("hello")?.receive_message_id()?;
//! client.quit()?; //! client.quit()?;
//! # Ok::<(), ssip_client::ClientError>(()) //! # Ok::<(), ssip_client::ClientError>(())

@ -111,9 +111,9 @@ where
let handle = Server::run(&server_path, communication); let handle = Server::run(&server_path, communication);
let mut client = new_fifo_client(&server_path).unwrap(); let mut client = new_fifo_client(&server_path).unwrap();
client client
.open(ClientName::new("test", "test")) .set_client_name(ClientName::new("test", "test"))
.unwrap() .unwrap()
.check_status(OK_CLIENT_NAME_SET) .check_client_name_set()
.unwrap(); .unwrap();
process_wrapper(&mut client).unwrap(); process_wrapper(&mut client).unwrap();
handle.join().unwrap() handle.join().unwrap()

Loading…
Cancel
Save