gloox  1.1-svn
jingledtmf.cpp
1 /*
2  Copyright (c) 2009 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 #include "jingledtmf.h"
15 #include "gloox.h"
16 #include "tag.h"
17 
18 #include <cstdlib>
19 
20 namespace gloox
21 {
22 
23  namespace Jingle
24  {
25 
26  DTMF::DTMF( const std::string& code, int volume, int duration )
27  : m_code( code ), m_volume( volume ), m_duration( duration )
28  {
29  }
30 
31  DTMF::DTMF( const Tag* tag )
32  : m_volume( 63 ), m_duration( 0 )
33  {
34  if( !tag || tag->name() != "dtmf" || tag->xmlns() != XMLNS_JINGLE_DTMF )
35  return;
36 
37  m_code = tag->findAttribute( "code" );
38  m_volume = strtol( tag->findAttribute( "volume" ).c_str(), 0, 10 );
39  m_duration = strtol( tag->findAttribute( "duration" ).c_str(), 0, 10 );
40  }
41 
42  const std::string& DTMF::filterString() const
43  {
44  static const std::string filter = "dtmf[@xmlns='" + XMLNS_JINGLE_DTMF + "']";
45  return filter;
46  }
47 
48  Tag* DTMF::tag() const
49  {
50  if( m_code.empty() )
51  return 0;
52 
53  Tag* t = new Tag( "dtmf" );
55  t->addAttribute( "code", m_code.substr( 0, 1 ) );
56  t->addAttribute( "volume", m_volume );
57  t->addAttribute( "duration", m_duration );
58 
59  return t;
60  }
61 
62  }
63 
64 }