tizen 2.3.1 release
[framework/web/wearable/wrt-plugins-tizen.git] / src / Filesystem / JSFilestream.h
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        JSFilestream.h
20  */
21
22 #ifndef TIZENAPIS_TIZEN_JSFILESTREAM_H_
23 #define TIZENAPIS_TIZEN_JSFILESTREAM_H_
24
25 #include <JavaScriptCore/JavaScript.h>
26 #include <CommonsJavaScript/PrivateObject.h>
27 #include "Stream.h"
28
29 namespace DeviceAPI {
30 namespace Filesystem {
31 class JSFilestream
32 {
33 public:
34     static const JSClassDefinition* getClassInfo();
35
36     static const JSClassRef getClassRef();
37
38     static StreamPtr getPrivateObject(JSContextRef context, JSValueRef value);
39     static void setPrivateObject(JSObjectRef object, StreamPtr data);
40     static JSObjectRef makeJSObject(JSContextRef context, StreamPtr ptr,
41             Common::SecurityAccessor* srcSecurityAccessor);
42
43 private:
44     /**
45     * The callback invoked when an object is first created.
46     */
47     static void initialize(JSContextRef context,
48         JSObjectRef object);
49
50     /**
51     * The callback invoked when an object is finalized.
52     */
53     static void finalize(JSObjectRef object);
54
55     /**
56     * The callback invoked when getting a property's value.
57     */
58     static JSValueRef getProperty(JSContextRef context,
59         JSObjectRef object,
60         JSStringRef propertyName,
61         JSValueRef* exception);
62
63     /**
64     * The callback invoked when setting a property's value.
65     */
66     static bool setProperty(JSContextRef context,
67         JSObjectRef object,
68         JSStringRef propertyName,
69         JSValueRef value,
70         JSValueRef* exception);
71
72     /**
73     * The callback invoked when collecting the names of an object's properties.
74     */
75     static void getPropertyNames(JSContextRef context,
76         JSObjectRef object,
77         JSPropertyNameAccumulatorRef propertyNames);
78
79     /**
80     * The callback invoked when an object is used as the target of an 'instanceof' expression.
81     */
82     static bool hasInstance(JSContextRef context,
83         JSObjectRef constructor,
84         JSValueRef possibleInstance,
85         JSValueRef* exception);
86
87     /**
88     * Closes this FileStream.
89     */
90     static JSValueRef close(JSContextRef context,
91         JSObjectRef object,
92         JSObjectRef thisObject,
93         size_t argumentCount,
94         const JSValueRef arguments[],
95         JSValueRef* exception);
96
97     /**
98     * Reads the specified number of characters from this FileStream.
99     */
100     static JSValueRef read(JSContextRef context,
101         JSObjectRef object,
102         JSObjectRef thisObject,
103         size_t argumentCount,
104         const JSValueRef arguments[],
105         JSValueRef* exception);
106
107     /**
108     * Reads the specified number of bytes from this FileStream.
109     */
110     static JSValueRef readBytes(JSContextRef context,
111         JSObjectRef object,
112         JSObjectRef thisObject,
113         size_t argumentCount,
114         const JSValueRef arguments[],
115         JSValueRef* exception);
116
117     /**
118     * Reads the specified number of bytes from this FileStream, encoding the result in base64.
119     */
120     static JSValueRef readBase64(JSContextRef context,
121         JSObjectRef object,
122         JSObjectRef thisObject,
123         size_t argumentCount,
124         const JSValueRef arguments[],
125         JSValueRef* exception);
126
127     /**
128     * Writes the specified DOMString to this FileStream.
129     */
130     static JSValueRef write(JSContextRef context,
131         JSObjectRef object,
132         JSObjectRef thisObject,
133         size_t argumentCount,
134         const JSValueRef arguments[],
135         JSValueRef* exception);
136
137     /**
138     * Writes the specified bytes to this FileStream.
139     */
140     static JSValueRef writeBytes(JSContextRef context,
141         JSObjectRef object,
142         JSObjectRef thisObject,
143         size_t argumentCount,
144         const JSValueRef arguments[],
145         JSValueRef* exception);
146
147     /**
148     * Converts the specified base64 DOMString to bytes and writes the result to this FileStream.
149     */
150     static JSValueRef writeBase64(JSContextRef context,
151         JSObjectRef object,
152         JSObjectRef thisObject,
153         size_t argumentCount,
154         const JSValueRef arguments[],
155         JSValueRef* exception);
156
157     /**
158     * This structure describes a statically declared function property.
159     */
160     static JSStaticFunction m_functions[];
161
162     /**
163     * This structure describes a statically declared value property.
164     */
165     static JSStaticValue m_properties[];
166
167     /**
168     * This structure contains properties and callbacks that define a type of object.
169     */
170     static JSClassDefinition m_classInfo;
171
172     static JSClassRef m_classRef;
173     Stream* getPrivateObject(JSObjectRef aObject);
174 };
175 }
176 }
177
178 #endif