3f879bbf6d15b06de114bd82272cc449ec38d931
[platform/core/connectivity/smartcard-service.git] / common / include / FileObject.h
1 /*
2  * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
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 #ifndef FILEOBJECT_H_
18 #define FILEOBJECT_H_
19
20 #include <vector>
21
22 #include "Debug.h"
23 #include "ProviderHelper.h"
24 #include "ByteArray.h"
25 #include "FCI.h"
26 #include "Record.h"
27
28 using namespace std;
29
30 namespace smartcard_service_api
31 {
32         class EXPORT FileObject : public ProviderHelper
33         {
34         private:
35                 FCI fci;
36                 FCP fcp;
37                 bool opened;
38
39                 int _select(const ByteArray &command);
40
41         protected:
42                 ByteArray selectResponse;
43                 bool setSelectResponse(const ByteArray &response);
44
45         public:
46                 static const int SUCCESS = 0;
47                 static const int ERROR_ILLEGAL_STATE = -1;
48                 static const int ERROR_ILLEGAL_REFERENCE = -2;
49                 static const int ERROR_ILLEGAL_PARAMETER = -3;
50                 static const int ERROR_SECURITY = -4;
51                 static const int ERROR_OPERATION_NOT_SUPPORT = -5;
52                 static const int ERROR_IO = -6;
53                 static const int ERROR_UNKNOWN = -99;
54
55                 static const unsigned int MF_FID = 0x003F;
56
57                 FileObject(Channel *channel);
58                 FileObject(Channel *channel, const ByteArray &selectResponse);
59                 ~FileObject();
60
61                 void close();
62                 inline bool isClosed() const { return (opened == false); }
63                 int select(const ByteArray &aid);
64                 int select(const ByteArray &path, bool fromCurrentDF);
65                 int select(unsigned int fid);
66                 int selectParent();
67
68                 inline const ByteArray getSelectResponse() const { return selectResponse; }
69
70                 const FCI *getFCI() const;
71                 const FCP *getFCP() const;
72
73                 int readRecord(unsigned int sfi, unsigned int recordId, Record &result);
74                 int writeRecord(unsigned int sfi, const Record &record);
75
76                 int searchRecord(unsigned int sfi, const ByteArray &searchParam, vector<int> &result);
77
78                 int readBinary(unsigned int sfi, unsigned int offset, unsigned int length, ByteArray &result);
79                 int writeBinary(unsigned int sfi, const ByteArray &data, unsigned int offset, unsigned int length);
80         };
81
82 } /* namespace smartcard_service_api */
83 #endif /* FILEOBJECT_H_ */