root/trunk/Implementations/Ivy/IvyWrapper.h

Revision 5, 4.6 kB (checked in by jchaffraix, 3 years ago)

Correct typo in one header
Correct some more coding style issues

Line 
1 /*
2  * Copyright (C) 2007 EDF.  All rights reserved.
3  * Copyright (C) 2007 Julien Chaffraix <julien.chaffraix@gmail.com>. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1.  Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  * 2.  Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  * 3.  Neither the name of EDF nor the names of
15  *     its contributors may be used to endorse or promote products derived
16  *     from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY EDF AND ITS CONTRIBUTORS "AS IS" AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL EDF OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  */
30
31 #ifndef IvyWrapper_h
32 #define IvyWrapper_h
33
34 #include "config.h"
35
36 #include <map>
37
38 #include "IvyWrapMsgCb.h"
39 #include "IvyWrapAppCb.h"
40
41 namespace KJS {
42     class IvyRequest;
43 }
44
45 /**
46  * @brief Abstraction layer over Ivy
47  *
48  * This class handles all calls from the javascript interpreter and calls appropriate functions (mainly Ivy C++ ones).
49  * The method names are inspired from Ivy ones.
50  * @see Ivycpp.h for the library used
51  */
52 class IvyWrapper: public Shared<IvyWrapper> {
53
54 public:
55
56     /**
57      * Ivy status internal values
58      */
59     enum IvyStatus {
60         UNINITIALISED = 0,
61         INITIALISED,
62         READY,
63         RUNNING
64     };
65
66     IvyWrapper(Frame *);
67     ~IvyWrapper();
68
69     void IvyInit();
70     void IvyInit(KJS::UString, KJS::UString);
71
72     void IvyStart();
73     void IvyStart(KJS::UString);
74
75     void IvyRun(KJS::ExecState*);
76
77     void IvyStop();
78
79     void IvyMsgSend(KJS::ExecState*, KJS::UString message);
80
81     /**
82      * @brief Add message listeners
83      *
84      * The callback is handled by an IvyWrapMsgCallback for each pair (regExp, scripCb)
85      * @see class IvyWrapMsgCallback
86      * @param regExp : regular expression to match
87      * @param scriptCb : Javascrip method to callback
88      * @return Javascript boolean :
89      *  - true if the listener was added
90      *  - false otherwise
91      */
92     KJS::JSValue* IvyMsgBind(KJS::ExecState*, KJS::UString regExp, KJS::JSValue* scriptCb);
93     /**
94      * @brief Remove a message listener
95      * @param regExp : same as in IvyBindMsg
96      * @param scriptCb : same as in IvyBindMsg
97      * @return a Javascript boolean :
98      * - true if a listener was removed
99      * - false if it was not
100      */
101     KJS::JSValue* IvyMsgUnbind(KJS::ExecState*, KJS::UString regExp, KJS::JSValue* scriptCb);
102
103     /**
104      * @brief Sets the connection / disconnection listeners
105      * If callBack is null, then it removes the previous registered callback function
106      *
107      * The callback is handled by an IvyWrapAppCb instance
108      * @see class IvyWrapAppCb
109      * @param callBack : Javascript callback method
110      */
111     void IvySetConnectListener(KJS::ExecState*, KJS::JSValue* callBack);
112     void IvySetDisconnectListener(KJS::ExecState*, KJS::JSValue* callBack);
113
114     /**
115      * @brief Unbind all message listeners
116      */
117     void IvyMsgUnbindAll();
118
119     /**
120      * @brief Convert internal state to Javascript string
121      */
122     KJS::JSValue* IvyGetStatus();
123
124 protected:
125
126     /**
127      * @brief Ivy mainLoop start
128      *
129      * This method is just to have the necessary signature for pthread_create
130      */
131     static void* __mainStart(void* unused);
132
133     /*
134      * Internal comparision function for the map
135      */
136     struct compareKJS {
137         bool operator()(const KJS::UString& s1, const KJS::UString& s2) {
138             return (s1 < s2);
139         }
140     };
141
142     WebCore::Frame* m_frame;
143     KJS::IvyRequest* m_ivyReq;
144     Ivy* m_ivy;
145     RefPtr<IvyWrapAppCb> m_wrapAppCb;
146     pthread_t m_ivyThread;
147
148     IvyStatus m_status;
149
150     std::map <KJS::UString, RefPtr<IvyWrapMsgCb>, compareKJS>* m_msgListeners;
151 };
152
153 #endif // IvyWrapper_h
154
Note: See TracBrowser for help on using the browser.