Skip to content

Commit

Permalink
Start mod_prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
moises-silva committed Aug 6, 2016
0 parents commit 46b4b8a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "mod_prometheus"
version = "0.1.0"
authors = ["Moises Silva <[email protected]>"]

[dependencies]

[dependencies.freeswitchrs]
path = ".."

[lib]
crate-type = ["dylib"]
name = "mod_prometheus"
path = "mod_prometheus.rs"

[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"

39 changes: 39 additions & 0 deletions mod_prometheus.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#[macro_use]
extern crate freeswitchrs;

use freeswitchrs::raw as fsr;
use freeswitchrs::mods::*; // This will get replaced with a mods prelude
use freeswitchrs::Status;
use std::borrow::Cow;

fn prometheus_load(mod_int: &ModInterface) -> Status {
mod_int.add_raw_api("counter_increase", "Increase counter", "counter_increase", counter_increase_api);

// Example of binding to an event
/*
freeswitchrs::event_bind("asd", fsr::event_types::ALL, None, |e| {
let s = e.subclass_name();
let b = e.body().unwrap_or(Cow::Borrowed("<No Body>"));
println!("{:?}/{:?} {} = {:?}", e.event_id(), s, e.flags(), b)
});
*/
Ok(())
}

static MOD_PROMETHEUS_DEF: ModDefinition = ModDefinition {
name: "mod_prometheus",
load: prometheus_load,
shutdown: None,
runtime: None,
};

freeswitch_export_mod!(mod_prometheus_module_interface, MOD_PROMETHEUS_DEF);

#[allow(unused_variables)]
unsafe extern "C" fn counter_increase_api(cmd: *const std::os::raw::c_char,
session: *mut fsr::core_session,
stream: *mut fsr::stream_handle)
-> fsr::status {
(*stream).write_function.unwrap()(stream, fsr::str_to_ptr("OK"));
fsr::status::SUCCESS
}

0 comments on commit 46b4b8a

Please sign in to comment.