2009-11-13 Jeffrey Stedfast <fejj@novell.com>
[moon.git] / src / deployment.h
blob5f00a4b7ba6cabdd6e6b8bb54e0d4cb3d90ba575
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * deployment.h: Deployment
5 * Copyright 2008 Novell, Inc. (http://www.novell.com)
7 * See the LICENSE file included with the distribution for details.
8 */
10 #ifndef __DEPLOYMENT_H__
11 #define __DEPLOYMENT_H__
13 #include <glib.h>
15 #include "enums.h"
16 #include "dependencyobject.h"
17 #include "fontmanager.h"
18 #include "application.h"
19 #include "collection.h"
20 #include "downloader.h"
21 #include "mutex.h"
22 #include "value.h"
24 #include <mono/metadata/appdomain.h>
25 #include <mono/metadata/assembly.h>
27 /* @Namespace=System.Windows */
28 class AssemblyPart : public DependencyObject {
29 public:
30 /* @PropertyType=string,DefaultValue=\"\" */
31 const static int SourceProperty;
33 /* @GenerateCBinding,GeneratePInvoke */
34 AssemblyPart ();
36 protected:
37 virtual ~AssemblyPart ();
40 /* @Namespace=System.Windows */
41 class AssemblyPartCollection : public DependencyObjectCollection {
42 public:
43 /* @GenerateCBinding,GeneratePInvoke */
44 AssemblyPartCollection ();
46 virtual Type::Kind GetElementType () { return Type::ASSEMBLYPART; }
48 protected:
49 virtual ~AssemblyPartCollection ();
52 /* @Namespace=System.Windows */
53 class ExternalPart : public DependencyObject {
54 public:
55 /* @GenerateCBinding,GeneratePInvoke */
56 ExternalPart ();
58 protected:
59 virtual ~ExternalPart ();
62 /* @Namespace=System.Windows */
63 class ExtensionPart : public ExternalPart {
64 public:
65 /* @PropertyType=Uri,AlwaysChange,GenerateAccessors,DefaultValue=Uri() */
66 const static int SourceProperty;
68 void SetSource (Uri *value);
69 Uri* GetSource ();
71 /* @GenerateCBinding,GeneratePInvoke */
72 ExtensionPart ();
74 protected:
75 virtual ~ExtensionPart ();
78 /* @Namespace=System.Windows */
79 class ExternalPartCollection : public DependencyObjectCollection {
80 public:
81 /* @GenerateCBinding,GeneratePInvoke */
82 ExternalPartCollection ();
84 virtual Type::Kind GetElementType () { return Type::EXTERNALPART; }
86 protected:
87 virtual ~ExternalPartCollection ();
90 /* @Namespace=System.Windows */
91 class WindowSettings : public DependencyObject {
92 public:
93 /* @GenerateCBinding,GeneratePInvoke */
94 WindowSettings ();
96 /* @PropertyType=string,DefaultValue=\"\",Validator=NonNullValidator,GenerateAccessors */
97 const static int TitleProperty;
98 /* @PropertyType=string,DefaultValue=\"\",GenerateAccessors */
99 const static int HeightProperty;
100 /* @PropertyType=string,DefaultValue=\"\",GenerateAccessors */
101 const static int WidthProperty;
103 const char *GetTitle ();
104 void SetTitle (const char *title);
106 const char *GetWidth ();
107 void SetWidth (const char *width);
109 const char *GetHeight ();
110 void SetHeight (const char *height);
112 protected:
113 virtual ~WindowSettings ();
116 /* @Namespace=System.Windows */
117 class Icon : public DependencyObject {
118 public:
119 /* @GenerateCBinding,GeneratePInvoke */
120 Icon ();
122 /* @PropertyType=Uri,GenerateAccessors */
123 const static int SourceProperty;
124 /* @PropertyType=Size,GenerateAccessors */
125 const static int SizeProperty;
127 Uri* GetSource ();
128 void SetSource (Uri *source);
130 Size* GetSize ();
131 void SetSize (Size *size);
133 protected:
134 virtual ~Icon ();
137 /* @Namespace=System.Windows */
138 class IconCollection : public Collection {
139 public:
140 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal */
141 IconCollection ();
143 virtual Type::Kind GetElementType () { return Type::ICON; }
145 protected:
146 virtual ~IconCollection ();
149 /* @Namespace=System.Windows */
150 class OutOfBrowserSettings : public DependencyObject {
151 public:
152 /* @GenerateCBinding,GeneratePInvoke */
153 OutOfBrowserSettings ();
155 /* @PropertyType=string,DefaultValue=\"\",Validator=NonNullValidator,GenerateAccessors */
156 const static int BlurbProperty;
157 /* @PropertyType=string,DefaultValue=\"\",Validator=NonNullValidator,GenerateAccessors */
158 const static int ShortNameProperty;
159 /* @PropertyType=bool,DefaultValue=true,GenerateAccessors */
160 const static int EnableGPUAccelerationProperty;
161 /* @PropertyType=bool,DefaultValue=true,GenerateAccessors */
162 const static int ShowInstallMenuItemProperty;
163 /* @PropertyType=WindowSettings,ManagedSetterAccess=Internal,GenerateAccessors */
164 const static int WindowSettingsProperty;
165 /* @PropertyType=IconCollection,ManagedSetterAccess=Internal,GenerateAccessors */
166 const static int IconsProperty;
168 const char *GetBlurb ();
169 void SetBlurb (const char *blurb);
171 const char *GetShortName ();
172 void SetShortName (const char *shortName);
174 bool GetEnableGPUAcceleration ();
175 void SetEnableGPUAcceleration (bool enable);
177 bool GetShowInstallMenuItem ();
178 void SetShowInstallMenuItem (bool show);
180 WindowSettings* GetWindowSettings ();
181 void SetWindowSettings (WindowSettings* settings);
183 IconCollection* GetIcons ();
184 void SetIcons (IconCollection* icons);
186 protected:
187 virtual ~OutOfBrowserSettings ();
190 /* @Namespace=System.Windows */
191 class Deployment : public DependencyObject {
192 public:
193 /* @PropertyType=CrossDomainAccess,DefaultValue=CrossDomainAccessNoAccess,ManagedSetterAccess=Internal,GenerateAccessors,Validator=CrossDomainValidator */
194 const static int ExternalCallersFromCrossDomainProperty;
195 /* @PropertyType=string,ManagedSetterAccess=Internal */
196 const static int EntryPointAssemblyProperty;
197 /* @PropertyType=string,ManagedSetterAccess=Internal */
198 const static int EntryPointTypeProperty;
199 /* @PropertyType=ExternalPartCollection,AutoCreateValue,ManagedSetterAccess=Internal,GenerateAccessors */
200 const static int ExternalPartsProperty;
201 /* @PropertyType=OutOfBrowserSettings,ManagedSetterAccess=Internal,GenerateAccessors */
202 const static int OutOfBrowserSettingsProperty;
203 /* @PropertyType=AssemblyPartCollection,ManagedSetterAccess=Internal,GenerateAccessors */
204 const static int PartsProperty;
205 /* @PropertyType=string,ManagedSetterAccess=Internal,GenerateAccessors */
206 const static int RuntimeVersionProperty;
207 /* @PropertyType=Surface,ManagedAccess=Internal,GenerateAccessors */
208 const static int SurfaceProperty;
210 /* @GenerateCBinding,GeneratePInvoke */
211 Deployment ();
213 bool InitializeManagedDeployment (gpointer plugin_instance, const char *file, const char *culture, const char *uiculture);
214 bool InitializeAppDomain ();
216 virtual void Dispose ();
218 /* @GenerateCBinding,GeneratePInvoke */
219 Types* GetTypes () { return types; }
221 Surface *GetSurface ();
222 void SetSurface (Surface *surface);
224 AssemblyPartCollection *GetParts ();
225 void SetParts (AssemblyPartCollection *col);
227 ExternalPartCollection *GetExternalParts ();
228 void SetExternalParts (ExternalPartCollection *col);
230 OutOfBrowserSettings *GetOutOfBrowserSettings ();
231 void SetOutOfBrowserSettings (OutOfBrowserSettings *oob);
233 void SetRuntimeVersion (const char *version);
234 const char *GetRuntimeVersion ();
236 void Reinitialize ();
238 Application* GetCurrentApplication ();
239 /* @GenerateCBinding,GeneratePInvoke */
240 void SetCurrentApplication (Application* value);
242 void RegisterDownloader (IDownloader *dl);
243 void UnregisterDownloader (IDownloader *dl);
245 * thread-safe, returns false if the media couldn't be registered (if the
246 * deployment is already shutting down, in which case the media should
247 * dispose itself immediately)
249 bool RegisterMedia (EventObject *media);
250 /* thread-safe */
251 void UnregisterMedia (EventObject *media);
253 /* @GenerateCBinding,GeneratePInvoke */
254 static Deployment* GetCurrent ();
255 /* @GenerateCBinding,GeneratePInvoke */
256 static void SetCurrent (Deployment* value);
257 static void SetCurrent (Deployment* value, bool domain);
259 static bool Initialize (const char *platform_dir, bool create_root_domain);
261 static void RegisterThread (Deployment *deployment);
263 void UnrefDelayed (EventObject *obj);
265 void TrackObjectCreated (EventObject *obj);
266 void TrackObjectDestroyed (EventObject *obj);
268 bool IsLoadedFromXap ();
269 /* @GenerateCBinding,GeneratePInvoke */
270 void SetIsLoadedFromXap (bool flag);
272 void SetXapLocation (const char *location);
273 const char *GetXapLocation ();
275 FontManager *GetFontManager ();
277 CrossDomainAccess GetExternalCallersFromCrossDomain ();
278 void SetExternalCallersFromCrossDomain (CrossDomainAccess value);
280 ErrorEventArgs* ManagedExceptionToErrorEventArgs (MonoObject *exc);
281 gpointer CreateManagedXamlLoader (gpointer plugin_instance, XamlLoader* native_loader, const char *resourceBase, const char *file, const char *str);
282 void DestroyManagedXamlLoader (gpointer xaml_loader);
283 void DestroyManagedApplication (gpointer plugin_instance);
285 void PostLoaded ();
286 void EmitLoaded ();
287 void AddAllLoadedHandlers (UIElement *el, bool only_unemitted);
288 void RemoveAllLoadedHandlers (UIElement *el);
289 void AddLoadedHandler (UIElement *el, int token);
290 void RemoveLoadedHandler (UIElement *el, int token);
292 static void emit_delayed_loaded (EventObject *data);
294 static void add_loaded_handler (EventObject *obj, EventHandler handler, gpointer handler_data, gpointer closure);
295 static void remove_loaded_handler (EventObject *obj, EventHandler handler, gpointer handler_data, gpointer closure);
296 static void delete_loaded_closure (gpointer closure);
297 static bool match_loaded_closure (EventHandler cb_handler, gpointer cb_data, gpointer data);
298 static void proxy_loaded_event (EventObject *sender, EventArgs *arg, gpointer closure);
300 /* @GenerateManagedEvent=false */
301 const static int LayoutUpdatedEvent;
303 /* @GenerateManagedEvent=false */
304 const static int LoadedEvent;
306 /* @GenerateManagedEvent=false */
307 const static int ShuttingDownEvent;
308 /* @GenerateManagedEvent=false */
309 const static int AppDomainUnloadedEvent; /* this is emitted just after the appdomain has successfully unloaded */
311 void LayoutUpdated ();
313 void Shutdown (); /* main thread only */
314 bool IsShuttingDown (); /* main thread only */
316 void TrackPath (char *path);
317 void UntrackPath (char *path);
319 static gint32 GetDeploymentCount (); /* returns the number of deployments currently alive */
320 protected:
321 virtual ~Deployment ();
323 private:
324 enum ShutdownState {
325 ShutdownFailed = -1,
326 Running = 0,
327 CallManagedShutdown = 1,
328 UnloadDomain = 2,
329 DisposeDeployment = 3
331 Deployment (MonoDomain *domain);
332 void InnerConstructor ();
334 void AbortAllDownloaders ();
335 void DisposeAllMedias ();
336 void DrainUnrefs ();
337 static gboolean DrainUnrefs (gpointer ptr);
339 Types* types;
340 FontManager *font_manager;
341 Application *current_app;
342 MonoDomain *domain;
343 List downloaders;
344 List paths;
346 // true if we're going to notify Loaded events on the next
347 // tick.
348 bool pending_loaded;
350 Mutex medias_mutex;
351 /* accessed from several threads, needs the medias_mutex locked on all accesses */
352 List *medias;
354 bool is_shutting_down;
355 bool appdomain_unloaded;
356 bool is_loaded_from_xap;
357 // xap location, to help forging the right uris for downloaders
358 char *xap_location;
360 #if GLIB_CHECK_VERSION(2,10,0)
361 volatile gpointer pending_unrefs;
362 #else
363 gpointer pending_unrefs;
364 #endif
366 gint objects_created;
367 gint objects_destroyed;
369 #if OBJECT_TRACKING
370 GHashTable *objects_alive;
371 pthread_mutex_t objects_alive_mutex;
372 void ReportLeaks ();
373 #endif
375 ShutdownState shutdown_state;
376 MonoImage *system_windows_image;
377 MonoAssembly *system_windows_assembly;
378 MonoClass *system_windows_deployment;
379 MonoMethod *deployment_shutdown;
381 // Methods
382 MonoMethod *moon_load_xaml;
383 MonoMethod *moon_initialize_deployment_xap;
384 MonoMethod *moon_initialize_deployment_xaml;
385 MonoMethod *moon_destroy_application;
387 MonoClass *moon_exception;
388 MonoProperty *moon_exception_message;
389 MonoProperty *moon_exception_error_code;
391 MonoMethod *MonoGetMethodFromName (MonoClass *klass, const char *name, int narg);
392 MonoProperty *MonoGetPropertyFromName (MonoClass *klass, const char *name);
395 static gboolean ShutdownManagedCallback (gpointer user_data);
396 gboolean ShutdownManaged ();
398 static Deployment *desktop_deployment;
399 static GHashTable *current_hash;
400 static gboolean initialized;
401 static pthread_key_t tls_key;
402 static pthread_mutex_t hash_mutex;
403 static MonoDomain *root_domain;
404 static gint32 deployment_count;
408 * DeploymentStack:
409 * for all calls into javascript we need to push/pop the current deployment.
410 * this class is (ab)uses C++ for this, just put a "DeploymentStack deployment_push_pop;"
411 * in every method which needs to push/pop the current deployment. the compiler will
412 * call the ctor in the beginning of the method, and the dtor in the end.
414 class DeploymentStack {
415 public:
416 DeploymentStack ()
418 deployment = Deployment::GetCurrent ();
421 ~DeploymentStack ()
423 Deployment::SetCurrent (deployment);
426 private:
427 Deployment *deployment;
430 #endif /* __DEPLOYMENT_H__ */