PageRenderTime 36ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/protocols/ss7/hardware/dialogic/java/src/main/java/org/mobicents/ss7/hardware/dialogic/oam/DialogicLinkset.java

http://mobicents.googlecode.com/
Java | 302 lines | 134 code | 57 blank | 111 comment | 7 complexity | a902646c579e1b6ed27434585f9a0bc6 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.mobicents.ss7.hardware.dialogic.oam;
  23. import java.io.IOException;
  24. import java.nio.ByteBuffer;
  25. import javolution.xml.XMLFormat;
  26. import javolution.xml.stream.XMLStreamException;
  27. import org.apache.log4j.Logger;
  28. import org.mobicents.protocols.stream.api.SelectorKey;
  29. import org.mobicents.protocols.stream.api.SelectorProvider;
  30. import org.mobicents.protocols.stream.api.StreamSelector;
  31. import org.mobicents.ss7.hardware.dialogic.InterProcessCommunicator;
  32. import org.mobicents.ss7.linkset.oam.FormatterHelp;
  33. import org.mobicents.ss7.linkset.oam.LinkOAMMessages;
  34. import org.mobicents.ss7.linkset.oam.Linkset;
  35. import org.mobicents.ss7.linkset.oam.LinksetMode;
  36. import org.mobicents.ss7.linkset.oam.LinksetSelector;
  37. import org.mobicents.ss7.linkset.oam.LinksetState;
  38. import org.mobicents.ss7.linkset.oam.LinksetStream;
  39. /**
  40. * <p>
  41. * Linkset for <tt>dialogic</tt> based hardware. <tt>dialogic</tt> boards
  42. * have MTP2 and MTP3 support on board.
  43. * </p>
  44. *
  45. * @author amit bhayani
  46. *
  47. */
  48. public class DialogicLinkset extends Linkset {
  49. private static final Logger logger = Logger.getLogger(DialogicLinkset.class);
  50. private static final String SRC_MODULE = "srcMod";
  51. private static final String DEST_MODULE = "destMod";
  52. private InterProcessCommunicator ipc;
  53. private int sourceModule;
  54. private int destModule;
  55. public DialogicLinkset() {
  56. super();
  57. }
  58. public DialogicLinkset(String linksetName, int opc, int dpc, int ni, int srcMod, int dstMod) {
  59. super(linksetName, opc, dpc, ni);
  60. this.sourceModule = srcMod;
  61. this.destModule = dstMod;
  62. }
  63. public int getSourceModule() {
  64. return sourceModule;
  65. }
  66. public void setSourceModule(int sourceModule) {
  67. this.sourceModule = sourceModule;
  68. }
  69. public int getDestModule() {
  70. return destModule;
  71. }
  72. public void setDestModule(int destModule) {
  73. this.destModule = destModule;
  74. }
  75. @Override
  76. protected void initialize() {
  77. // this.linksetStream = new LinksetStreamImpl();
  78. }
  79. @Override
  80. protected void configure() throws Exception {
  81. if (this.mode == LinksetMode.CONFIGURED) {
  82. ipc = new InterProcessCommunicator(this.sourceModule, this.destModule);
  83. }
  84. }
  85. @Override
  86. public void activate() throws Exception {
  87. if (this.state == LinksetState.AVAILABLE) {
  88. throw new Exception(LinkOAMMessages.LINKSET_ALREADY_ACTIVE);
  89. }
  90. this.mode = LinksetMode.CONFIGURED;
  91. this.configure();
  92. }
  93. @Override
  94. public void deactivate() throws Exception {
  95. throw new Exception(LinkOAMMessages.NOT_IMPLEMENTED);
  96. }
  97. @Override
  98. public void activateLink(String linkName) throws Exception {
  99. throw new Exception(LinkOAMMessages.OPERATION_NOT_SUPPORTED);
  100. }
  101. @Override
  102. public void deactivateLink(String linkName) throws Exception {
  103. throw new Exception(LinkOAMMessages.OPERATION_NOT_SUPPORTED);
  104. }
  105. @Override
  106. public void createLink(String[] arg0) throws Exception {
  107. throw new Exception(LinkOAMMessages.NOT_IMPLEMENTED);
  108. }
  109. @Override
  110. public void deleteLink(String arg0) throws Exception {
  111. throw new Exception(LinkOAMMessages.NOT_IMPLEMENTED);
  112. }
  113. protected static final XMLFormat<DialogicLinkset> DAHDI_LINK_XML = new XMLFormat<DialogicLinkset>(
  114. DialogicLinkset.class) {
  115. @Override
  116. public void read(javolution.xml.XMLFormat.InputElement xml, DialogicLinkset linkset) throws XMLStreamException {
  117. LINKSET_XML.read(xml, linkset);
  118. linkset.sourceModule = xml.getAttribute(SRC_MODULE, -1);
  119. linkset.destModule = xml.getAttribute(DEST_MODULE, -1);
  120. try {
  121. linkset.configure();
  122. } catch (Exception e) {
  123. logger.error("Failed to initialize dialogic card", e);
  124. }
  125. }
  126. @Override
  127. public void write(DialogicLinkset linkset, javolution.xml.XMLFormat.OutputElement xml)
  128. throws XMLStreamException {
  129. LINKSET_XML.write(linkset, xml);
  130. xml.setAttribute(SRC_MODULE, linkset.sourceModule);
  131. xml.setAttribute(DEST_MODULE, linkset.destModule);
  132. }
  133. };
  134. // private class LinksetStreamImpl extends LinksetStream {
  135. // ByteBuffer rxData = null;
  136. //
  137. // @Override
  138. // public boolean poll(int arg0, int arg1) {
  139. // rxData = null;
  140. // try {
  141. // if (ipc != null) {
  142. // rxData = ipc.read(null);
  143. // return true;
  144. // }
  145. // } catch (IOException ex) {
  146. // logger.error("IO error while receiving data from InterProcessCommunicator", ex);
  147. // }
  148. // return false;
  149. // }
  150. //
  151. // @Override
  152. // public String getName() {
  153. // return linksetName;
  154. // }
  155. //
  156. // public void close() {
  157. // // TODO Auto-generated method stub
  158. //
  159. // }
  160. //
  161. // public SelectorProvider provider() {
  162. // throw new UnsupportedOperationException("Not supported yet.");
  163. // }
  164. //
  165. // public int read(byte[] paramArrayOfByte) throws IOException {
  166. // if (rxData != null) {
  167. // System.arraycopy(rxData, 0, paramArrayOfByte, 0, rxData.length);
  168. // return rxData.length;
  169. // }
  170. //
  171. // return 0;
  172. // }
  173. //
  174. // public SelectorKey register(StreamSelector selector) throws IOException {
  175. // return ((LinksetSelector) selector).register(this);
  176. // }
  177. //
  178. // public int write(byte[] paramArrayOfByte) throws IOException {
  179. // ipc.send(paramArrayOfByte);
  180. // return paramArrayOfByte.length;
  181. // }
  182. //
  183. // @Override
  184. // public int read(ByteBuffer arg0) throws IOException {
  185. // // TODO Auto-generated method stub
  186. // return 0;
  187. // }
  188. //
  189. // @Override
  190. // public int write(ByteBuffer arg0) throws IOException {
  191. // // TODO Auto-generated method stub
  192. // return 0;
  193. // }
  194. // }
  195. @Override
  196. public void print(StringBuffer sb, int leftPad, int descPad) {
  197. // left pad
  198. FormatterHelp.createPad(sb, leftPad);
  199. // Add name
  200. sb.append(this.linksetName);
  201. // check if length is less than Link.NAME_SIZE, add padding
  202. if (this.linksetName.length() < Linkset.NAME_SIZE) {
  203. FormatterHelp.createPad(sb, Linkset.NAME_SIZE - this.linksetName.length());
  204. }
  205. // add desc padding
  206. FormatterHelp.createPad(sb, descPad);
  207. // type is dahdi
  208. sb.append("dialogic");
  209. // add desc padding
  210. FormatterHelp.createPad(sb, descPad);
  211. // add opc
  212. sb.append(LINKSET_OPC).append(FormatterHelp.EQUAL_SIGN).append(this.opc);
  213. // opc can be max 8 (ANSI is max 24bits) digits. Add padding if its not
  214. int length = (Integer.toString(this.opc).length());
  215. if (length < 8) {
  216. FormatterHelp.createPad(sb, 8 - length);
  217. }
  218. // add desc padding
  219. FormatterHelp.createPad(sb, descPad);
  220. // add apc
  221. sb.append(LINKSET_APC).append(FormatterHelp.EQUAL_SIGN).append(this.apc);
  222. // opc can be max 8 (ANSI is max 24bits) digits. Add padding if its not
  223. length = (Integer.toString(this.apc).length());
  224. if (length < 8) {
  225. FormatterHelp.createPad(sb, 8 - length);
  226. }
  227. // add desc padding
  228. FormatterHelp.createPad(sb, descPad);
  229. // add NI
  230. sb.append(LINKSET_NI).append(FormatterHelp.EQUAL_SIGN).append(this.ni);
  231. // add desc padding
  232. FormatterHelp.createPad(sb, descPad);
  233. // add Source Module
  234. sb.append(SRC_MODULE).append(FormatterHelp.EQUAL_SIGN).append(this.sourceModule);
  235. // add desc padding
  236. FormatterHelp.createPad(sb, descPad);
  237. // add dest Module
  238. sb.append(DEST_MODULE).append(FormatterHelp.EQUAL_SIGN).append(this.destModule);
  239. // add desc padding
  240. FormatterHelp.createPad(sb, descPad);
  241. // add state
  242. sb.append(LINKSET_STATE).append(FormatterHelp.EQUAL_SIGN).append(FormatterHelp.getLinksetState(this.state));
  243. sb.append(FormatterHelp.NEW_LINE);
  244. }
  245. }