⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 amodemdriver.java

📁 java平台 smslib 短 信 开 发 包
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			while (isConnected())
			{
				try
				{
					event = this.eventQueue.take();
					getGateway().getService().getLogger().logDebug("Processing AsyncEvent: " + event, null, getGateway().getGatewayId());
					if (event.event == AsyncEvents.INBOUNDMESSAGE)
					{
						getGateway().getService().getLogger().logDebug("Inbound message detected!", null, getGateway().getGatewayId());
						event.event = AsyncEvents.NOTHING;
						response = event.response;
						getAsyncMessageProcessor().setProcess();
						//If SMS indication happened even it wasn't set before - set it to 'true' to
						//prevent collision of processing inbound messages by syncMessageProcessor
						if (!isCnmiActivated()) setCnmiActivated(true);
					}
					else if (event.event == AsyncEvents.INBOUNDSTATUSREPORTMESSAGE)
					{
						getGateway().getService().getLogger().logDebug("Inbound status report message detected!", null, getGateway().getGatewayId());
						event.event = AsyncEvents.NOTHING;
						response = event.response;
						getAsyncMessageProcessor().setProcess();
					}
					else if (event.event == AsyncEvents.INBOUNDCALL)
					{
						getGateway().getService().getLogger().logDebug("Inbound call detected!", null, getGateway().getGatewayId());
						event.event = AsyncEvents.NOTHING;
						synchronized (getSYNCCommander())
						{
							getGateway().getATHandler().switchToCmdMode();
							getGateway().getModemDriver().write("ATH\r");
							getGateway().getModemDriver().getResponse();
							response = event.response;
						}
						if (getGateway().getCallNotification() != null) getGateway().getCallNotification().process(getGateway().getGatewayId(), getOriginator(response));
						if (getGateway().getService().getCallNotification() != null) getGateway().getService().getCallNotification().process(getGateway().getGatewayId(), getOriginator(response));
					}
				}
				catch (InterruptedException e)
				{
					if (!isConnected()) break;
				}
				catch (GatewayException e)
				{
					// Swallow this...
				}
				catch (IOException e)
				{
					// Swallow this...
				}
				catch (TimeoutException e)
				{
					// Swallow this...
				}
			}
			getGateway().getService().getLogger().logDebug("AsyncNotifier thread ended.", null, getGateway().getGatewayId());
		}
	}

	private class AsyncMessageProcessor extends Thread
	{
		private List<InboundMessage> msgList;

		private Object SYNC;

		private boolean process;

		public AsyncMessageProcessor()
		{
			this.msgList = new ArrayList<InboundMessage>();
			this.SYNC = new Object();
			this.process = false;
			setPriority(MAX_PRIORITY);
			setName("SMSLib-AsyncMessageProcessor : " + getGateway().getGatewayId());
			setDaemon(true);
			start();
			getGateway().getService().getLogger().logDebug("AsyncMessageProcessor thread started.", null, getGateway().getGatewayId());
		}

		public void setProcess()
		{
			synchronized (this.SYNC)
			{
				if (this.process) return;
				this.process = true;
				this.SYNC.notify();
			}
		}

		@SuppressWarnings("deprecation")
		@Override
		public void run()
		{
			while (isConnected())
			{
				try
				{
					synchronized (this.SYNC)
					{
						if (!this.process)
						{
							this.SYNC.wait();
							if (!isConnected()) break;
						}
					}
					if ((getGateway().getInboundNotification() != null) || (getGateway().getService().getInboundNotification() != null))
					{
						synchronized (getSYNCInboundReader())
						{
							getGateway().readMessages(this.msgList, MessageClasses.ALL);
							for (InboundMessage msg : this.msgList)
							{
								switch (msg.getType())
								{
									case INBOUND:
									case STATUSREPORT:
										if (getGateway().getInboundNotification() != null) getGateway().getInboundNotification().process(getGateway().getGatewayId(), msg.getType(), msg);
										if (getGateway().getService().getInboundNotification() != null) getGateway().getService().getInboundNotification().process(getGateway().getGatewayId(), msg.getType(), msg);
										break;
									default:
										break;
								}
							}
						}
					}
					this.msgList.clear();
					this.process = false;
				}
				catch (InterruptedException e)
				{
					if (!isConnected()) break;
				}
				catch (GatewayException e)
				{
					// Swallow this...
				}
				catch (IOException e)
				{
					// Swallow this...
				}
				catch (TimeoutException e)
				{
					// Swallow this...
				}
			}
			getGateway().getService().getLogger().logDebug("AsyncMessageProcessor thread ended.", null, getGateway().getGatewayId());
		}
	}

	private class CNMIEmulatorProcessor extends Thread
	{
		private List<InboundMessage> msgList;

		public CNMIEmulatorProcessor()
		{
			this.msgList = new ArrayList<InboundMessage>();
			setName("SMSLib-CNMIEmulator : " + getGateway().getGatewayId());
			start();
			getGateway().getService().getLogger().logDebug("SyncMessageProcessor thread started.", null, getGateway().getGatewayId());
		}

		@Override
		public void run()
		{
			//messages are forced to be read at least once during startup. After that messages are processed
			//by async or sync threads depending on smsIndications value
			boolean firstRun = true;
			if (isCnmiActivated()) firstRun = false;
			//Wait a bit until gateway is up and running...
			while (getGateway().getStatus() != GatewayStatuses.RUNNING)
			{
				try
				{
					Thread.sleep(getGateway().getService().S.SYNC_MSG_PROC_INTERVAL / 10);
				}
				catch (InterruptedException e)
				{
					break;
				}
			}
			while (isConnected())
			{
				try
				{
					if (firstRun || !isCnmiActivated())
					{
						firstRun = false;
						if ((getGateway().getInboundNotification() != null) || (getGateway().getService().getInboundNotification() != null))
						{
							synchronized (getSYNCInboundReader())
							{
								getGateway().readMessages(this.msgList, MessageClasses.ALL);
								for (InboundMessage msg : this.msgList)
								{
									switch (msg.getType())
									{
										case INBOUND:
										case STATUSREPORT:
											if (getGateway().getInboundNotification() != null) getGateway().getInboundNotification().process(getGateway().getGatewayId(), msg.getType(), msg);
											if (getGateway().getService().getInboundNotification() != null) getGateway().getService().getInboundNotification().process(getGateway().getGatewayId(), msg.getType(), msg);
											break;
										default:
											break;
									}
								}
							}
						}
					}
					this.msgList.clear();
					Thread.sleep(getGateway().getService().S.SYNC_MSG_PROC_INTERVAL);
					if (!isConnected()) break;
				}
				catch (InterruptedException e)
				{
					if (!isConnected()) break;
				}
				catch (GatewayException e)
				{
					// Swallow this...
				}
				catch (IOException e)
				{
					// Swallow this...
				}
				catch (TimeoutException e)
				{
					// Swallow this...
				}
			}
			getGateway().getService().getLogger().logDebug("SyncMessageProcessor thread ended.", null, getGateway().getGatewayId());
		}
	}

	void setLastError(int myLastError)
	{
		this.lastError = myLastError;
	}

	public int getLastError()
	{
		return this.lastError;
	}

	public String getLastErrorText()
	{
		if (getLastError() == 0) return "OK";
		else if (getLastError() == -1) return "Invalid or empty response";
		else if ((getLastError() / 1000) == 5) return "CME Error " + (getLastError() % 1000);
		else if ((getLastError() / 1000) == 6) return "CMS Error " + (getLastError() % 1000);
		else return "Error: unknown";
	}

	public boolean isOk()
	{
		return (getLastError() == OK);
	}

	protected ModemGateway getGateway()
	{
		return this.gateway;
	}

	protected void setGateway(ModemGateway myGateway)
	{
		this.gateway = myGateway;
	}

	protected boolean isConnected()
	{
		return this.connected;
	}

	protected void setConnected(boolean myConnected)
	{
		this.connected = myConnected;
	}

	protected boolean isDataReceived()
	{
		return this.dataReceived;
	}

	protected void setDataReceived(boolean myDataReceived)
	{
		this.dataReceived = myDataReceived;
	}

	protected boolean isCnmiActivated()
	{
		return this.cnmiActivated;
	}

	protected void setCnmiActivated(boolean myCnmiActivated)
	{
		this.cnmiActivated = myCnmiActivated;
	}

	protected CharQueue getCharQueue()
	{
		return this.charQueue;
	}

	protected void setCharQueue(CharQueue myCharQueue)
	{
		this.charQueue = myCharQueue;
	}

	protected Object getSYNCReader()
	{
		return this.SYNC_Reader;
	}

	protected void setSYNCReader(Object reader)
	{
		this.SYNC_Reader = reader;
	}

	protected Object getSYNCCommander()
	{
		return this.SYNC_Commander;
	}

	protected void setSYNCCommander(Object commander)
	{
		this.SYNC_Commander = commander;
	}

	protected Object getSYNCInboundReader()
	{
		return this.SYNC_InboundReader;
	}

	protected void setSYNCInboundReader(Object inbMessage)
	{
		this.SYNC_InboundReader = inbMessage;
	}

	protected KeepAlive getKeepAlive()
	{
		return this.keepAlive;
	}

	protected void setKeepAlive(KeepAlive myKeepAlive)
	{
		this.keepAlive = myKeepAlive;
	}

	protected AsyncNotifier getAsyncNotifier()
	{
		return this.asyncNotifier;
	}

	protected void setAsyncNotifier(AsyncNotifier myAsyncNotifier)
	{
		this.asyncNotifier = myAsyncNotifier;
	}

	protected AsyncMessageProcessor getAsyncMessageProcessor()
	{
		return this.asyncMessageProcessor;
	}

	protected void setAsyncMessageProcessor(AsyncMessageProcessor myAsyncMessageProcessor)
	{
		this.asyncMessageProcessor = myAsyncMessageProcessor;
	}

	protected CNMIEmulatorProcessor getCnmiEmulationProcessor()
	{
		return this.cnmiEmulationProcessor;
	}

	protected void setCnmiEmulationProcessor(CNMIEmulatorProcessor myCnmiEmulationProcessor)
	{
		this.cnmiEmulationProcessor = myCnmiEmulationProcessor;
	}

	protected ModemReader getModemReader()
	{
		return this.modemReader;
	}

	protected void setModemReader(ModemReader myModemReader)
	{
		this.modemReader = myModemReader;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -