1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * deployment.h: Deployment
5 * Copyright 2008 Novell, Inc. (http://www.novell.com)
7 * See the LICENSE file included with the distribution for details.
10 #ifndef __DEPLOYMENT_H__
11 #define __DEPLOYMENT_H__
16 #include "dependencyobject.h"
17 #include "fontmanager.h"
18 #include "application.h"
19 #include "collection.h"
20 #include "downloader.h"
24 #if !INCLUDED_MONO_HEADERS
25 typedef struct _MonoAssembly MonoAssembly
;
26 typedef struct _MonoClass MonoClass
;
27 typedef struct _MonoDomain MonoDomain
;
28 typedef struct _MonoImage MonoImage
;
29 typedef struct _MonoMethod MonoMethod
;
30 typedef struct _MonoObject MonoObject
;
31 typedef struct _MonoProperty MonoProperty
;
34 /* @Namespace=System.Windows */
35 class AssemblyPart
: public DependencyObject
{
37 /* @PropertyType=string,DefaultValue=\"\" */
38 const static int SourceProperty
;
40 /* @GenerateCBinding,GeneratePInvoke */
44 virtual ~AssemblyPart ();
47 /* @Namespace=System.Windows */
48 class AssemblyPartCollection
: public DependencyObjectCollection
{
50 /* @GenerateCBinding,GeneratePInvoke */
51 AssemblyPartCollection ();
53 virtual Type::Kind
GetElementType () { return Type::ASSEMBLYPART
; }
56 virtual ~AssemblyPartCollection ();
59 /* @Namespace=System.Windows */
60 class ExternalPart
: public DependencyObject
{
62 /* @GenerateCBinding,GeneratePInvoke */
66 virtual ~ExternalPart ();
69 /* @Namespace=System.Windows */
70 class ExtensionPart
: public ExternalPart
{
72 /* @PropertyType=Uri,AlwaysChange,GenerateAccessors,DefaultValue=Uri() */
73 const static int SourceProperty
;
75 void SetSource (Uri
*value
);
78 /* @GenerateCBinding,GeneratePInvoke */
82 virtual ~ExtensionPart ();
85 /* @Namespace=System.Windows */
86 class ExternalPartCollection
: public DependencyObjectCollection
{
88 /* @GenerateCBinding,GeneratePInvoke */
89 ExternalPartCollection ();
91 virtual Type::Kind
GetElementType () { return Type::EXTERNALPART
; }
94 virtual ~ExternalPartCollection ();
97 /* @Namespace=System.Windows */
98 class WindowSettings
: public DependencyObject
{
100 /* @GenerateCBinding,GeneratePInvoke */
103 /* @PropertyType=string,DefaultValue=\"\",Validator=NonNullValidator,GenerateAccessors,ManagedSetterAccess=Private */
104 const static int TitleProperty
;
105 /* @PropertyType=double,DefaultValue=\"\",GenerateAccessors,ManagedSetterAccess=Private */
106 const static int HeightProperty
;
107 /* @PropertyType=double,DefaultValue=\"\",GenerateAccessors,ManagedSetterAccess=Private */
108 const static int WidthProperty
;
110 const char *GetTitle ();
111 void SetTitle (const char *title
);
114 void SetWidth (double width
);
117 void SetHeight (double height
);
120 virtual ~WindowSettings ();
123 /* @Namespace=System.Windows */
124 class Icon
: public DependencyObject
{
126 /* @GenerateCBinding,GeneratePInvoke */
129 /* @PropertyType=Uri,GenerateAccessors */
130 const static int SourceProperty
;
131 /* @PropertyType=Size,GenerateAccessors */
132 const static int SizeProperty
;
135 void SetSource (Uri
*source
);
138 void SetSize (Size
*size
);
144 /* @Namespace=System.Windows */
145 class IconCollection
: public Collection
{
147 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal */
150 virtual Type::Kind
GetElementType () { return Type::ICON
; }
153 virtual ~IconCollection ();
156 /* @Namespace=System.Windows */
157 class OutOfBrowserSettings
: public DependencyObject
{
159 /* @GenerateCBinding,GeneratePInvoke */
160 OutOfBrowserSettings ();
162 /* @PropertyType=string,DefaultValue=\"\",Validator=NonNullValidator,GenerateAccessors */
163 const static int BlurbProperty
;
164 /* @PropertyType=string,DefaultValue=\"\",Validator=NonNullValidator,GenerateAccessors */
165 const static int ShortNameProperty
;
166 /* @PropertyType=bool,DefaultValue=true,GenerateAccessors */
167 const static int EnableGPUAccelerationProperty
;
168 /* @PropertyType=bool,DefaultValue=true,GenerateAccessors */
169 const static int ShowInstallMenuItemProperty
;
170 /* @PropertyType=WindowSettings,ManagedSetterAccess=Internal,GenerateAccessors */
171 const static int WindowSettingsProperty
;
172 /* @PropertyType=IconCollection,ManagedSetterAccess=Internal,GenerateAccessors */
173 const static int IconsProperty
;
175 const char *GetBlurb ();
176 void SetBlurb (const char *blurb
);
178 const char *GetShortName ();
179 void SetShortName (const char *shortName
);
181 bool GetEnableGPUAcceleration ();
182 void SetEnableGPUAcceleration (bool enable
);
184 bool GetShowInstallMenuItem ();
185 void SetShowInstallMenuItem (bool show
);
187 WindowSettings
* GetWindowSettings ();
188 void SetWindowSettings (WindowSettings
* settings
);
190 IconCollection
* GetIcons ();
191 void SetIcons (IconCollection
* icons
);
194 virtual ~OutOfBrowserSettings ();
197 /* @Namespace=System.Windows */
198 class Deployment
: public DependencyObject
{
200 /* @PropertyType=CrossDomainAccess,DefaultValue=CrossDomainAccessNoAccess,ManagedSetterAccess=Internal,GenerateAccessors,Validator=CrossDomainValidator */
201 const static int ExternalCallersFromCrossDomainProperty
;
202 /* @PropertyType=string,ManagedSetterAccess=Internal */
203 const static int EntryPointAssemblyProperty
;
204 /* @PropertyType=string,ManagedSetterAccess=Internal */
205 const static int EntryPointTypeProperty
;
206 /* @PropertyType=ExternalPartCollection,AutoCreateValue,ManagedSetterAccess=Internal,GenerateAccessors */
207 const static int ExternalPartsProperty
;
208 /* @PropertyType=OutOfBrowserSettings,ManagedSetterAccess=Internal,GenerateAccessors */
209 const static int OutOfBrowserSettingsProperty
;
210 /* @PropertyType=AssemblyPartCollection,ManagedSetterAccess=Internal,GenerateAccessors */
211 const static int PartsProperty
;
212 /* @PropertyType=string,ManagedSetterAccess=Internal,GenerateAccessors */
213 const static int RuntimeVersionProperty
;
215 /* @GenerateCBinding,GeneratePInvoke */
218 bool InitializeManagedDeployment (gpointer plugin_instance
, const char *file
, const char *culture
, const char *uiculture
);
219 bool InitializeAppDomain ();
221 virtual void Dispose ();
223 /* @GenerateCBinding,GeneratePInvoke */
224 Types
* GetTypes () { return types
; }
226 Surface
*GetSurface ();
227 /* @GenerateCBinding,GeneratePInvoke */
228 Surface
*GetSurfaceReffed (); /* thread-safe */
229 void SetSurface (Surface
*surface
);
231 AssemblyPartCollection
*GetParts ();
232 void SetParts (AssemblyPartCollection
*col
);
234 ExternalPartCollection
*GetExternalParts ();
235 void SetExternalParts (ExternalPartCollection
*col
);
237 OutOfBrowserSettings
*GetOutOfBrowserSettings ();
238 void SetOutOfBrowserSettings (OutOfBrowserSettings
*oob
);
240 void SetRuntimeVersion (const char *version
);
241 const char *GetRuntimeVersion ();
243 void Reinitialize ();
245 Application
* GetCurrentApplication ();
246 /* @GenerateCBinding,GeneratePInvoke */
247 void SetCurrentApplication (Application
* value
);
249 void RegisterDownloader (IDownloader
*dl
);
250 void UnregisterDownloader (IDownloader
*dl
);
252 * thread-safe, returns false if the media couldn't be registered (if the
253 * deployment is already shutting down, in which case the media should
254 * dispose itself immediately)
256 bool RegisterMedia (EventObject
*media
);
258 void UnregisterMedia (EventObject
*media
);
260 /* @GenerateCBinding,GeneratePInvoke */
261 static Deployment
* GetCurrent ();
262 /* @GenerateCBinding,GeneratePInvoke */
263 static void SetCurrent (Deployment
* value
);
264 static void SetCurrent (Deployment
* value
, bool domain
);
266 static bool Initialize (const char *platform_dir
, bool create_root_domain
);
268 static void RegisterThread (Deployment
*deployment
);
270 void UnrefDelayed (EventObject
*obj
);
272 void TrackObjectCreated (EventObject
*obj
);
273 void TrackObjectDestroyed (EventObject
*obj
);
275 bool IsLoadedFromXap ();
276 /* @GenerateCBinding,GeneratePInvoke */
277 void SetIsLoadedFromXap (bool flag
);
279 void SetXapLocation (const char *location
);
280 const char *GetXapLocation ();
282 FontManager
*GetFontManager ();
284 CrossDomainAccess
GetExternalCallersFromCrossDomain ();
285 void SetExternalCallersFromCrossDomain (CrossDomainAccess value
);
287 ErrorEventArgs
* ManagedExceptionToErrorEventArgs (MonoObject
*exc
);
288 gpointer
CreateManagedXamlLoader (gpointer plugin_instance
, XamlLoader
* native_loader
, const char *resourceBase
, const char *file
, const char *str
);
289 void DestroyManagedXamlLoader (gpointer xaml_loader
);
290 void DestroyManagedApplication (gpointer plugin_instance
);
294 void AddAllLoadedHandlers (UIElement
*el
, bool only_unemitted
);
295 void RemoveAllLoadedHandlers (UIElement
*el
);
296 void AddLoadedHandler (UIElement
*el
, int token
);
297 void RemoveLoadedHandler (UIElement
*el
, int token
);
299 static void emit_delayed_loaded (EventObject
*data
);
301 static void add_loaded_handler (EventObject
*obj
, EventHandler handler
, gpointer handler_data
, gpointer closure
);
302 static void remove_loaded_handler (EventObject
*obj
, EventHandler handler
, gpointer handler_data
, gpointer closure
);
303 static void delete_loaded_closure (gpointer closure
);
304 static bool match_loaded_closure (EventHandler cb_handler
, gpointer cb_data
, gpointer data
);
305 static void proxy_loaded_event (EventObject
*sender
, EventArgs
*arg
, gpointer closure
);
307 /* @GenerateManagedEvent=false */
308 const static int LayoutUpdatedEvent
;
310 /* @GenerateManagedEvent=false */
311 const static int LoadedEvent
;
313 /* @GenerateManagedEvent=false */
314 const static int ShuttingDownEvent
;
315 /* @GenerateManagedEvent=false */
316 const static int AppDomainUnloadedEvent
; /* this is emitted just after the appdomain has successfully unloaded */
318 void LayoutUpdated ();
320 void Shutdown (); /* main thread only */
321 bool IsShuttingDown (); /* main thread only */
323 void TrackPath (char *path
);
324 void UntrackPath (char *path
);
326 static gint32
GetDeploymentCount (); /* returns the number of deployments currently alive */
328 virtual ~Deployment ();
334 CallManagedShutdown
= 1,
336 DisposeDeployment
= 3
338 Deployment (MonoDomain
*domain
);
339 void InnerConstructor ();
341 void AbortAllDownloaders ();
342 void DisposeAllMedias ();
344 static gboolean
DrainUnrefs (gpointer ptr
);
349 FontManager
*font_manager
;
350 Application
*current_app
;
355 // true if we're going to notify Loaded events on the next
360 /* accessed from several threads, needs the medias_mutex locked on all accesses */
363 bool is_shutting_down
;
364 bool appdomain_unloaded
;
365 bool is_loaded_from_xap
;
366 // xap location, to help forging the right uris for downloaders
369 #if GLIB_CHECK_VERSION(2,10,0)
370 volatile gpointer pending_unrefs
;
372 gpointer pending_unrefs
;
375 gint objects_created
;
376 gint objects_destroyed
;
379 GHashTable
*objects_alive
;
380 pthread_mutex_t objects_alive_mutex
;
384 ShutdownState shutdown_state
;
385 MonoImage
*system_windows_image
;
386 MonoAssembly
*system_windows_assembly
;
387 MonoClass
*system_windows_deployment
;
388 MonoMethod
*deployment_shutdown
;
391 MonoMethod
*moon_load_xaml
;
392 MonoMethod
*moon_initialize_deployment_xap
;
393 MonoMethod
*moon_initialize_deployment_xaml
;
394 MonoMethod
*moon_destroy_application
;
396 MonoClass
*moon_exception
;
397 MonoProperty
*moon_exception_message
;
398 MonoProperty
*moon_exception_error_code
;
400 MonoMethod
*MonoGetMethodFromName (MonoClass
*klass
, const char *name
, int narg
);
401 MonoProperty
*MonoGetPropertyFromName (MonoClass
*klass
, const char *name
);
404 static gboolean
ShutdownManagedCallback (gpointer user_data
);
405 gboolean
ShutdownManaged ();
407 static Deployment
*desktop_deployment
;
408 static GHashTable
*current_hash
;
409 static gboolean initialized
;
410 static pthread_key_t tls_key
;
411 static pthread_mutex_t hash_mutex
;
412 static MonoDomain
*root_domain
;
413 static gint32 deployment_count
;
418 * for all calls into javascript we need to push/pop the current deployment.
419 * this class is (ab)uses C++ for this, just put a "DeploymentStack deployment_push_pop;"
420 * in every method which needs to push/pop the current deployment. the compiler will
421 * call the ctor in the beginning of the method, and the dtor in the end.
423 class DeploymentStack
{
427 deployment
= Deployment::GetCurrent ();
432 Deployment::SetCurrent (deployment
);
436 Deployment
*deployment
;
439 #endif /* __DEPLOYMENT_H__ */