• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.dhimpl;
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 
NativeLlcpSocket()33     public NativeLlcpSocket(){ }
34 
doConnect(int nSap)35     private native boolean doConnect(int nSap);
36     @Override
connectToSap(int sap)37     public void connectToSap(int sap) throws IOException {
38         if (!doConnect(sap)) {
39             throw new IOException();
40         }
41     }
42 
doConnectBy(String sn)43     private native boolean doConnectBy(String sn);
44     @Override
connectToService(String serviceName)45     public void connectToService(String serviceName) throws IOException {
46         if (!doConnectBy(serviceName)) {
47             throw new IOException();
48         }
49     }
50 
doClose()51     private native boolean doClose();
52     @Override
close()53     public void close() throws IOException {
54         if (!doClose()) {
55             throw new IOException();
56         }
57     }
58 
doSend(byte[] data)59     private native boolean doSend(byte[] data);
60     @Override
send(byte[] data)61     public void send(byte[] data) throws IOException {
62         if (!doSend(data)) {
63             throw new IOException();
64         }
65     }
66 
doReceive(byte[] recvBuff)67     private native int doReceive(byte[] recvBuff);
68     @Override
receive(byte[] recvBuff)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 
doGetRemoteSocketMiu()77     private native int doGetRemoteSocketMiu();
78     @Override
getRemoteMiu()79     public int getRemoteMiu() { return doGetRemoteSocketMiu(); }
80 
doGetRemoteSocketRw()81     private native int doGetRemoteSocketRw();
82     @Override
getRemoteRw()83     public int getRemoteRw() { return doGetRemoteSocketRw(); }
84 
85     @Override
getLocalSap()86     public int getLocalSap(){
87         return mSap;
88     }
89 
90     @Override
getLocalMiu()91     public int getLocalMiu(){
92         return mLocalMiu;
93     }
94 
95     @Override
getLocalRw()96     public int getLocalRw(){
97         return mLocalRw;
98     }
99 }
100