?? agateway.java
字號:
// SMSLib for Java v3
// A Java API library for sending and receiving SMS via a GSM modem
// or other supported gateways.
// Web Site: http://www.smslib.org
//
// Copyright (C) 2002-2009, Thanasis Delenikas, Athens/GREECE.
// SMSLib is distributed under the terms of the Apache License version 2.0
//
// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.smslib;
import java.io.IOException;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
import org.smslib.InboundMessage.MessageClasses;
import org.smslib.OutboundMessage.FailureCauses;
import org.smslib.OutboundMessage.MessageStatuses;
import org.smslib.StatusReportMessage.DeliveryStatuses;
import org.smslib.scheduler.ASchedulerTask;
/**
* Abstract class representing a Gateway, i.e. an interface capable of sending
* and/or receiving SMS messages.
*/
public abstract class AGateway
{
/**
* Enumeration representing the operation protocols of a GSM modem.
*/
public enum Protocols
{
/**
* PDU protocol.
*/
PDU,
/**
* TEXT protocol. <b>Warning</b>: the TEXT protocol is not yet fully
* supported.
*/
TEXT
}
public enum GatewayStatuses
{
STOPPED, STOPPING, STARTING, STARTED, FAILURE, RESTART
}
public enum AsyncEvents
{
DELETE, NOTHING, INBOUNDMESSAGE, INBOUNDSTATUSREPORTMESSAGE, INBOUNDCALL
}
public static class GatewayAttributes
{
public static final int SEND = 0x0001;
public static final int RECEIVE = 0x0002;
public static final int CUSTOMFROM = 0x0004;
public static final int BIGMESSAGES = 0x0008;
public static final int WAPSI = 0x0010;
public static final int PORTADDRESSING = 0x0020;
public static final int FLASHSMS = 0x0040;
public static final int DELIVERYREPORTS = 0x0080;
}
private String gatewayId;
private int attributes;
private boolean inbound;
private boolean outbound;
private Service srv;
private Protocols protocol;
private Statistics statistics;
private String from;
private int deliveryErrorCode;
private GatewayStatuses status;
private int restartCount;
private QueueManager queueManager;
public AGateway(String id)
{
this.gatewayId = id;
this.srv = null;
this.inbound = false;
this.outbound = false;
this.attributes = 0;
this.protocol = Protocols.PDU;
this.from = "";
this.statistics = new Statistics();
this.from = "";
this.deliveryErrorCode = -1;
this.status = GatewayStatuses.STOPPED;
this.restartCount = 0;
}
public void setAttributes(int myAttributes)
{
this.attributes = myAttributes;
}
public int getAttributes()
{
return this.attributes;
}
public Service getService()
{
return this.srv;
}
public void setService(Service mySrv)
{
this.srv = mySrv;
}
/**
* Returns true if the the gateway is set for inbound messaging.
*
* @return True if this gateway is set for inbound messaging.
*/
public boolean isInbound()
{
return this.inbound;
}
/**
* Enables or disables the gateway for inbound messaging. The command is
* accepted only if the gateway supports inbound messaging.
*
* @param value
* True to enable the gateway for inbound messaging.
*/
public void setInbound(boolean value)
{
if ((this.attributes & GatewayAttributes.RECEIVE) != 0) this.inbound = value;
}
/**
* Returns true if the the gateway is set for outbound messaging.
*
* @return True if this gateway is set for outbound messaging.
*/
public boolean isOutbound()
{
return this.outbound;
}
/**
* Enables or disables the gateway for outbound messaging. The command is
* accepted only if the gateway supports outbound messaging.
*
* @param value
* True to enable the gateway for outbound messaging.
*/
public void setOutbound(boolean value)
{
if ((this.attributes & GatewayAttributes.SEND) != 0) this.outbound = value;
}
/**
* Sets the communication protocol of the gateway. The call is applicable
* only for modem gateways, in other cases it is ignored.
*
* @param myProtocoll
* The protocol to be used.
* @see Protocols
* @see #getProtocol
*/
public void setProtocol(Protocols myProtocoll)
{
this.protocol = myProtocoll;
}
/**
* Returns the communication protocol current in use by the gateway.
*
* @return The communication protocol.
* @see Protocols
* @see #setProtocol(Protocols)
*/
public Protocols getProtocol()
{
return this.protocol;
}
/**
* Returns the gateway id assigned to this gateway during initialization.
*
* @return The gateway id.
*/
public String getGatewayId()
{
return this.gatewayId;
}
/**
* Returns the gateway status.
*
* @return The gateway status
* @see GatewayStatuses
*/
public GatewayStatuses getStatus()
{
return this.status;
}
/**
* Sets the gateway status to a new value.
*
* @param myStatus
* The new gateway status.
* @see GatewayStatuses
*/
public void setStatus(GatewayStatuses myStatus)
{
if (getService().getGatewayStatusNotification() != null) getService().getGatewayStatusNotification().process(getGatewayId(), getStatus(), myStatus);
this.status = myStatus;
}
/**
* Returns the total number of messages received by this gateway.
*
* @return The number of received messages.
*/
public int getInboundMessageCount()
{
return this.statistics.inbound;
}
public void incInboundMessageCount()
{
this.statistics.inbound++;
}
/**
* Returns the total number of messages sent via this gateway.
*
* @return The number of sent messages.
*/
public int getOutboundMessageCount()
{
return this.statistics.outbound;
}
public void incOutboundMessageCount()
{
this.statistics.outbound++;
}
/**
* Returns the string that will appear on recipient's phone as the
* originator. Not all gateways support this.
*
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -