Context.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005 Palmsource, Inc.
00003  * 
00004  * This software is licensed as described in the file LICENSE, which
00005  * you should have received as part of this distribution. The terms
00006  * are also available at http://www.openbinder.org/license.html.
00007  * 
00008  * This software consists of voluntary contributions made by many
00009  * individuals. For the exact contribution history, see the revision
00010  * history and logs, available at http://www.openbinder.org
00011  */
00012 
00013 #ifndef SUPPORT_CONTEXT_H_
00014 #define SUPPORT_CONTEXT_H_
00015 
00021 #include <support/String.h>
00022 #include <support/Value.h>
00023 #include <support/Vector.h>
00024 
00025 #if _SUPPORTS_NAMESPACE
00026 namespace palmos {
00027 namespace support {
00028 #endif
00029 
00034 class INode;
00035 class IProcess;
00036 
00038 class SContext
00039 {
00040 public:
00041 // SContext must exist, but only by name in bootstrap code
00042 #if !LIBBE_BOOTSTRAP
00043     SContext();
00044     SContext(const sptr<INode>& node);
00045     SContext(const SContext& context);
00046     ~SContext();
00047     
00048     SContext& operator=(const SContext& o);
00049     
00050     bool operator==(const SContext& o) const;
00051     bool operator!=(const SContext& o) const;
00052     bool operator<(const SContext& o) const;
00053     bool operator<=(const SContext& o) const;
00054     bool operator>=(const SContext& o) const;
00055     bool operator>(const SContext& o) const;
00056 
00057     status_t InitCheck() const;
00058 
00060     enum new_flags_enum {
00062         PROCESS_MASK    = 0x000f,
00063         
00065 
00067         PREFER_LOCAL    = 0x0000,
00069 
00074         PREFER_REMOTE   = 0x0001,
00076 
00078         REQUIRE_LOCAL   = 0x0002,
00080 
00083         REQUIRE_REMOTE  = 0x0003
00084     };
00085     
00087 
00096     sptr<IBinder> New(  const SValue& component,
00097                         const SValue& args = B_UNDEFINED_VALUE,
00098                         uint32_t flags = PREFER_LOCAL,
00099                         status_t* outError = NULL) const;
00100 
00102 
00117     sptr<IBinder> RemoteNew(    const SValue& component,
00118                                 const sptr<IProcess>& process,
00119                                 const SValue& args = B_UNDEFINED_VALUE,
00120                                 uint32_t flags = PREFER_LOCAL,
00121                                 status_t* outError = NULL) const;
00122     
00124 
00137     sptr<IProcess> NewProcess(  const SString& name,
00138                                 uint32_t flags = PREFER_REMOTE,
00139                                 const SValue& env = B_UNDEFINED_VALUE,
00140                                 status_t* outError = NULL) const;
00141     
00143     sptr<IBinder> NewCustomProcess( const SString& executable,
00144                                     const SVector<SString>& args = SVector<SString>(),
00145                                     uint32_t flags = 0,
00146                                     const SValue& env = B_UNDEFINED_VALUE,
00147                                     status_t* outError = NULL) const;
00148     
00149     SValue Lookup(const SString& location) const;
00150     sptr<IBinder> LookupService(const SString& name) const;
00151     template<class INTERFACE> sptr<INTERFACE> LookupServiceAs(const SString& name) const;
00152     
00153     status_t Publish(const SString& location, const SValue& val) const;
00154     status_t PublishService(const SString& name, const sptr<IBinder>& object) const;
00155     status_t Unpublish(const SString& location) const;
00156     
00157     sptr<INode> Root() const;
00158 
00159     status_t LookupComponent(const SString& id, SValue* out_info) const;
00160     SValue LookupComponentProperty(const SString& component, const SString& property) const;
00161 
00162     status_t RunScript(const SString &filename) const;
00163 
00165 
00173     static SContext UserContext();
00174     
00176 
00180     static SContext SystemContext();
00181 
00183 
00187     static SContext GetContext(const SString& name);
00188     
00190 
00192     static SContext GetContext(const SString& name, const sptr<IProcess>& caller);
00193 
00194 private:
00195     mutable sptr<INode> m_root;
00196 
00197 #endif
00198 };
00199 
00202 #if !LIBBE_BOOTSTRAP
00203 template<class INTERFACE>
00204 sptr<INTERFACE> SContext::LookupServiceAs(const SString& name) const
00205 {
00206     return interface_cast<INTERFACE>(LookupService(name));
00207 }   
00208 #endif // !LIBBE_BOOTSTRAP
00209 
00210 #if _SUPPORTS_NAMESPACE
00211 } } // namespace palmos::support
00212 #endif
00213 
00214 #endif // SUPPORT_CONTEXT_H_