Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Attributes | Private Member Functions
xpcom.client.Component Class Reference
Inheritance diagram for xpcom.client.Component:
Inheritance graph
[legend]
Collaboration diagram for xpcom.client.Component:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def QueryInterface
def __getattr__
def __setattr__
def __repr__
def __cmp__
def __hash__
def __str__
def __int__
def __long__
def __float__

Static Public Attributes

 queryInterface = QueryInterface

Private Member Functions

def _build_all_supported_interfaces_
def _remember_interface_info
def _make_interface_info

Detailed Description

Definition at line 208 of file __init__.py.


Constructor & Destructor Documentation

def xpcom.client.Component.__init__ (   self,
  ob,
  iid 
)

Definition at line 209 of file __init__.py.

00209 
00210     def __init__(self, ob, iid):
00211         assert not hasattr(ob, "_comobj_"), "Should be a raw nsIWhatever, not a wrapped one"
00212         ob_name = None
00213         if not hasattr(ob, "IID"):
00214             ob_name = ob
00215             cm = GetComponentManager()
00216             ob = cm.createInstanceByContractID(ob)
00217             assert not hasattr(ob, "_comobj_"), "The created object should be a raw nsIWhatever, not a wrapped one"
00218         # Keep a reference to the object in the component too
00219         self.__dict__['_comobj_'] = ob
00220         # hit __dict__ directly to avoid __setattr__()
00221         self.__dict__['_interfaces_'] = {} # keyed by IID
00222         self.__dict__['_interface_names_'] = {} # keyed by IID name
00223         self.__dict__['_interface_infos_'] = {} # keyed by IID
00224         self.__dict__['_name_to_interface_name_'] = {}
00225         self.__dict__['_tried_classinfo_'] = 0
00226 
00227         if ob_name is None:
00228             ob_name = "<unknown>"
00229         self.__dict__['_object_name_'] = ob_name
00230         self.QueryInterface(iid)

Here is the call graph for this function:


Member Function Documentation

def xpcom.client._XPCOMBase.__cmp__ (   self,
  other 
) [inherited]

Definition at line 169 of file __init__.py.

00169 
00170     def __cmp__(self, other):
00171         try:
00172             other = other._comobj_
00173         except AttributeError:
00174             pass
00175         return cmp(self._comobj_, other)

def xpcom.client._XPCOMBase.__float__ (   self) [inherited]

Definition at line 205 of file __init__.py.

00205 
00206     def __float__(self):
        return self._do_conversion(_float_interfaces, float)

Here is the call graph for this function:

def xpcom.client.Component.__getattr__ (   self,
  attr 
)

Definition at line 308 of file __init__.py.

00308 
00309     def __getattr__(self, attr):
00310         if attr in _special_getattr_names:
00311             raise AttributeError, attr
00312         # First allow the interface name to return the "raw" interface
00313         interface = self.__dict__['_interface_names_'].get(attr, None)
00314         if interface is not None:
00315             return interface
00316         interface_name = self.__dict__['_name_to_interface_name_'].get(attr, None)
00317         # This may be first time trying this interface - get the nsIClassInfo
00318         if interface_name is None and not self._tried_classinfo_:
00319             self._build_all_supported_interfaces_()
00320             interface_name = self.__dict__['_name_to_interface_name_'].get(attr, None)
00321             
00322         if interface_name is not None:
00323             interface = self.__dict__['_interface_names_'].get(interface_name, None)
00324             if interface is None:
00325                 iid = XPTI_GetInterfaceInfoManager().GetInfoForName(interface_name).GetIID()
00326                 self.QueryInterface(iid)
00327                 interface = self.__dict__['_interface_names_'][interface_name]
00328             return getattr(interface, attr)
00329         # Some interfaces may provide this name via "native" support.
00330         # Loop over all interfaces, and if found, cache it for next time.
00331         for interface in self.__dict__['_interfaces_'].values():
00332             try:
00333                 ret = getattr(interface, attr)
00334                 self.__dict__['_name_to_interface_name_'][attr] = interface._iid_.name
00335                 return ret
00336             except AttributeError:
00337                 pass
00338         raise AttributeError, "XPCOM component '%s' has no attribute '%s'" % (self._object_name_, attr)
        

Here is the call graph for this function:

def xpcom.client._XPCOMBase.__hash__ (   self) [inherited]

Definition at line 176 of file __init__.py.

00176 
00177     def __hash__(self):
00178         return hash(self._comobj_)

Here is the call graph for this function:

def xpcom.client._XPCOMBase.__int__ (   self) [inherited]

Definition at line 199 of file __init__.py.

00199 
00200     def __int__(self):
00201         return self._do_conversion(_int_interfaces, int)

Here is the call graph for this function:

def xpcom.client._XPCOMBase.__long__ (   self) [inherited]

Definition at line 202 of file __init__.py.

00202 
00203     def __long__(self):
00204         return self._do_conversion(_long_interfaces, long)

Here is the call graph for this function:

Definition at line 354 of file __init__.py.

00354 
00355     def __repr__(self):
00356         # We can advantage from nsIClassInfo - use it.
00357         try:
00358             if not self._tried_classinfo_:
00359                 self._build_all_supported_interfaces_()
00360             assert self._tried_classinfo_, "Should have tried the class info by now!"
00361         except COMException:
00362             # Error building the info - ignore the error, but ensure that
00363             # we are flagged as *not* having built, so the error is seen
00364             # by the first caller who actually *needs* this to work.
00365             self.__dict__['_tried_classinfo_'] = 0
00366         infos = self.__dict__['_interface_infos_']
00367         if infos:
00368             iface_names = ",".join([iid.name for iid in infos.keys()])
00369             iface_desc = " (implementing %s)" % (iface_names,)
00370         else:
00371             iface_desc = " (with no class info)"
00372         return "<XPCOM component '%s'%s>" % (self._object_name_,iface_desc)

Here is the call graph for this function:

Here is the caller graph for this function:

def xpcom.client.Component.__setattr__ (   self,
  attr,
  val 
)

Definition at line 339 of file __init__.py.

00339 
00340     def __setattr__(self, attr, val):
00341         interface_name = self._name_to_interface_name_.get(attr, None)
00342         # This may be first time trying this interface - get the nsIClassInfo
00343         if interface_name is None and not self._tried_classinfo_:
00344             self._build_all_supported_interfaces_()
00345             interface_name = self.__dict__['_name_to_interface_name_'].get(attr, None)
00346         if interface_name is not None:
00347             interface = self._interface_names_.get(interface_name, None)
00348             if interface is None:
00349                 iid = XPTI_GetInterfaceInfoManager().GetInfoForName(interface_name).GetIID()
00350                 self.QueryInterface(iid)
00351                 interface = self.__dict__['_interface_names_'][interface_name]
00352             setattr(interface, attr, val)
00353             return
        raise AttributeError, "XPCOM component '%s' has no attribute '%s'" % (self._object_name_, attr)

Here is the call graph for this function:

def xpcom.client._XPCOMBase.__str__ (   self) [inherited]

Definition at line 180 of file __init__.py.

00180 
00181     def __str__(self):
00182         try:
00183             self._comobj_.QueryInterface(IID_nsISupportsCString, 0)
00184             return str(self._comobj_)
00185         except COMException:
00186             return self.__repr__()

Here is the call graph for this function:

Definition at line 231 of file __init__.py.

00231 
00232     def _build_all_supported_interfaces_(self):
00233         # Use nsIClassInfo, but don't do it at object construction to keep perf up.
00234         # Only pay the penalty when we really need it.
00235         assert not self._tried_classinfo_, "already tried to get the class info."
00236         self.__dict__['_tried_classinfo_'] = 1
00237         # See if nsIClassInfo is supported.
00238         try:
00239             classinfo = self._comobj_.QueryInterface(IID_nsIClassInfo, 0)
00240         except COMException:
00241             classinfo = None
00242         if classinfo is not None:
00243             try:
00244                 real_cid = classinfo.contractID
00245             except COMException:
00246                 real_cid = None
00247             if real_cid:
00248                 self.__dict__['_object_name_'] = real_cid
00249                 contractid_info = contractid_info_cache.get(real_cid)
00250             else:
00251                 contractid_info = None
00252             if contractid_info is None:
00253                 try:
00254                     interface_infos = classinfo.getInterfaces()
00255                 except COMException:
00256                     interface_infos = []
00257                 for nominated_iid in interface_infos:
00258                     # Interface may appear twice in the class info list, so check this here.
00259                     if not self.__dict__['_interface_infos_'].has_key(nominated_iid):
00260                         self._remember_interface_info(nominated_iid)
00261                 if real_cid is not None:
00262                     contractid_info = {}
00263                     contractid_info['_name_to_interface_name_'] = self.__dict__['_name_to_interface_name_']
00264                     contractid_info['_interface_infos_'] = self.__dict__['_interface_infos_']
00265                     contractid_info_cache[real_cid] = contractid_info
00266             else:
00267                 for key, val in contractid_info.items():
00268                     self.__dict__[key].update(val)
00269 
00270         self.__dict__['_com_classinfo_'] = classinfo

Here is the call graph for this function:

Here is the caller graph for this function:

def xpcom.client.Component._make_interface_info (   self,
  ob,
  iid 
) [private]

Definition at line 283 of file __init__.py.

00283 
00284     def _make_interface_info(self, ob, iid):
00285         interface_infos = self._interface_infos_
00286         assert not self._interfaces_.has_key(iid), "Already have made this interface"
00287         method_infos, getters, setters, constants = interface_infos[iid]
00288         new_interface = _Interface(ob, iid, method_infos, getters, setters, constants)
00289         self._interfaces_[iid] = new_interface
00290         self._interface_names_[iid.name] = new_interface
00291         # No point remembering these.
00292         del interface_infos[iid]

Here is the caller graph for this function:

def xpcom.client.Component._remember_interface_info (   self,
  iid 
) [private]

Definition at line 271 of file __init__.py.

00271 
00272     def _remember_interface_info(self, iid):
00273         method_infos, getters, setters, constants = BuildInterfaceInfo(iid)
00274         # Remember all the names so we can delegate
00275         assert not self.__dict__['_interface_infos_'].has_key(iid), "Already remembered this interface!"
00276         self.__dict__['_interface_infos_'][iid] = method_infos, getters, setters, constants
00277         interface_name = iid.name
00278         names = self.__dict__['_name_to_interface_name_']
00279         for name in method_infos.keys(): names[name] = interface_name
00280         for name in getters.keys(): names[name] = interface_name
00281         for name in setters.keys(): names[name] = interface_name
00282         for name in constants.keys():  names[name] = interface_name

Here is the call graph for this function:

Here is the caller graph for this function:

def xpcom.client.Component.QueryInterface (   self,
  iid 
)

Definition at line 293 of file __init__.py.

00293 
00294     def QueryInterface(self, iid):
00295         if self._interfaces_.has_key(iid):
00296             assert self._interface_names_.has_key(iid.name), "_interfaces_ has the key, but _interface_names_ does not!"
00297             return self
00298         # Haven't seen this before - do a real QI.
00299         if not self._interface_infos_.has_key(iid):
00300             self._remember_interface_info(iid)
00301         ret = self._comobj_.QueryInterface(iid, 0)
00302 #        print "Component QI for", iid, "yielded", ret
00303         self._make_interface_info(ret, iid)
00304         assert self._interfaces_.has_key(iid) and self._interface_names_.has_key(iid.name), "Making the interface didn't update the maps"
00305         return self

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 306 of file __init__.py.


The documentation for this class was generated from the following file: