4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Ja-young Gu <jygu@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
30 #include "user_request.h"
33 struct private_object_data {
34 struct tcore_sap_operations *ops;
37 static TReturn _dispatcher(CoreObject *o, UserRequest *ur)
39 enum tcore_request_command command;
40 struct private_object_data *po = NULL;
42 CORE_OBJECT_CHECK_RETURN(o, CORE_OBJECT_TYPE_SAP, TCORE_RETURN_EINVAL);
44 po = tcore_object_ref_object(o);
46 return TCORE_RETURN_ENOSYS;
48 command = tcore_user_request_get_command(ur);
50 case TREQ_SAP_REQ_CONNECT:
51 po = tcore_object_ref_object(o);
52 if (!po->ops->connect)
53 return TCORE_RETURN_ENOSYS;
55 return po->ops->connect(o, ur);
58 case TREQ_SAP_REQ_DISCONNECT:
59 if (!po->ops->disconnect)
60 return TCORE_RETURN_ENOSYS;
62 return po->ops->disconnect(o, ur);
65 case TREQ_SAP_REQ_STATUS:
66 if (!po->ops->req_status)
67 return TCORE_RETURN_ENOSYS;
69 return po->ops->req_status(o, ur);
72 case TREQ_SAP_REQ_ATR:
73 if (!po->ops->get_atr)
74 return TCORE_RETURN_ENOSYS;
76 return po->ops->get_atr(o, ur);
79 case TREQ_SAP_TRANSFER_APDU:
80 if (!po->ops->transfer_apdu)
81 return TCORE_RETURN_ENOSYS;
83 return po->ops->transfer_apdu(o, ur);
86 case TREQ_SAP_SET_PROTOCOL:
87 if (!po->ops->set_transport_protocol)
88 return TCORE_RETURN_ENOSYS;
90 return po->ops->set_transport_protocol(o, ur);
93 case TREQ_SAP_SET_POWER:
94 if (!po->ops->set_power)
95 return TCORE_RETURN_ENOSYS;
97 return po->ops->set_power(o, ur);
100 case TREQ_SAP_REQ_CARDREADERSTATUS:
101 if (!po->ops->get_cardreader_status)
102 return TCORE_RETURN_ENOSYS;
104 return po->ops->get_cardreader_status(o, ur);
110 return TCORE_RETURN_SUCCESS;
113 static void _clone_hook(CoreObject *src, CoreObject *dest)
115 struct private_object_data *src_po = NULL;
116 struct private_object_data *dest_po = NULL;
121 dest_po = calloc(1, sizeof(struct private_object_data));
123 tcore_object_link_object(dest, NULL);
127 src_po = tcore_object_ref_object(src);
128 dest_po->ops = src_po->ops;
130 tcore_object_link_object(dest, dest_po);
133 static void _free_hook(CoreObject *o)
135 struct private_object_data *po = NULL;
137 CORE_OBJECT_CHECK(o, CORE_OBJECT_TYPE_SAP);
139 po = tcore_object_ref_object(o);
142 tcore_object_link_object(o, NULL);
146 CoreObject *tcore_sap_new(TcorePlugin *p, const char *name,
147 struct tcore_sap_operations *ops, TcoreHal *hal)
149 CoreObject *o = NULL;
150 struct private_object_data *po = NULL;
155 o = tcore_object_new(p, name, hal);
159 po = calloc(1, sizeof(struct private_object_data));
161 tcore_object_free(o);
167 tcore_object_set_type(o, CORE_OBJECT_TYPE_SAP);
168 tcore_object_link_object(o, po);
169 tcore_object_set_free_hook(o, _free_hook);
170 tcore_object_set_clone_hook(o, _clone_hook);
171 tcore_object_set_dispatcher(o, _dispatcher);
176 void tcore_sap_free(CoreObject *o)
178 CORE_OBJECT_CHECK(o, CORE_OBJECT_TYPE_SAP);
179 tcore_object_free(o);
182 void tcore_sap_set_ops(CoreObject *o, struct tcore_sap_operations *ops)
184 struct private_object_data *po = NULL;
186 CORE_OBJECT_CHECK(o, CORE_OBJECT_TYPE_SAP);
188 po = (struct private_object_data *)tcore_object_ref_object(o);