<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][14774] </title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=14774">14774</a></dd>
<dt>Author</dt> <dd>michaelgg</dd>
<dt>Date</dt> <dd>2009-09-05 12:34:41 -0500 (Sat, 05 Sep 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>Start adding some strongly-typed accessors to common channel vars</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcmodlanguagesmod_managedmanagedFreeSWITCHManagedcsproj">freeswitch/trunk/src/mod/languages/mod_managed/managed/FreeSWITCH.Managed.csproj</a></li>
<li><a href="#freeswitchtrunksrcmodlanguagesmod_managedmanagedManagedSessioncs">freeswitch/trunk/src/mod/languages/mod_managed/managed/ManagedSession.cs</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcmodlanguagesmod_managedmanagedChannelVariablescs">freeswitch/trunk/src/mod/languages/mod_managed/managed/ChannelVariables.cs</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcmodlanguagesmod_managedmanagedChannelVariablescs"></a>
<div class="addfile"><h4>Added: freeswitch/trunk/src/mod/languages/mod_managed/managed/ChannelVariables.cs (0 => 14774)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/languages/mod_managed/managed/ChannelVariables.cs         (rev 0)
+++ freeswitch/trunk/src/mod/languages/mod_managed/managed/ChannelVariables.cs        2009-09-05 17:34:41 UTC (rev 14774)
</span><span class="lines">@@ -0,0 +1,231 @@
</span><ins>+/*
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_managed
+ * Copyright (C) 2008, Michael Giagnocavo <mgg@giagnocavo.net>
+ *
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - mod_managed
+ *
+ * The Initial Developer of the Original Code is
+ * Michael Giagnocavo <mgg@giagnocavo.net>
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Michael Giagnocavo <mgg@giagnocavo.net>
+ *
+ * ChannelVariables.cs -- Strongly typed channel variables for ManagedSession
+ *
+ */
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Runtime.InteropServices;
+
+namespace FreeSWITCH.Native {
+ public partial class ManagedSession {
+
+ // Need to find a better place to put these - then make them public
+ static readonly DateTime epoch = new DateTime(1970, 1, 1);
+ static DateTime epochUsToDateTime(long us){
+ return us == 0 ?
+ DateTime.MinValue :
+ epoch.AddMilliseconds((double)((decimal)us / 1000m));
+ }
+ static bool strToBool(string s) {
+ if (string.IsNullOrEmpty(s)) return false;
+ switch (s.ToLowerInvariant()) {
+ case "true":
+ case "yes":
+ case "on":
+ case "enable":
+ case "enabled":
+ case "active":
+ case "allow":
+ return true;
+ default:
+ // Numbers are true
+ long tmp;
+ return long.TryParse(s, out tmp);
+ }
+ }
+ static string boolToStr(bool b) {
+ return b ? "true" : "false";
+ }
+
+ ChannelVariables _variables; // Set on ManagedSession init
+ public ChannelVariables Variables {
+ get {
+ if (_variables == null) {
+ _variables = new ChannelVariables(this);
+ }
+ return _variables;
+ }
+ }
+
+ /// <summary>Strongly typed access to common variables</summary>
+ public class ChannelVariables {
+ readonly ManagedSession sess;
+ internal ChannelVariables(ManagedSession session) {
+ this.sess = session;
+ }
+
+ public IDictionary<string, string> GetAllVariables() {
+ var dic = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
+ var evt = Native.freeswitch.switch_channel_variable_first(sess.channel);
+ while(evt != null) {
+ dic.Add(evt.name, evt.value);
+ evt = evt.next;
+ }
+ Native.freeswitch.switch_channel_variable_last(sess.channel);
+ return dic;
+ }
+
+ /*** Settings ***/
+ const string bypass_media = "bypass_media";
+ public bool BypassMedia {
+ get { return strToBool(sess.GetVariable(bypass_media)); }
+ set { sess.SetVariable(bypass_media, boolToStr(value)); }
+ }
+
+ /*** Times ***/
+ const string created_time = "created_time";
+ const string answered_time = "answered_time";
+ const string hangup_time = "hangup_time";
+ const string progress_time = "progress_time";
+ const string transfer_time = "transfer_time";
+
+ public DateTime CreatedTime {
+ get { return epochUsToDateTime(long.Parse(sess.GetVariable(created_time))); }
+ }
+
+ DateTime? readUsecsDateTime(string varName) {
+ var v = sess.GetVariable(varName);
+ if (string.IsNullOrEmpty(v)) return null;
+ else {
+ var d = epochUsToDateTime(long.Parse(v));
+ if (d == DateTime.MinValue) return null;
+ return d;
+ }
+ }
+
+ public DateTime? AnsweredTime {
+ get { return readUsecsDateTime(answered_time); }
+ }
+ public DateTime? HangupTime {
+ get { return readUsecsDateTime(hangup_time); }
+ }
+ public DateTime? ProgressTime {
+ get { return readUsecsDateTime(progress_time); }
+ }
+ public DateTime? TransferTime {
+ get { return readUsecsDateTime(transfer_time); }
+ }
+
+
+ /*** SIP Variables ***/
+ const string sofia_profile_name = "sofia_profile_name";
+ const string sip_received_ip = "sip_received_ip";
+ const string sip_received_port = "sip_received_port";
+ const string sip_via_protocol = "sip_via_protocol";
+ const string sip_from_user = "sip_from_user";
+ const string sip_from_uri = "sip_from_uri";
+ const string sip_from_host = "sip_from_host";
+ const string sip_req_user = "sip_req_user";
+ const string sip_req_uri = "sip_req_uri";
+ const string sip_req_host = "sip_req_host";
+ const string sip_to_user = "sip_to_user";
+ const string sip_to_uri = "sip_to_uri";
+ const string sip_to_host = "sip_to_host";
+ const string sip_contact_user = "sip_contact_user";
+ const string sip_contact_port = "sip_contact_port";
+ const string sip_contact_uri = "sip_contact_uri";
+ const string sip_contact_host = "sip_contact_host";
+ const string sip_call_id = "sip_call_id";
+ const string sip_destination_url = "sip_destination_url";
+ const string sip_term_status = "sip_term_status";
+ const string sip_term_cause = "sip_term_status";
+ const string switch_r_sdp = "switch_r_sdp";
+ const string switch_m_sdp = "switch_m_sdp";
+ const string sip_hangup_phrase = "sip_hangup_phrase";
+
+
+ short? readShort(string varName) {
+ var s = sess.GetVariable(varName);
+ if (string.IsNullOrEmpty(s)) return null;
+ short res;
+ if (short.TryParse(s, out res)) return res;
+ else return null;
+ }
+ int? readInt(string varName) {
+ var s = sess.GetVariable(varName);
+ if (string.IsNullOrEmpty(s)) return null;
+ int res;
+ if (int.TryParse(s, out res)) return res;
+ else return null;
+ }
+
+ // String suffix is added when the var is better represented as
+ // a different data type, but for now we return string
+
+ public string SofiaProfileName { get { return sess.GetVariable(sofia_profile_name); } }
+ public string SipCallID { get { return sess.GetVariable(sip_call_id); } }
+ public string SipReceivedIP { get { return sess.GetVariable(sip_received_ip); } }
+ public short? SipReceivedPort { get { return readShort(sip_received_port); } }
+ public string SipViaProtocolString { get { return sess.GetVariable(sip_via_protocol); } }
+ public string SipFromUser { get { return sess.GetVariable(sip_from_user); } }
+ public string SipFromUriString { get { return sess.GetVariable(sip_from_uri); } }
+ public string SipFromHost { get { return sess.GetVariable(sip_from_host); } }
+ public string SipReqUser { get { return sess.GetVariable(sip_req_user); } }
+ public string SipReqUriString { get { return sess.GetVariable(sip_req_uri); } }
+ public string SipReqHost { get { return sess.GetVariable(sip_req_host); } }
+ public string SipToUser { get { return sess.GetVariable(sip_to_user); } }
+ public string SipToUriString { get { return sess.GetVariable(sip_to_uri); } }
+ public string SipToHost { get { return sess.GetVariable(sip_to_host); } }
+ public string SipContactUser { get { return sess.GetVariable(sip_contact_user); } }
+ public string SipContactUriString { get { return sess.GetVariable(sip_contact_uri); } }
+ public string SipContactHost { get { return sess.GetVariable(sip_contact_host); } }
+ public short? SipContactPort { get { return readShort(sip_contact_port); } }
+ public string SipDestinationUrlString { get { return sess.GetVariable(sip_destination_url); } }
+ public int? SipTermStatus { get { return readInt(sip_term_status); } }
+ public int? SipTermCause { get { return readInt(sip_term_cause); } }
+ public string SwitchRSdp { get { return sess.GetVariable(switch_r_sdp); } }
+ public string SwitchMSdp { get { return sess.GetVariable(switch_m_sdp); } }
+ public string SipHangupPhrase { get { return sess.GetVariable(sip_hangup_phrase); } }
+
+ /*** Other ***/
+
+ const string proto_specific_hangup_cause = "proto_specific_hangup_cause";
+ const string hangup_cause = "hangup_cause";
+ const string hangup_cause_q850 = "hangup_cause_q850";
+ const string originate_disposition = "originate_disposition";
+ const string direction = "direction";
+
+ public string ProtoSpecificHangupCause { get { return sess.GetVariable(proto_specific_hangup_cause); } }
+ public string HangupCauseString { get { return sess.GetVariable(hangup_cause); } }
+ public int? HangupCauseQ850 { get { return readInt(hangup_cause_q850); } }
+ public string OriginateDispositionString { get { return sess.GetVariable(originate_disposition); } }
+
+ public Native.switch_call_direction_t CallDirection {
+ get {
+ var s = sess.GetVariable(direction);
+ if (string.IsNullOrEmpty(s)) return switch_call_direction_t.SWITCH_CALL_DIRECTION_INBOUND; // I guess
+ return s.ToLowerInvariant() == "inbound" ? switch_call_direction_t.SWITCH_CALL_DIRECTION_INBOUND : switch_call_direction_t.SWITCH_CALL_DIRECTION_OUTBOUND;
+ }
+
+ }
+ }
+ }
+}
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="freeswitchtrunksrcmodlanguagesmod_managedmanagedFreeSWITCHManagedcsproj"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/languages/mod_managed/managed/FreeSWITCH.Managed.csproj (14773 => 14774)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/languages/mod_managed/managed/FreeSWITCH.Managed.csproj        2009-09-05 16:55:45 UTC (rev 14773)
+++ freeswitch/trunk/src/mod/languages/mod_managed/managed/FreeSWITCH.Managed.csproj        2009-09-05 17:34:41 UTC (rev 14774)
</span><span class="lines">@@ -48,6 +48,7 @@
</span><span class="cx"> </ItemGroup>
</span><span class="cx"> <ItemGroup>
</span><span class="cx"> <Compile Include="AssemblyInfo.cs" />
</span><ins>+ <Compile Include="ChannelVariables.cs" />
</ins><span class="cx"> <Compile Include="ManagedSession.cs" />
</span><span class="cx"> <Compile Include="Loader.cs" />
</span><span class="cx"> <Compile Include="Extensions.cs" />
</span></span></pre></div>
<a id="freeswitchtrunksrcmodlanguagesmod_managedmanagedManagedSessioncs"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/languages/mod_managed/managed/ManagedSession.cs (14773 => 14774)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/languages/mod_managed/managed/ManagedSession.cs        2009-09-05 16:55:45 UTC (rev 14773)
+++ freeswitch/trunk/src/mod/languages/mod_managed/managed/ManagedSession.cs        2009-09-05 17:34:41 UTC (rev 14774)
</span><span class="lines">@@ -52,6 +52,9 @@
</span><span class="cx"> /// <summary>Initializes the native ManagedSession. Must be called after Originate.</summary>
</span><span class="cx"> public void Initialize()
</span><span class="cx"> {
</span><ins>+ if (allocated == 0) {
+ Log.WriteLine(LogLevel.Critical, "Cannot initialize a ManagedSession until it is allocated (originated successfully).");
+ }
</ins><span class="cx"> // P/Invoke generated function pointers stick around until the delegate is collected
</span><span class="cx"> // By sticking the delegates in fields, their lifetime won't be less than the session
</span><span class="cx"> // So we don't need to worry about GCHandles and all that....
</span><span class="lines">@@ -59,6 +62,7 @@
</span><span class="cx"> this._inputCallbackRef = inputCallback;
</span><span class="cx"> this._hangupCallbackRef = hangupCallback;
</span><span class="cx"> InitManagedSession(ManagedSession.getCPtr(this).Handle, this._inputCallbackRef, this._hangupCallbackRef);
</span><ins>+ this._variables = new ChannelVariables(this);
</ins><span class="cx"> }
</span><span class="cx"> DtmfCallback _inputCallbackRef;
</span><span class="cx"> CdeclAction _hangupCallbackRef;
</span><span class="lines">@@ -122,15 +126,9 @@
</span><span class="cx"> get { return this.Ready(); }
</span><span class="cx"> }
</span><span class="cx">
</span><del>- Guid _uuid;
- bool _uuidSet;
</del><span class="cx"> public Guid Uuid {
</span><span class="cx"> get {
</span><del>- if (!_uuidSet) {
- _uuid = new Guid(this.GetUuid());
- _uuidSet = true;
- }
- return _uuid;
</del><ins>+ return new Guid(this.GetUuid());
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>