Home | History | Annotate | Download | only in nxp
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.nfc.nxp;
     18 
     19 import com.android.nfc.DeviceHost;
     20 
     21 import java.io.IOException;
     22 
     23 /**
     24  * LlcpClientSocket represents a LLCP Connection-Oriented client to be used in a
     25  * connection-oriented communication
     26  */
     27 public class NativeLlcpSocket implements DeviceHost.LlcpSocket {
     28     private int mHandle;
     29     private int mSap;
     30     private int mLocalMiu;
     31     private int mLocalRw;
     32 
     33     public NativeLlcpSocket(){ }
     34 
     35     private native boolean doConnect(int nSap);
     36     @Override
     37     public void connectToSap(int sap) throws IOException {
     38         if (!doConnect(sap)) {
     39             throw new IOException();
     40         }
     41     }
     42 
     43     private native boolean doConnectBy(String sn);
     44     @Override
     45     public void connectToService(String serviceName) throws IOException {
     46         if (!doConnectBy(serviceName)) {
     47             throw new IOException();
     48         }
     49     }
     50 
     51     private native boolean doClose();
     52     @Override
     53     public void close() throws IOException {
     54         if (!doClose()) {
     55             throw new IOException();
     56         }
     57     }
     58 
     59     private native boolean doSend(byte[] data);
     60     @Override
     61     public void send(byte[] data) throws IOException {
     62         if (!doSend(data)) {
     63             throw new IOException();
     64         }
     65     }
     66 
     67     private native int doReceive(byte[] recvBuff);
     68     @Override
     69     public int receive(byte[] recvBuff) throws IOException {
     70         int receiveLength = doReceive(recvBuff);
     71         if (receiveLength == -1) {
     72             throw new IOException();
     73         }
     74         return receiveLength;
     75     }
     76 
     77     private native int doGetRemoteSocketMiu();
     78     @Override
     79     public int getRemoteMiu() { return doGetRemoteSocketMiu(); }
     80 
     81     private native int doGetRemoteSocketRw();
     82     @Override
     83     public int getRemoteRw() { return doGetRemoteSocketRw(); }
     84 
     85     @Override
     86     public int getLocalSap(){
     87         return mSap;
     88     }
     89 
     90     @Override
     91     public int getLocalMiu(){
     92         return mLocalMiu;
     93     }
     94 
     95     @Override
     96     public int getLocalRw(){
     97         return mLocalRw;
     98     }
     99 }
    100