93cc6ade146f12fce6cbad42a678ff5a787f2c81
[platform/upstream/iotjs.git] / src / module / iotjs_module_blehcisocket.h
1 /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 /* Copyright (C) 2015 Sandeep Mistry sandeep.mistry@gmail.com
17  *
18  * Permission is hereby granted, free of charge, to any person obtaining a copy
19  * of this software and associated documentation files (the "Software"), to deal
20  * in the Software without restriction, including without limitation the rights
21  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
22  * copies of the Software, and to permit persons to whom the Software is
23  * furnished to do so, subject to the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be included in
26  * all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
33  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34  * SOFTWARE.
35  */
36
37 #ifndef IOTJS_MODULE_BLE_HCI_SOCKET_H
38 #define IOTJS_MODULE_BLE_HCI_SOCKET_H
39
40 #include "iotjs_def.h"
41 #include "iotjs_objectwrap.h"
42 #include "iotjs_reqwrap.h"
43
44 typedef struct {
45   iotjs_jobjectwrap_t jobjectwrap;
46
47   int _mode;
48   int _socket;
49   int _devId;
50   uv_poll_t _pollHandle;
51   int _l2sockets[1024];
52   int _l2socketCount;
53   uint8_t _address[6];
54   uint8_t _addressType;
55 } IOTJS_VALIDATED_STRUCT(iotjs_blehcisocket_t);
56
57
58 #define THIS iotjs_blehcisocket_t* iotjs_blehcisocket
59
60
61 iotjs_blehcisocket_t* iotjs_blehcisocket_create(const iotjs_jval_t* jble);
62 iotjs_blehcisocket_t* iotjs_blehcisocket_instance_from_jval(
63     const iotjs_jval_t* jble);
64
65
66 void iotjs_blehcisocket_initialize(THIS);
67 void iotjs_blehcisocket_close(THIS);
68 void iotjs_blehcisocket_start(THIS);
69 int iotjs_blehcisocket_bindRaw(THIS, int* devId);
70 int iotjs_blehcisocket_bindUser(THIS, int* devId);
71 void iotjs_blehcisocket_bindControl(THIS);
72 bool iotjs_blehcisocket_isDevUp(THIS);
73 void iotjs_blehcisocket_setFilter(THIS, char* data, int length);
74 void iotjs_blehcisocket_poll(THIS);
75 void iotjs_blehcisocket_stop(THIS);
76 void iotjs_blehcisocket_write(THIS, char* data, int length);
77 void iotjs_blehcisocket_emitErrnoError(THIS);
78 int iotjs_blehcisocket_devIdFor(THIS, int* pDevId, bool isUp);
79 void iotjs_blehcisocket_kernelDisconnectWorkArounds(THIS, int length,
80                                                     char* data);
81
82 #undef THIS
83
84 void iotjs_blehcisocket_poll_cb(uv_poll_t* handle, int status, int events);
85
86
87 #endif /* IOTJS_MODULE_BLE_HCI_SOCKET_H */