#![deny(missing_docs)]
#![doc(test(attr(allow(unused_variables), deny(warnings))))]
#[macro_use]
extern crate lazy_static;
extern crate tokio_io;
extern crate tokio_service;
extern crate tokio_proto;
extern crate futures;
extern crate bytes;
pub mod escape;
mod codec;
mod protocol;
mod error_codes;
mod command;
mod transaction;
use tokio_service::Service;
use futures::{future, Future, BoxFuture};
use std::io;
use tokio_proto::TcpServer;
use std::net::{IpAddr, SocketAddr, Ipv4Addr};
use protocol::DbgpProto;
lazy_static! {
static ref DEFAULT_IP_ADDR: Ipv4Addr = {
Ipv4Addr::new(127,0,0,1)
};
}
static DEFAULT_PORT: u16 = 9000;
enum BreakReason {
Ok,
Error,
Aborted,
Exception,
}
enum SessionStatus {
Starting,
Stopping,
Stopped,
Running,
Break(BreakReason),
}
pub struct Session {
address: SocketAddr,
status: Option<SessionStatus>,
}
impl Session {
pub fn new() -> Session {
Session {
address: SocketAddr::new(IpAddr::V4(*DEFAULT_IP_ADDR), DEFAULT_PORT),
status: None,
}
}
pub fn address(mut self, addr: IpAddr) -> Self {
self.address.set_ip(addr);
self
}
pub fn port(mut self, port: u16) -> Self {
self.address.set_port(port);
self
}
pub fn run(self) {
let server = TcpServer::new(DbgpProto, self.address);
server.serve(|| Ok(Echo));
}
}
pub struct Echo;
impl Service for Echo {
type Request = String;
type Response = String;
type Error = io::Error;
type Future = BoxFuture<Self::Response, Self::Error>;
fn call(&self, req: Self::Request) -> Self::Future {
future::ok(req).boxed()
}
}