00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00040 #include "TclXPCOMPrivate.h"
00041
00042 #ifndef USE_TCL_WIDEINT
00043 # include "prprf.h"
00044 #endif
00045
00046 #define NULL_STRINGREP "TclXPCOM NULL Object"
00047
00092 typedef struct TclXPCOM_Command
00093 {
00094 char *dummy1;
00095 char *dummy2;
00096 int dummy3;
00097 int dummy4;
00098 char *dummy5;
00099 Tcl_ObjCmdProc *objProc;
00100 ClientData objClientData;
00101 char *dummy6;
00102 ClientData dummy7;
00103 char *dummy8;
00104 ClientData dummy9;
00105 int dummy10;
00106 char *dummy11;
00107 char *dummy12;
00108 } TclXPCOM_Command;
00109
00110 typedef struct TclXPCOM_ResolvedCmdName
00111 {
00112 TclXPCOM_Command *cmdPtr;
00113 char *dummy1;
00114 long dummy2;
00115 int dummy3;
00116 int dummy4;
00117 int dummy5;
00118 } TclXPCOM_ResolvedCmdName;
00119
00120 static TclXPCOM_Command isupportscmd =
00121 {
00122 NULL,
00123 NULL,
00124 0,
00125 0,
00126 NULL,
00127 TclXPCOM_InvokeObjCmd,
00128 (ClientData)0,
00129 NULL,
00130 NULL,
00131 NULL,
00132 NULL,
00133 0,
00134 NULL,
00135 NULL
00136 };
00137
00138 static TclXPCOM_ResolvedCmdName resolvedisupports =
00139 {
00140 &isupportscmd,
00141 NULL,
00142 0,
00143 0,
00144 0,
00145 0
00146 };
00147
00148 Tcl_ObjType ISupportsType;
00149
00150 static Tcl_ObjType SavedCmdNameType;
00151 static Tcl_ObjType NsIDType;
00152 static Tcl_ObjType PointerType;
00153 static Tcl_ObjType IdentifierType;
00154 static Tcl_ObjType *CmdNameType;
00155
00156 #ifndef USE_TCL_WIDEINT
00157 #define TCLXPCOM_WIDEINTTYPENAME "TclXPCOM_WideInt"
00158 static Tcl_ObjType WideIntType;
00159 #endif
00160
00164 static void
00165 UpdateStringOfPointer(
00166 Tcl_Obj *objPtr
00167 )
00168 {
00169 int length;
00170 char str[128];
00171
00172 NS_PRECONDITION(objPtr, "null pointer");
00173
00174 if (objPtr->internalRep.twoPtrValue.ptr1 == NULL)
00175 {
00176 length = sprintf(str, NULL_STRINGREP);
00177 } else
00178 {
00179 length = sprintf(str, "TclXPCOM Pointer @%p", objPtr->internalRep.twoPtrValue.ptr1);
00180 }
00181
00182 objPtr->bytes = Tcl_Alloc(length + 1);
00183 memcpy(objPtr->bytes, str, length + 1);
00184 objPtr->length = length;
00185 }
00186
00187
00197 static int
00198 SetPointerFromAny(
00199 Tcl_Interp *interp,
00200 Tcl_Obj *objPtr
00201 )
00202 {
00203 int rv;
00204 void *ptr;
00205
00206
00207 NS_PRECONDITION(objPtr, "null pointer");
00208
00209 if (TclXPCOM_IsNULL(objPtr))
00210 {
00211 ptr = NULL;
00212 rv = TCL_OK;
00213
00214 } else if (sscanf(Tcl_GetString(objPtr), "TclXPCOM Pointer @%p", (void **)&ptr) == 1)
00215 {
00216 rv = TCL_OK;
00217 } else
00218 {
00219 if (interp)
00220 {
00221 Tcl_ResetResult(interp);
00222 Tcl_AppendResult(interp, "invalid pointer object \"", Tcl_GetString(objPtr), "\"", NULL);
00223 }
00224 rv = TCL_ERROR;
00225 }
00226
00227 if (rv == TCL_OK)
00228 {
00229 if (objPtr->typePtr && objPtr->typePtr->freeIntRepProc)
00230 {
00231 objPtr->typePtr->freeIntRepProc(objPtr);
00232 }
00233 objPtr->internalRep.twoPtrValue.ptr1 = ptr;
00234 objPtr->typePtr = &PointerType;
00235 }
00236
00237 return rv;
00238 }
00239
00240
00244 static void
00245 FreeISupportsObj(
00246 Tcl_Obj *objPtr
00247 )
00248 {
00249 Tcl_HashEntry *entry;
00250
00251 NS_PRECONDITION(objPtr, "null pointer");
00252
00253
00254 entry = (Tcl_HashEntry *)objPtr->internalRep.twoPtrValue.ptr2;
00255 ReleaseInterface((nsISupports *)Tcl_GetHashValue(entry));
00256 }
00257
00258
00262 static void
00263 DuplicateISupportsObj(
00264 Tcl_Obj *srcPtr,
00265 Tcl_Obj *dupPtr
00266 )
00267 {
00268 Tcl_HashEntry *entry;
00269
00270 NS_PRECONDITION(srcPtr, "null pointer");
00271 NS_PRECONDITION(dupPtr, "null pointer");
00272
00273
00274
00275 dupPtr->internalRep.twoPtrValue = srcPtr->internalRep.twoPtrValue;
00276 entry = (Tcl_HashEntry *)dupPtr->internalRep.twoPtrValue.ptr2;
00277 AddRefInterface((nsISupports *)Tcl_GetHashValue(entry), (nsIInterfaceInfo *)entry->key.oneWordValue, NULL);
00278 }
00279
00280
00285 static void
00286 UpdateStringOfISupports(
00287 Tcl_Obj *objPtr
00288 )
00289 {
00290 int length;
00291 char str[128];
00292 const char *name;
00293 Tcl_HashEntry *entry;
00294
00295 NS_PRECONDITION(objPtr, "null pointer");
00296
00297
00298
00299 entry = (Tcl_HashEntry *)objPtr->internalRep.twoPtrValue.ptr2;
00300 ((nsIInterfaceInfo *)(entry->key.oneWordValue))->GetNameShared(&name);
00301
00302 length = sprintf(str, "xpcom::inscope %s::%p", name, Tcl_GetHashValue(entry));
00303
00304 objPtr->bytes = Tcl_Alloc(length + 1);
00305 memcpy(objPtr->bytes, str, length + 1);
00306 objPtr->length = length;
00307 }
00308
00309
00319 static int
00320 SetISupportsFromAny(
00321 Tcl_Interp *interp,
00322 Tcl_Obj *objPtr
00323 )
00324 {
00325 int rv;
00326 nsresult res;
00327 char name[128];
00328 nsISupports *ref, *isupports;
00329 nsIInterfaceInfo *interfaceinfo;
00330 InterfaceRef *iref;
00331 Tcl_HashEntry *entry;
00332
00333
00334 NS_PRECONDITION(objPtr, "null pointer");
00335
00336 if (objPtr->typePtr == CmdNameType && objPtr->internalRep.twoPtrValue.ptr2)
00337 {
00338 return TCL_OK;
00339 }
00340
00341
00342
00343 if (sscanf(Tcl_GetString(objPtr), "xpcom::inscope %127[^:]::%p", name, (void **)&ref) == 2)
00344 {
00345 iref = GetInterfaceRef(ref);
00346 if (iref)
00347 {
00348 res = manager->GetInfoForName(name, &interfaceinfo);
00349 if (NS_SUCCEEDED(res))
00350 {
00351 rv = QueryInterfaceIRef(NULL, iref, interfaceinfo, &isupports);
00352 if (rv != TCL_OK)
00353 {
00354 if (interp)
00355 {
00356 Tcl_ResetResult(interp);
00357 Tcl_AppendResult(interp, "interface \"", name, "\" is not supported by \"", Tcl_GetString(objPtr), "\"", NULL);
00358 }
00359 }
00360 } else
00361 {
00362 if (interp)
00363 {
00364 Tcl_ResetResult(interp);
00365 Tcl_AppendResult(interp, "unknown interface \"", name, "\" in interface reference \"", Tcl_GetString(objPtr), "\"", NULL);
00366 }
00367 rv = TCL_ERROR;
00368 }
00369 } else
00370 {
00371 if (interp)
00372 {
00373 Tcl_ResetResult(interp);
00374 Tcl_AppendResult(interp, "interface reference \"", Tcl_GetString(objPtr), "\" doesn't point to a known component", NULL);
00375 }
00376 rv = TCL_ERROR;
00377 }
00378 } else
00379 {
00380 if (interp)
00381 {
00382 Tcl_ResetResult(interp);
00383 Tcl_AppendResult(interp, "invalid interface reference \"", Tcl_GetString(objPtr), "\"", NULL);
00384 }
00385 rv = TCL_ERROR;
00386 }
00387
00388 if (rv == TCL_OK)
00389 {
00390 if (objPtr->typePtr && objPtr->typePtr->freeIntRepProc)
00391 {
00392 objPtr->typePtr->freeIntRepProc(objPtr);
00393 }
00394 objPtr->internalRep.twoPtrValue.ptr1 = &resolvedisupports;
00395 AddRefInterface(isupports, interfaceinfo, &entry);
00396 objPtr->internalRep.twoPtrValue.ptr2 = entry;
00397 objPtr->typePtr = CmdNameType;
00398 }
00399
00400 return rv;
00401 }
00402
00403
00407 static void
00408 FreeCmdNameObj(
00409 Tcl_Obj *objPtr
00410 )
00411 {
00412 NS_PRECONDITION(objPtr, "null pointer");
00413
00414 if (objPtr->internalRep.twoPtrValue.ptr2)
00415 {
00416 FreeISupportsObj(objPtr);
00417 } else
00418 {
00419 SavedCmdNameType.freeIntRepProc(objPtr);
00420 }
00421 }
00422
00423
00427 static void
00428 DuplicateCmdNameObj(
00429 Tcl_Obj *srcPtr,
00430 Tcl_Obj *dupPtr
00431 )
00432 {
00433 NS_PRECONDITION(srcPtr, "null pointer");
00434 NS_PRECONDITION(dupPtr, "null pointer");
00435
00436 if (srcPtr->internalRep.twoPtrValue.ptr2)
00437 {
00438 DuplicateISupportsObj(srcPtr, dupPtr);
00439 } else
00440 {
00441 SavedCmdNameType.dupIntRepProc(srcPtr, dupPtr);
00442 }
00443 }
00444
00445
00449 static void
00450 UpdateStringOfCmdName(
00451 Tcl_Obj *objPtr
00452 )
00453 {
00454 NS_PRECONDITION(objPtr, "null pointer");
00455
00456 if (objPtr->internalRep.twoPtrValue.ptr2)
00457 {
00458 UpdateStringOfISupports(objPtr);
00459 } else
00460 {
00461 NS_ASSERTION(0, "shouldn't call UpdateString on a cmdName object");
00462 }
00463 }
00464
00465
00472 static int
00473 SetCmdNameFromAny(
00474 Tcl_Interp *interp,
00475 Tcl_Obj *objPtr
00476 )
00477 {
00478 int rv;
00479
00480
00481 NS_PRECONDITION(objPtr, "null pointer");
00482
00483 rv = SetISupportsFromAny(NULL, objPtr);
00484
00485 if (rv != TCL_OK)
00486 {
00487 rv = SavedCmdNameType.setFromAnyProc(interp, objPtr);
00488 }
00489
00490 return rv;
00491 }
00492
00493
00497 static void
00498 FreeIdentifierObj(
00499 Tcl_Obj *objPtr
00500 )
00501 {
00502 NS_PRECONDITION(objPtr, "null pointer");
00503
00504 nsIInterfaceInfo *interfaceinfo;
00505
00506 if (objPtr->internalRep.twoPtrValue.ptr1)
00507 {
00508 interfaceinfo = (nsIInterfaceInfo *)objPtr->internalRep.twoPtrValue.ptr1;
00509 NS_RELEASE(interfaceinfo);
00510 }
00511
00512 memmgr->Free(objPtr->internalRep.twoPtrValue.ptr2);
00513 }
00514
00515
00519 static void
00520 DuplicateIdentifierObj(
00521 Tcl_Obj *srcPtr,
00522 Tcl_Obj *dupPtr
00523 )
00524 {
00525 NS_PRECONDITION(srcPtr, "null pointer");
00526 NS_PRECONDITION(dupPtr, "null pointer");
00527
00528 if (srcPtr->internalRep.twoPtrValue.ptr1)
00529 {
00530 dupPtr->internalRep.twoPtrValue.ptr1 = srcPtr->internalRep.twoPtrValue.ptr1;
00531 NS_ADDREF(((nsIInterfaceInfo *)dupPtr->internalRep.twoPtrValue.ptr1));
00532 } else
00533 {
00534 dupPtr->internalRep.twoPtrValue.ptr1 = NULL;
00535 }
00536
00537 dupPtr->internalRep.twoPtrValue.ptr2 = (void *)CloneMemory(srcPtr->internalRep.twoPtrValue.ptr2, sizeof(char) * (strlen((char *)srcPtr->internalRep.twoPtrValue.ptr2) + 1));
00538 }
00539
00540
00544 static void
00545 UpdateStringOfIdentifier(
00546 Tcl_Obj *objPtr
00547 )
00548 {
00549 int inamelength, identifierlength, length;
00550 const char *iname;
00551
00552 NS_PRECONDITION(objPtr, "null pointer");
00553
00554 if (objPtr->internalRep.twoPtrValue.ptr1)
00555 {
00556 ((nsIInterfaceInfo *)objPtr->internalRep.twoPtrValue.ptr1)->GetNameShared(&iname);
00557
00558 inamelength = strlen(iname);
00559 identifierlength = strlen((char *)objPtr->internalRep.twoPtrValue.ptr2);
00560
00561 length = inamelength + 2 + identifierlength;
00562
00563 objPtr->bytes = Tcl_Alloc(length + 1);
00564 memcpy(objPtr->bytes, iname, inamelength);
00565 objPtr->bytes[inamelength] = ':';
00566 objPtr->bytes[inamelength + 1] = ':';
00567 memcpy(&objPtr->bytes[inamelength + 2], objPtr->internalRep.twoPtrValue.ptr2, identifierlength + 1);
00568 objPtr->length = length;
00569
00570 } else
00571 {
00572 length = strlen((char *)objPtr->internalRep.twoPtrValue.ptr2);
00573
00574 objPtr->bytes = Tcl_Alloc(length + 1);
00575 memcpy(objPtr->bytes, objPtr->internalRep.twoPtrValue.ptr2, length + 1);
00576 objPtr->length = length;
00577 }
00578 }
00579
00580
00591 static int
00592 SetIdentifierFromAny(
00593 Tcl_Interp *interp,
00594 Tcl_Obj *objPtr
00595 )
00596 {
00597 int rv, index;
00598 nsresult res;
00599 char *interfacename, *identifier;
00600 nsIInterfaceInfo *interfaceinfo;
00601
00602
00603 NS_PRECONDITION(objPtr, "null pointer");
00604
00605 identifier = Tcl_GetString(objPtr);
00606
00607 for (index = strlen(identifier); index > 1; index--)
00608 {
00609 if (identifier[index-1] == ':' &&
00610 identifier[index-2] == ':')
00611 {
00612 break;
00613 }
00614 }
00615
00616 if (index > 1)
00617 {
00618 interfacename = (char *)memmgr->Alloc(sizeof(char) * (index - 1));
00619 memcpy(interfacename, identifier, sizeof(char) * (index - 2));
00620 interfacename[index - 2] = '\0';
00621
00622 res = manager->GetInfoForName(interfacename, &interfaceinfo);
00623
00624 if (NS_FAILED(res))
00625 {
00626 if (interp)
00627 {
00628 Tcl_ResetResult(interp);
00629 Tcl_AppendResult(interp, "unknown interface \"", interfacename, "\" in identifier \"", identifier, "\"", NULL);
00630 }
00631 rv = TCL_ERROR;
00632 } else
00633 {
00634 rv = TCL_OK;
00635 }
00636
00637 memmgr->Free(interfacename);
00638
00639 } else
00640 {
00641 index = 0;
00642 interfaceinfo = NULL;
00643 rv = TCL_OK;
00644 }
00645
00646 if (rv == TCL_OK)
00647 {
00648 if (objPtr->typePtr && objPtr->typePtr->freeIntRepProc)
00649 {
00650 objPtr->typePtr->freeIntRepProc(objPtr);
00651 }
00652 objPtr->internalRep.twoPtrValue.ptr1 = interfaceinfo;
00653 objPtr->internalRep.twoPtrValue.ptr2 = (void *)CloneMemory(&identifier[index], sizeof(char) * (strlen(&identifier[index]) + 1));
00654 objPtr->typePtr = &IdentifierType;
00655 }
00656
00657 return rv;
00658 }
00659
00660
00664 static void
00665 FreeNsIDObj(
00666 Tcl_Obj *objPtr
00667 )
00668 {
00669 NS_PRECONDITION(objPtr, "null pointer");
00670
00671 memmgr->Free(objPtr->internalRep.otherValuePtr);
00672 }
00673
00674
00678 static void
00679 DuplicateNsIDObj(
00680 Tcl_Obj *srcPtr,
00681 Tcl_Obj *dupPtr
00682 )
00683 {
00684 NS_PRECONDITION(srcPtr, "null pointer");
00685 NS_PRECONDITION(dupPtr, "null pointer");
00686
00687 dupPtr->internalRep.otherValuePtr = (void *)CloneMemory(srcPtr->internalRep.otherValuePtr, sizeof(nsID));
00688 }
00689
00690
00694 static void
00695 UpdateStringOfNsID(
00696 Tcl_Obj *objPtr
00697 )
00698 {
00699 int length;
00700 char *str;
00701 nsresult res;
00702
00703 NS_PRECONDITION(objPtr, "null pointer");
00704
00705 if ((res = manager->GetNameForIID((nsIID *)objPtr->internalRep.otherValuePtr, &str)) == NS_OK)
00706 {
00707
00708 }
00709 else if ((res = registrar->CIDToContractID(*(nsCID *)objPtr->internalRep.otherValuePtr, &str)) == NS_OK)
00710 {
00711
00712 }
00713 else
00714 {
00715
00716 str = ((nsID *)objPtr->internalRep.otherValuePtr)->ToString();
00717 }
00718
00719 length = strlen(str);
00720
00721 objPtr->bytes = Tcl_Alloc(length + 1);
00722 memcpy(objPtr->bytes, str, length + 1);
00723 objPtr->length = length;
00724
00725 memmgr->Free(str);
00726 }
00727
00728
00740 static int
00741 SetNsIDFromAny(
00742 Tcl_Interp *interp,
00743 Tcl_Obj *objPtr
00744 )
00745 {
00746 nsID id_stack;
00747 nsID *id;
00748 nsresult res;
00749
00750
00751 NS_PRECONDITION(objPtr, "null pointer");
00752
00753 if (id_stack.Parse(Tcl_GetString(objPtr)))
00754 {
00755
00756 id = (nsID *)CloneMemory(&id_stack, sizeof(nsID));
00757 } else if ((res = manager->GetIIDForName(Tcl_GetString(objPtr), (nsIID **)&id)) == NS_OK)
00758 {
00759
00760 } else if ((res = registrar->ContractIDToCID(Tcl_GetString(objPtr), (nsCID **)&id)) == NS_OK)
00761 {
00762
00763 } else
00764 {
00765 if (interp)
00766 {
00767 Tcl_ResetResult(interp);
00768 Tcl_AppendResult(interp, "invalid ID string \"", Tcl_GetString(objPtr), "\"", NULL);
00769 }
00770 return TCL_ERROR;
00771 }
00772
00773 if (objPtr->typePtr && objPtr->typePtr->freeIntRepProc)
00774 {
00775 objPtr->typePtr->freeIntRepProc(objPtr);
00776 }
00777 objPtr->internalRep.otherValuePtr = id;
00778 objPtr->typePtr = &NsIDType;
00779
00780 return TCL_OK;
00781 }
00782
00783
00784 #ifndef USE_TCL_WIDEINT
00785
00789 static void
00790 UpdateStringOfWideInt(
00791 Tcl_Obj *objPtr
00792 )
00793 {
00794 int length;
00795 char str[128];
00796
00797 NS_PRECONDITION(objPtr, "null pointer");
00798
00799 length = PR_snprintf(str, 128, "%lld", *(PRInt64 *)(&objPtr->internalRep));
00800
00801 objPtr->bytes = Tcl_Alloc(length + 1);
00802 memcpy(objPtr->bytes, str, length + 1);
00803 objPtr->length = length;
00804 }
00805
00806
00816 static int
00817 SetWideIntFromAny(
00818 Tcl_Interp *interp,
00819 Tcl_Obj *objPtr
00820 )
00821 {
00822 int rv;
00823 PRInt64 wideint;
00824
00825
00826 NS_PRECONDITION(objPtr, "null pointer");
00827
00828 if (PR_sscanf(Tcl_GetString(objPtr), "%lld", &wideint))
00829 {
00830 rv = TCL_OK;
00831 } else
00832 {
00833 if (interp)
00834 {
00835 Tcl_ResetResult(interp);
00836 Tcl_AppendResult(interp, "invalid 64-bit integer object \"", Tcl_GetString(objPtr), "\"", NULL);
00837 }
00838 rv = TCL_ERROR;
00839 }
00840
00841 if (rv == TCL_OK)
00842 {
00843 if (objPtr->typePtr && objPtr->typePtr->freeIntRepProc)
00844 {
00845 objPtr->typePtr->freeIntRepProc(objPtr);
00846 }
00847 *(PRInt64 *)(&objPtr->internalRep) = wideint;
00848 objPtr->typePtr = &WideIntType;
00849 }
00850
00851 return rv;
00852 }
00853
00854
00860 Tcl_Obj *
00861 TclXPCOM_NewWideIntObj(
00862 PRInt64 wideint
00863 )
00864 {
00865 Tcl_Obj *result;
00866
00867 result = Tcl_NewObj();
00868
00869 result->typePtr = &WideIntType;
00870 *(PRInt64 *)(&result->internalRep) = wideint;
00871 Tcl_InvalidateStringRep(result);
00872
00873 return result;
00874 }
00875
00876
00886 int
00887 TclXPCOM_GetWideIntFromObj(
00888 Tcl_Interp *interp,
00889 Tcl_Obj *objPtr,
00890 PRInt64 *wideint
00891 )
00892 {
00893 int rv;
00894
00895
00896 NS_PRECONDITION(objPtr, "null pointer");
00897 NS_PRECONDITION(wideint, "null pointer");
00898
00899 rv = Tcl_ConvertToType(interp, objPtr, &WideIntType);
00900
00901 if (rv == TCL_OK)
00902 {
00903 *wideint = *(PRInt64 *)(&objPtr->internalRep);
00904 }
00905
00906 return rv;
00907 }
00908
00909 #endif
00910
00911
00918 Tcl_Obj *
00919 TclXPCOM_NewISupportsObj(
00920 nsISupports *isupports,
00921 nsIInterfaceInfo *interfaceinfo
00922 )
00923 {
00924 Tcl_Obj *result;
00925 Tcl_HashEntry *entry;
00926
00927 NS_PRECONDITION(isupports, "null pointer");
00928 NS_PRECONDITION(interfaceinfo, "null pointer");
00929
00930 result = Tcl_NewObj();
00931
00932 result->typePtr = CmdNameType;
00933 result->internalRep.twoPtrValue.ptr1 = &resolvedisupports;
00934 AddRefInterface(isupports, interfaceinfo, &entry);
00935 result->internalRep.twoPtrValue.ptr2 = entry;
00936 Tcl_InvalidateStringRep(result);
00937
00938 return result;
00939 }
00940
00941
00948 Tcl_Obj *
00949 TclXPCOM_NewNsIDObj(
00950 nsID *id
00951 )
00952 {
00953 Tcl_Obj *result;
00954
00955 NS_PRECONDITION(id, "null pointer");
00956
00957 result = Tcl_NewObj();
00958
00959 result->typePtr = &NsIDType;
00960 result->internalRep.otherValuePtr = (void *)CloneMemory(id, sizeof(nsID));
00961 Tcl_InvalidateStringRep(result);
00962
00963 return result;
00964 }
00965
00966
00973 Tcl_Obj *
00974 TclXPCOM_NewIdentifierObj(
00975 nsIInterfaceInfo *interfaceinfo,
00976 char *identifier
00977 )
00978 {
00979 Tcl_Obj *result;
00980
00981 NS_PRECONDITION(interfaceinfo, "null pointer");
00982 NS_PRECONDITION(identifier, "null pointer");
00983
00984 result = Tcl_NewObj();
00985
00986 result->typePtr = &IdentifierType;
00987 result->internalRep.twoPtrValue.ptr1 = interfaceinfo;
00988 NS_ADDREF(interfaceinfo);
00989 result->internalRep.twoPtrValue.ptr2 = (char *)CloneMemory(identifier, sizeof(char) * (strlen(identifier) + 1));
00990 Tcl_InvalidateStringRep(result);
00991
00992 return result;
00993 }
00994
00995
01001 Tcl_Obj *
01002 TclXPCOM_NewPointerObj(
01003 void *ptr
01004 )
01005 {
01006 Tcl_Obj *result;
01007
01008
01009
01010 result = Tcl_NewObj();
01011
01012 result->typePtr = &PointerType;
01013 result->internalRep.twoPtrValue.ptr1 = ptr;
01014 Tcl_InvalidateStringRep(result);
01015
01016 return result;
01017 }
01018
01019
01028 int
01029 TclXPCOM_GetPointerFromObj(
01030 Tcl_Interp *interp,
01031 Tcl_Obj *objPtr,
01032 void **ptr
01033 )
01034 {
01035 int rv;
01036
01037
01038 NS_PRECONDITION(objPtr, "null pointer");
01039 NS_PRECONDITION(ptr, "null pointer");
01040
01041 rv = Tcl_ConvertToType(interp, objPtr, &PointerType);
01042
01043 if (rv == TCL_OK)
01044 {
01045 *ptr = objPtr->internalRep.twoPtrValue.ptr1;
01046 }
01047
01048 return rv;
01049 }
01050
01051
01058 int
01059 TclXPCOM_IsNULL(
01060 Tcl_Obj *objPtr
01061 )
01062 {
01063 NS_PRECONDITION(objPtr, "null pointer");
01064
01065 if ((objPtr->typePtr == &PointerType) &&
01066 (objPtr->internalRep.twoPtrValue.ptr1) == NULL)
01067 {
01068 return 1;
01069 }
01070
01071 if (!strcmp(Tcl_GetString(objPtr), NULL_STRINGREP))
01072 {
01073 return 1;
01074 }
01075
01076 return 0;
01077 }
01078
01079
01089 int
01090 TclXPCOM_GetISupportsFromObj(
01091 Tcl_Interp *interp,
01092 Tcl_Obj *objPtr,
01093 nsISupports **isupports,
01094 nsIInterfaceInfo **interfaceinfo
01095 )
01096 {
01097 int rv;
01098 Tcl_HashEntry *entry;
01099
01100
01101 NS_PRECONDITION(objPtr, "null pointer");
01102 NS_PRECONDITION(isupports, "null pointer");
01103 NS_PRECONDITION(interfaceinfo, "null pointer");
01104
01105 rv = Tcl_ConvertToType(interp, objPtr, &ISupportsType);
01106
01107 if (rv == TCL_OK)
01108 {
01109 entry = (Tcl_HashEntry *)objPtr->internalRep.twoPtrValue.ptr2;
01110
01111 *isupports = (nsISupports *)Tcl_GetHashValue(entry);
01112 *interfaceinfo = (nsIInterfaceInfo *)entry->key.oneWordValue;
01113 }
01114
01115 return rv;
01116 }
01117
01118
01129 int
01130 TclXPCOM_QueryISupportsObj(
01131 Tcl_Interp *interp,
01132 Tcl_Obj *objPtr,
01133 nsIInterfaceInfo *queryinfo,
01134 nsISupports **result
01135 )
01136 {
01137 int rv;
01138 nsISupports *isupports;
01139 nsIInterfaceInfo *interfaceinfo;
01140 InterfaceRef *iref;
01141
01142
01143 NS_PRECONDITION(objPtr, "null pointer");
01144 NS_PRECONDITION(queryinfo, "null pointer");
01145 NS_PRECONDITION(result, "null pointer");
01146
01147 rv = TclXPCOM_GetISupportsFromObj(interp, objPtr, &isupports, &interfaceinfo);
01148 if (rv != TCL_OK)
01149 {
01150 return rv;
01151 }
01152
01153 iref = GetInterfaceRef(isupports);
01154 NS_ASSERTION(iref, "isupports entry doesn't exist in irefhash");
01155
01156 rv = QueryInterfaceIRef(interp, iref, queryinfo, result);
01157 if (rv == TCL_OK)
01158 {
01159 NS_ADDREF(*result);
01160 }
01161
01162 return rv;
01163 }
01164
01165
01174 int
01175 TclXPCOM_GetIdentifierFromObj(
01176 Tcl_Interp *interp,
01177 Tcl_Obj *objPtr,
01178 nsIInterfaceInfo **interfaceinfo,
01179 char **identifier
01180 )
01181 {
01182 int rv;
01183
01184
01185 NS_PRECONDITION(objPtr, "null pointer");
01186 NS_PRECONDITION(interfaceinfo, "null pointer");
01187 NS_PRECONDITION(identifier, "null pointer");
01188
01189 rv = Tcl_ConvertToType(interp, objPtr, &IdentifierType);
01190
01191 if (rv == TCL_OK)
01192 {
01193 *interfaceinfo = (nsIInterfaceInfo *)objPtr->internalRep.twoPtrValue.ptr1;
01194 *identifier = (char *)objPtr->internalRep.twoPtrValue.ptr2;
01195 }
01196
01197 return rv;
01198 }
01199
01200
01209 int
01210 TclXPCOM_GetNsIDFromObj(
01211 Tcl_Interp *interp,
01212 Tcl_Obj *objPtr,
01213 nsID **id
01214 )
01215 {
01216 int rv;
01217
01218
01219 NS_PRECONDITION(objPtr, "null pointer");
01220 NS_PRECONDITION(id, "null pointer");
01221
01222 rv = Tcl_ConvertToType(interp, objPtr, &NsIDType);
01223
01224 if (rv == TCL_OK)
01225 {
01226 *id = (nsID *)objPtr->internalRep.otherValuePtr;
01227 }
01228
01229 return rv;
01230 }
01231
01232
01236 void
01237 TclXPCOM_RegisterObjTypes(void)
01238 {
01239 CmdNameType = Tcl_GetObjType("cmdName");
01240 SavedCmdNameType = *CmdNameType;
01241
01242 NS_ASSERTION(CmdNameType->freeIntRepProc, "no built-in UpdateStringOfCmdName exists");
01243 NS_ASSERTION(CmdNameType->dupIntRepProc, "no built-in UpdateStringOfCmdName exists");
01244 NS_ASSERTION(!CmdNameType->updateStringProc, "built-in UpdateStringOfCmdName exists");
01245 NS_ASSERTION(CmdNameType->setFromAnyProc, "no built-in UpdateStringOfCmdName exists");
01246
01247 CmdNameType->freeIntRepProc = FreeCmdNameObj;
01248 CmdNameType->dupIntRepProc = DuplicateCmdNameObj;
01249 CmdNameType->updateStringProc = UpdateStringOfCmdName;
01250 CmdNameType->setFromAnyProc = SetCmdNameFromAny;
01251
01252 ISupportsType.name = TCLXPCOM_ISUPPORTSTYPENAME;
01253 ISupportsType.freeIntRepProc = FreeISupportsObj;
01254 ISupportsType.dupIntRepProc = DuplicateISupportsObj;
01255 ISupportsType.updateStringProc = UpdateStringOfISupports;
01256 ISupportsType.setFromAnyProc = SetISupportsFromAny;
01257
01258 NsIDType.name = TCLXPCOM_NSIDTYPENAME;
01259 NsIDType.freeIntRepProc = FreeNsIDObj;
01260 NsIDType.dupIntRepProc = DuplicateNsIDObj;
01261 NsIDType.updateStringProc = UpdateStringOfNsID;
01262 NsIDType.setFromAnyProc = SetNsIDFromAny;
01263
01264 PointerType.name = TCLXPCOM_POINTERTYPENAME;
01265 PointerType.freeIntRepProc = (Tcl_FreeInternalRepProc *)NULL;
01266 PointerType.dupIntRepProc = (Tcl_DupInternalRepProc *)NULL;
01267 PointerType.updateStringProc = UpdateStringOfPointer;
01268 PointerType.setFromAnyProc = SetPointerFromAny;
01269
01270 IdentifierType.name = TCLXPCOM_IDENTIFIERTYPENAME;
01271 IdentifierType.freeIntRepProc = FreeIdentifierObj;
01272 IdentifierType.dupIntRepProc = DuplicateIdentifierObj;
01273 IdentifierType.updateStringProc = UpdateStringOfIdentifier;
01274 IdentifierType.setFromAnyProc = SetIdentifierFromAny;
01275
01276 #ifndef USE_TCL_WIDEINT
01277 WideIntType.name = TCLXPCOM_WIDEINTTYPENAME;
01278 WideIntType.freeIntRepProc = (Tcl_FreeInternalRepProc *)NULL;
01279 WideIntType.dupIntRepProc = (Tcl_DupInternalRepProc *)NULL;
01280 WideIntType.updateStringProc = UpdateStringOfWideInt;
01281 WideIntType.setFromAnyProc = SetWideIntFromAny;
01282 #endif
01283
01284 Tcl_RegisterObjType(&ISupportsType);
01285 Tcl_RegisterObjType(&NsIDType);
01286 Tcl_RegisterObjType(&PointerType);
01287 Tcl_RegisterObjType(&IdentifierType);
01288
01289 #ifndef USE_TCL_WIDEINT
01290 Tcl_RegisterObjType(&WideIntType);
01291 #endif
01292
01293 }
01294