source: trunk/icedtea-web/plugin/icedteanp/IcedTeaPluginRequestProcessor.h

Last change on this file was 431, checked in by dmik, 11 years ago

icedtea-web: Adapt 1.5.1 changes to OS/2.

File size: 4.8 KB
Line 
1/* IcedTeaPluginRequestProcessor.h
2
3 Copyright (C) 2009, 2010 Red Hat
4
5This file is part of IcedTea.
6
7IcedTea is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12IcedTea is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with IcedTea; see the file COPYING. If not, write to the
19Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
2002110-1301 USA.
21
22Linking this library statically or dynamically with other modules is
23making a combined work based on this library. Thus, the terms and
24conditions of the GNU General Public License cover the whole
25combination.
26
27As a special exception, the copyright holders of this library give you
28permission to link this library with independent modules to produce an
29executable, regardless of the license terms of these independent
30modules, and to copy and distribute the resulting executable under
31terms of your choice, provided that you also meet, for each linked
32independent module, the terms and conditions of the license of that
33module. An independent module is a module which is not derived from
34or based on this library. If you modify this library, you may extend
35this exception to your version of the library, but you are not
36obligated to do so. If you do not wish to do so, delete this
37exception statement from your version. */
38
39#ifndef __ICEDTEAPLUGINREQUESTPROCESSOR_H__
40#define __ICEDTEAPLUGINREQUESTPROCESSOR_H__
41
42#include <map>
43#include <stdio.h>
44#include <stdlib.h>
45#include <pthread.h>
46#include <time.h>
47
48#include <npapi.h>
49#include <npruntime.h>
50
51#include "IcedTeaPluginUtils.h"
52#include "IcedTeaJavaRequestProcessor.h"
53
54/* Internal request reference counter */
55static long internal_req_ref_counter;
56
57/* Given a value and type, performs the appropriate Java->JS type
58 * mapping and puts it in the given variant */
59
60static void convertToNPVariant(std::string value, std::string type, NPVariant* result_variant);
61
62// Internal methods that need to run in main thread
63void _getMember(void* data);
64void _setMember(void* data);
65void _call(void* data);
66void _eval(void* data);
67void _getString(void* data);
68void _loadURL(void* data);
69
70void* queue_processor(void* data);
71
72#ifdef __OS2__
73struct QueueProcessorData;
74#endif
75
76/**
77 * Processes requests made TO the plugin (by java or anyone else)
78 */
79class PluginRequestProcessor : public BusSubscriber
80{
81 private:
82
83 /* Mutex to ensure that the request queue is accessed synchronously */
84 pthread_mutex_t message_queue_mutex;
85
86 /* Condition on which the queue processor waits */
87 pthread_cond_t cond_message_available;
88
89 /* Queue for holding messages that get processed in a separate thread */
90 std::vector< std::vector<std::string*>* >* message_queue;
91
92 /* Mutex to ensure synchronized writes */
93 pthread_mutex_t syn_write_mutex;
94
95 /* Dispatch request processing to a new thread for asynch. processing */
96 void dispatch(void* func_ptr (void*), std::vector<std::string>* message, std::string* src);
97
98 /* Send main window pointer to Java */
99 void sendWindow(std::vector<std::string*>* message_parts);
100
101 /* Stores the variant on java side */
102 void storeVariantInJava(NPVariant variant, std::string* result);
103
104 /* Send member ID to Java */
105 void sendMember(std::vector<std::string*>* message_parts);
106
107 /* Set member to given value */
108 void setMember(std::vector<std::string*>* message_parts);
109
110 /* Send string value of requested object */
111 void sendString(std::vector<std::string*>* message_parts);
112
113 /* Evaluate the given script */
114 void eval(std::vector<std::string*>* message_parts);
115
116 /* Evaluate the given script */
117 void call(std::vector<std::string*>* message_parts);
118
119 /* Decrements reference count for given object */
120 void finalize(std::vector<std::string*>* message_parts);
121
122 /* Loads a URL into the specified target */
123 void loadURL(std::vector<std::string*>* message_parts);
124
125 public:
126 PluginRequestProcessor(); /* Constructor */
127 ~PluginRequestProcessor(); /* Destructor */
128
129 /* Process new requests (if applicable) */
130 virtual bool newMessageOnBus(const char* message);
131
132 /* Thread run method for processing queued messages */
133#ifdef __OS2__
134 void queueProcessorThread(QueueProcessorData *queue_processor_data);
135 void cancelWait() { pthread_cond_broadcast(&cond_message_available); }
136#else
137 void queueProcessorThread();
138#endif
139};
140
141#endif // __ICEDTEAPLUGINREQUESTPROCESSOR_H__
Note: See TracBrowser for help on using the repository browser.