Home | History | Annotate | Download | only in map
      1 /*
      2  * Copyright (C) 2014 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 android.bluetooth.client.map;
     18 
     19 import java.io.IOException;
     20 
     21 import javax.obex.ClientSession;
     22 import javax.obex.HeaderSet;
     23 import javax.obex.ResponseCodes;
     24 
     25 class BluetoothMasRequestSetPath extends BluetoothMasRequest {
     26 
     27     enum SetPathDir {
     28         ROOT, UP, DOWN
     29     };
     30 
     31     SetPathDir mDir;
     32 
     33     String mName;
     34 
     35     public BluetoothMasRequestSetPath(String name) {
     36         mDir = SetPathDir.DOWN;
     37         mName = name;
     38 
     39         mHeaderSet.setHeader(HeaderSet.NAME, name);
     40     }
     41 
     42     public BluetoothMasRequestSetPath(boolean goRoot) {
     43         mHeaderSet.setEmptyNameHeader();
     44         if (goRoot) {
     45             mDir = SetPathDir.ROOT;
     46         } else {
     47             mDir = SetPathDir.UP;
     48         }
     49     }
     50 
     51     @Override
     52     public void execute(ClientSession session) {
     53         HeaderSet hs = null;
     54 
     55         try {
     56             switch (mDir) {
     57                 case ROOT:
     58                 case DOWN:
     59                     hs = session.setPath(mHeaderSet, false, false);
     60                     break;
     61                 case UP:
     62                     hs = session.setPath(mHeaderSet, true, false);
     63                     break;
     64             }
     65 
     66             mResponseCode = hs.getResponseCode();
     67         } catch (IOException e) {
     68             mResponseCode = ResponseCodes.OBEX_HTTP_INTERNAL_ERROR;
     69         }
     70     }
     71 }
     72