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