Update change log and spec for wrt-plugins-tizen_0.4.10
[framework/web/wrt-plugins-tizen.git] / src / Common / ArgumentValidationChecker.h
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2013 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 #ifndef _WRTPLUGINS_TIZEN_ARGUMENTVALIDATIONCHECKER_
19 #define _WRTPLUGINS_TIZEN_ARGUMENTVALIDATIONCHECKER_
20
21 #include <string>
22 #include <JavaScriptCore/JavaScript.h>
23
24 namespace DeviceAPI {
25 namespace Common{
26
27 class ArgumentValidationException{
28 public:
29     std::string mTizenException;
30     std::string mMessage;
31     int mInvalidArgumentIndex;
32     ArgumentValidationException(const std::string tizenException ,const  std::string message):mTizenException(tizenException),mMessage(message),mInvalidArgumentIndex(-1){}
33     ArgumentValidationException(const std::string tizenException ,const  std::string message, int index):mTizenException(tizenException),mMessage(message),mInvalidArgumentIndex(index){}
34 };
35
36
37
38 class ArgumentValidationChecker{
39     public : 
40         typedef bool (* SelfChecker)(JSValueRef value);
41
42         /**
43          * @brief Argument Validation options
44          * MANDATORY - Must existed
45          * OPTIONAL - Can be omitted
46          * NULLABLE - Can be use NULL value
47          * END - Variable argument terminator symbol
48          */
49         enum Option { MANDATORY = 0x01 , OPTIONAL = 0x02, NULLABLE = 0x04, END = 0x00 };
50         
51         enum Type { Float, Long, String, Function, Boolean, Object, Array, UserDefine, SelfCheck };
52
53        /**
54         * @brief check argment validation
55         *
56         * @remarks 
57         * Option phase instruction
58         *
59         * OPTIONS => OPTION, OPTIONS | OPTION,"END"
60         * OPTION => FIRST, SECOND
61         * FIRST => "MANDATORY"  | "OPTIONAL" NULLABLE
62         * NULLABLE => "|NULLABLE" | ""
63         * SECOND => "Float" | "Long" | "String" | "Function" | "Boolean" | "Object" | "Array" | "UserDefine", CLASSREF | "SelfCheck", CHECKFUN
64         * CLASSREF => ,JSClassRef
65         * CHECKFUN => ,SelfChecker
66         *
67         * @param[in] ctx        Context
68         * @param[in] oirginArgumentCount  Number of passed arguments count
69         * @param[in] originArguments   Passed arguments
70         * @param[in] convertedArgumentCount   Number of argument count in spec
71         * @param[out] convertedArguments   Converted arguments in proper types
72         * @param[in] option Argument options
73         *
74         */
75         static void check(JSContextRef ctx, int oirginArgumentCount , const JSValueRef originArguments[], int convertedArgumentCount , JSValueRef convertedArguments[], Option option,  ...);
76 };
77
78 }
79 }
80
81 #endif //_WRTPLUGINS_TIZEN_ARGUMENTVALIDATIONCHECKER_
82