2009-10-09 Chris Toshok <toshok@ximian.com>
[moon.git] / src / deployment.h
blob4c943464004a0e581304afffe0ab4c3a8bd0e2d2
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 DependencyObject {
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 OutOfBrowserSettings : public DependencyObject {
92 public:
93 /* @GenerateCBinding,GeneratePInvoke */
94 OutOfBrowserSettings ();
96 /* @PropertyType=string,DefaultValue=\"\",Version=2.0,Validator=NonNullValidator,GenerateAccessors */
97 const static int BlurbProperty;
98 /* @PropertyType=bool,DefaultValue=true,GenerateAccessors */
99 const static int EnableGPUAccelerationProperty;
101 const char *GetBlurb ();
102 void SetBlurb (const char *blurb);
104 bool GetEnableGPUAcceleration ();
105 void SetEnableGPUAcceleration (bool enable);
107 protected:
108 virtual ~OutOfBrowserSettings ();
111 /* @Namespace=System.Windows */
112 class Deployment : public DependencyObject {
113 public:
114 /* @PropertyType=CrossDomainAccess,DefaultValue=CrossDomainAccessNoAccess,ManagedSetterAccess=Internal,GenerateAccessors,Validator=CrossDomainValidator */
115 const static int ExternalCallersFromCrossDomainProperty;
116 /* @PropertyType=string,ManagedSetterAccess=Internal */
117 const static int EntryPointAssemblyProperty;
118 /* @PropertyType=string,ManagedSetterAccess=Internal */
119 const static int EntryPointTypeProperty;
120 /* @PropertyType=ExternalPartCollection,AutoCreateValue,ManagedSetterAccess=Internal,GenerateAccessors */
121 const static int ExternalPartsProperty;
122 /* @PropertyType=OutOfBrowserSettings,ManagedSetterAccess=Internal,GenerateAccessors */
123 const static int OutOfBrowserSettingsPropery;
124 /* @PropertyType=AssemblyPartCollection,ManagedSetterAccess=Internal,GenerateAccessors */
125 const static int PartsProperty;
126 /* @PropertyType=string,ManagedSetterAccess=Internal,GenerateAccessors */
127 const static int RuntimeVersionProperty;
128 /* @PropertyType=Surface,ManagedAccess=Internal,GenerateAccessors */
129 const static int SurfaceProperty;
131 /* @GenerateCBinding,GeneratePInvoke */
132 Deployment ();
134 virtual void Dispose ();
136 /* @GenerateCBinding,GeneratePInvoke */
137 Types* GetTypes();
139 Surface *GetSurface ();
140 void SetSurface (Surface *surface);
142 AssemblyPartCollection *GetParts ();
143 void SetParts (AssemblyPartCollection *col);
145 ExternalPartCollection *GetExternalParts ();
146 void SetExternalParts (ExternalPartCollection *col);
148 OutOfBrowserSettings *GetOutOfBrowserSettings ();
149 void SetOutOfBrowserSettings (OutOfBrowserSettings *oob);
151 void SetRuntimeVersion (const char *version);
152 const char *GetRuntimeVersion ();
154 void Reinitialize ();
156 Application* GetCurrentApplication ();
157 /* @GenerateCBinding,GeneratePInvoke */
158 void SetCurrentApplication (Application* value);
160 void RegisterDownloader (IDownloader *dl);
161 void UnregisterDownloader (IDownloader *dl);
163 * thread-safe, returns false if the media couldn't be registered (if the
164 * deployment is already shutting down, in which case the media should
165 * dispose itself immediately)
167 bool RegisterMedia (EventObject *media);
168 /* thread-safe */
169 void UnregisterMedia (EventObject *media);
171 /* @GenerateCBinding,GeneratePInvoke */
172 static Deployment* GetCurrent ();
173 /* @GenerateCBinding,GeneratePInvoke */
174 static void SetCurrent (Deployment* value);
175 static void SetCurrent (Deployment* value, bool domain);
177 static bool Initialize (const char *platform_dir, bool create_root_domain);
179 static void RegisterThread (Deployment *deployment);
181 void UnrefDelayed (EventObject *obj);
183 void TrackObjectCreated (EventObject *obj);
184 void TrackObjectDestroyed (EventObject *obj);
186 bool IsLoadedFromXap ();
187 /* @GenerateCBinding,GeneratePInvoke */
188 void SetIsLoadedFromXap (bool flag);
190 void SetXapLocation (const char *location);
191 const char *GetXapLocation ();
193 FontManager *GetFontManager ();
195 CrossDomainAccess GetExternalCallersFromCrossDomain ();
196 void SetExternalCallersFromCrossDomain (CrossDomainAccess value);
198 /* @GenerateManagedEvent=false */
199 const static int ShuttingDownEvent;
200 /* @GenerateManagedEvent=false */
201 const static int AppDomainUnloadedEvent; /* this is emitted just after the appdomain has successfully unloaded */
203 void Shutdown (MonoImage *system_windows_assembly); /* main thread only */
204 bool IsShuttingDown (); /* main thread only */
206 void TrackPath (char *path);
207 void UntrackPath (char *path);
209 static gint32 GetDeploymentCount (); /* returns the number of deployments currently alive */
210 protected:
211 virtual ~Deployment ();
213 private:
214 enum ShutdownState {
215 ShutdownFailed = -1,
216 Running = 0,
217 CallManagedShutdown = 1,
218 UnloadDomain = 2,
219 DisposeDeployment = 3
221 Deployment (MonoDomain *domain);
222 void InnerConstructor ();
224 void AbortAllDownloaders ();
225 void DisposeAllMedias ();
226 void DrainUnrefs ();
227 static gboolean DrainUnrefs (gpointer ptr);
229 Types* types;
230 FontManager *font_manager;
231 Application *current_app;
232 MonoDomain *domain;
233 List downloaders;
234 List paths;
236 Mutex medias_mutex;
237 /* accessed from several threads, needs the medias_mutex locked on all accesses */
238 List *medias;
240 bool is_shutting_down;
241 bool appdomain_unloaded;
242 bool is_loaded_from_xap;
243 // xap location, to help forging the right uris for downloaders
244 char *xap_location;
246 #if GLIB_CHECK_VERSION(2,10,0)
247 volatile gpointer pending_unrefs;
248 #else
249 gpointer pending_unrefs;
250 #endif
252 gint objects_created;
253 gint objects_destroyed;
255 #if OBJECT_TRACKING
256 GHashTable *objects_alive;
257 pthread_mutex_t objects_alive_mutex;
258 void ReportLeaks ();
259 #endif
261 ShutdownState shutdown_state;
262 MonoImage *system_windows_assembly;
263 MonoClass *system_windows_deployment;
264 MonoMethod *deployment_shutdown;
265 static gboolean ShutdownManagedCallback (gpointer user_data);
266 gboolean ShutdownManaged ();
268 static Deployment *desktop_deployment;
269 static GHashTable *current_hash;
270 static gboolean initialized;
271 static pthread_key_t tls_key;
272 static pthread_mutex_t hash_mutex;
273 static MonoDomain *root_domain;
274 static gint32 deployment_count;
278 * DeploymentStack:
279 * for all calls into javascript we need to push/pop the current deployment.
280 * this class is (ab)uses C++ for this, just put a "DeploymentStack deployment_push_pop;"
281 * in every method which needs to push/pop the current deployment. the compiler will
282 * call the ctor in the beginning of the method, and the dtor in the end.
284 class DeploymentStack {
285 public:
286 DeploymentStack ()
288 deployment = Deployment::GetCurrent ();
291 ~DeploymentStack ()
293 Deployment::SetCurrent (deployment);
296 private:
297 Deployment *deployment;
300 #endif /* __DEPLOYMENT_H__ */