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
00049 void *
00050 CloneMemory(
00051 void *ptr,
00052 size_t size
00053 )
00054 {
00055 void *result;
00056
00057 result = memmgr->Alloc(size);
00058 memcpy(result, ptr, size);
00059
00060 return result;
00061 }
00062
00063
00074 int
00075 TclXPCOM_CheckInterfaceIsReflectable(
00076 Tcl_Interp *interp,
00077 nsIInterfaceInfo *interfaceinfo,
00078 int flags
00079 )
00080 {
00081 PRBool scriptable;
00082 const char *name;
00083
00084 NS_PRECONDITION(interp, "null pointer");
00085 NS_PRECONDITION(interfaceinfo, "null pointer");
00086 NS_PRECONDITION(!(flags & ~(FORCE_HIDDEN | FORCE_NOTXPCOM | FORCE_NOTSCRIPTABLE)), "invalid flags");
00087
00088 if (!(flags & FORCE_NOTSCRIPTABLE))
00089 {
00090 interfaceinfo->IsScriptable(&scriptable);
00091 if (!scriptable)
00092 {
00093 interfaceinfo->GetNameShared(&name);
00094 Tcl_ResetResult(interp);
00095 Tcl_AppendResult(interp, "interface \"", name, "\" is not scriptable", NULL);
00096 return TCL_ERROR;
00097 }
00098 }
00099 return TCL_OK;
00100 }
00101
00102
00114 int
00115 TclXPCOM_CheckMethodIsReflectable(
00116 Tcl_Interp *interp,
00117 nsIInterfaceInfo *interfaceinfo,
00118 PRUint16 methodindex,
00119 int flags
00120 )
00121 {
00122 const char *name;
00123 const nsXPTMethodInfo *methodinfo;
00124
00125 NS_PRECONDITION(interp, "null pointer");
00126 NS_PRECONDITION(interfaceinfo, "null pointer");
00127 NS_PRECONDITION(!(flags & ~(FORCE_HIDDEN | FORCE_NOTXPCOM | FORCE_NOTSCRIPTABLE)), "invalid flags");
00128
00129 interfaceinfo->GetMethodInfo(methodindex, &methodinfo);
00130
00131 if (methodinfo->IsNotXPCOM() && !(flags & FORCE_NOTXPCOM))
00132 {
00133 name = methodinfo->GetName();
00134 Tcl_ResetResult(interp);
00135 Tcl_AppendResult(interp, "\"", name, "\" is not an XPCOM method", NULL);
00136 return TCL_ERROR;
00137 }
00138
00139 if (!(flags & FORCE_HIDDEN) && methodinfo->IsHidden())
00140 {
00141 name = methodinfo->GetName();
00142 Tcl_ResetResult(interp);
00143 Tcl_AppendResult(interp, "\"", name, "\" is a hidden method", NULL);
00144 return TCL_ERROR;
00145 }
00146
00147 return TCL_OK;
00148 }
00149
00150
00159 int
00160 isInInterface(
00161 nsIInterfaceInfo *interfaceinfo,
00162 nsIID *iid
00163 )
00164 {
00165 PRBool isiid;
00166 PRBool hasancestor;
00167
00168 NS_PRECONDITION(interfaceinfo, "null pointer");
00169 NS_PRECONDITION(iid, "null pointer");
00170
00171 interfaceinfo->IsIID(iid, &isiid);
00172 interfaceinfo->HasAncestor(iid, &hasancestor);
00173
00174 if (isiid || hasancestor)
00175 {
00176 return 1;
00177 }
00178
00179 return 0;
00180 }
00181
00182
00188 Tcl_Obj *
00189 TclXPCOM_ListInterfaceConstants(
00190 nsIInterfaceInfo *interfaceinfo
00191 )
00192 {
00193 PRUint16 i;
00194 Tcl_Obj *result;
00195 InterfaceInfo *iinfo;
00196
00197 NS_PRECONDITION(interfaceinfo, "null pointer");
00198
00199 iinfo = GetInterfaceInfo(interfaceinfo);
00200
00201 result = Tcl_NewListObj(0, NULL);
00202 for (i = 0; i < iinfo->constantcount; i++)
00203 {
00204 Tcl_ListObjAppendElement(NULL, result, Tcl_NewStringObj(iinfo->constantnames[i], -1));
00205 }
00206
00207 return result;
00208 }
00209
00210
00216 Tcl_Obj *
00217 TclXPCOM_ListInterfaceAttributes(
00218 nsIInterfaceInfo *interfaceinfo
00219 )
00220 {
00221 PRUint16 i;
00222 Tcl_Obj *result;
00223 InterfaceInfo *iinfo;
00224
00225 NS_PRECONDITION(interfaceinfo, "null pointer");
00226
00227 iinfo = GetInterfaceInfo(interfaceinfo);
00228
00229 result = Tcl_NewListObj(0, NULL);
00230 for (i = 0; i < iinfo->attributecount; i++)
00231 {
00232 Tcl_ListObjAppendElement(NULL, result, Tcl_NewStringObj(iinfo->attributes[i].name, -1));
00233 }
00234
00235 return result;
00236 }
00237
00238
00244 Tcl_Obj *
00245 TclXPCOM_ListInterfaceMethods(
00246 nsIInterfaceInfo *interfaceinfo
00247 )
00248 {
00249 PRUint16 i;
00250 Tcl_Obj *result;
00251 InterfaceInfo *iinfo;
00252
00253 NS_PRECONDITION(interfaceinfo, "null pointer");
00254
00255 iinfo = GetInterfaceInfo(interfaceinfo);
00256
00257 result = Tcl_NewListObj(0, NULL);
00258 for (i = 0; i < iinfo->methodcount; i++)
00259 {
00260 Tcl_ListObjAppendElement(NULL, result, Tcl_NewStringObj(iinfo->methods[i].name, -1));
00261 }
00262
00263 return result;
00264 }
00265
00266
00274 Tcl_Obj *
00275 TclXPCOM_ListClassMethods(
00276 ClassInfo *cinfo
00277 )
00278 {
00279 PRUint16 i;
00280 Tcl_Obj *result;
00281
00282 NS_PRECONDITION(cinfo, "null pointer");
00283
00284 result = Tcl_NewListObj(0, NULL);
00285 for (i = 0; i < cinfo->methodcount; i++)
00286 {
00287 Tcl_ListObjAppendElement(NULL, result, Tcl_NewStringObj(cinfo->methods[i].idinfo.name, -1));
00288 }
00289
00290 return result;
00291 }
00292
00293
00301 Tcl_Obj *
00302 TclXPCOM_ListClassAttributes(
00303 ClassInfo *cinfo
00304 )
00305 {
00306 PRUint16 i;
00307 Tcl_Obj *result;
00308
00309 NS_PRECONDITION(cinfo, "null pointer");
00310
00311 result = Tcl_NewListObj(0, NULL);
00312 for (i = 0; i < cinfo->attributecount; i++)
00313 {
00314 Tcl_ListObjAppendElement(NULL, result, Tcl_NewStringObj(cinfo->attributes[i].idinfo.name, -1));
00315 }
00316
00317 return result;
00318 }
00319
00320
00330 Tcl_Obj *
00331 GetType(
00332 nsIInterfaceInfo *interfaceinfo,
00333 PRUint16 methodindex,
00334 nsXPTParamInfo *paraminfo,
00335 nsXPTType type
00336 )
00337 {
00338 nsXPTType arraytype;
00339 nsIInterfaceInfo *info;
00340 const char *name;
00341 Tcl_Obj *result;
00342 nsresult res;
00343 const nsXPTMethodInfo *methodinfo;
00344 char str[128];
00345
00346 NS_PRECONDITION(interfaceinfo, "null pointer");
00347 NS_PRECONDITION(paraminfo, "null pointer");
00348
00349
00350 switch (type.TagPart())
00351 {
00352 case nsXPTType::T_I8:
00353 result = Tcl_NewStringObj("int8", -1);
00354 break;
00355 case nsXPTType::T_I16:
00356 result = Tcl_NewStringObj("int16", -1);
00357 break;
00358 case nsXPTType::T_I32:
00359 result = Tcl_NewStringObj("int32", -1);
00360 break;
00361 case nsXPTType::T_I64:
00362 result = Tcl_NewStringObj("int64", -1);
00363 break;
00364 case nsXPTType::T_U8:
00365 result = Tcl_NewStringObj("uint8", -1);
00366 break;
00367 case nsXPTType::T_U16:
00368 result = Tcl_NewStringObj("uint16", -1);
00369 break;
00370 case nsXPTType::T_U32:
00371 result = Tcl_NewStringObj("uint32", -1);
00372 break;
00373 case nsXPTType::T_U64:
00374 result = Tcl_NewStringObj("uint64", -1);
00375 break;
00376 case nsXPTType::T_FLOAT:
00377 result = Tcl_NewStringObj("float", -1);
00378 break;
00379 case nsXPTType::T_DOUBLE:
00380 result = Tcl_NewStringObj("double", -1);
00381 break;
00382 case nsXPTType::T_BOOL:
00383 result = Tcl_NewStringObj("boolean", -1);
00384 break;
00385 case nsXPTType::T_CHAR:
00386 result = Tcl_NewStringObj("char", -1);
00387 break;
00388 case nsXPTType::T_WCHAR:
00389 result = Tcl_NewStringObj("wchar", -1);
00390 break;
00391 case nsXPTType::T_VOID:
00392 if (type.IsPointer())
00393 {
00394 result = Tcl_NewStringObj("pointer", -1);
00395 } else
00396 {
00397 result = Tcl_NewStringObj("void", -1);
00398 }
00399 break;
00400 case nsXPTType::T_IID:
00401 result = Tcl_NewStringObj("interface", -1);
00402 break;
00403
00404 case nsXPTType::T_ASTRING:
00405 case nsXPTType::T_DOMSTRING:
00406 case nsXPTType::T_UTF8STRING:
00407 case nsXPTType::T_WCHAR_STR:
00408 case nsXPTType::T_PWSTRING_SIZE_IS:
00409 result = Tcl_NewStringObj("wstring", -1);
00410 break;
00411
00412 case nsXPTType::T_CSTRING:
00413 case nsXPTType::T_CHAR_STR:
00414 case nsXPTType::T_PSTRING_SIZE_IS:
00415 result = Tcl_NewStringObj("string", -1);
00416 break;
00417
00418 case nsXPTType::T_INTERFACE:
00419 res = interfaceinfo->GetInfoForParam(methodindex, paraminfo, &info);
00420 if (NS_SUCCEEDED(res))
00421 {
00422 info->GetNameShared(&name);
00423 result = Tcl_NewStringObj(name, -1);
00424 NS_RELEASE(info);
00425 } else {
00426 interfaceinfo->GetMethodInfo(methodindex, &methodinfo);
00427 interfaceinfo->GetNameShared(&name);
00428 sprintf(str, "GetInfoForParam Failed: Interface %s Method %s", name, methodinfo->GetName());
00429 NS_WARNING(str);
00430
00431 result = Tcl_NewStringObj("nsISupports", -1);
00432 }
00433 break;
00434
00435 case nsXPTType::T_INTERFACE_IS:
00436 result = Tcl_NewStringObj("nsISupports", -1);
00437 break;
00438
00439 case nsXPTType::T_ARRAY:
00440 interfaceinfo->GetTypeForParam(methodindex, paraminfo, 1, &arraytype);
00441 result = Tcl_NewListObj(0, NULL);
00442 Tcl_ListObjAppendElement(NULL, result, Tcl_NewStringObj("list", -1));
00443 Tcl_ListObjAppendElement(NULL, result, GetType(interfaceinfo, methodindex, paraminfo, arraytype));
00444 break;
00445
00446 default:
00447 NS_ERROR("invalid type");
00448 break;
00449 }
00450
00451 return result;
00452 }
00453
00454
00464 Tcl_Obj *
00465 GetParam(
00466 nsIInterfaceInfo *interfaceinfo,
00467 PRUint16 methodindex,
00468 nsXPTParamInfo *paraminfo
00469 )
00470 {
00471 Tcl_Obj *result, *direction;
00472
00473 NS_PRECONDITION(interfaceinfo, "null pointer");
00474 NS_PRECONDITION(paraminfo, "null pointer");
00475
00476 result = Tcl_NewListObj(0, NULL);
00477
00478 if (paraminfo->IsIn() && !paraminfo->IsDipper())
00479 {
00480 if (paraminfo->IsOut())
00481 {
00482 direction = Tcl_NewStringObj("inout", -1);
00483 } else
00484 {
00485 direction = Tcl_NewStringObj("in", -1);
00486 }
00487 } else
00488 {
00489 direction = Tcl_NewStringObj("out", -1);
00490 }
00491
00492 Tcl_ListObjAppendElement(NULL, result, direction);
00493 Tcl_ListObjAppendElement(NULL, result, GetType(interfaceinfo, methodindex, paraminfo, paraminfo->GetType()));
00494
00495 return result;
00496 }
00497
00498
00505 Tcl_Obj *
00506 TclXPCOM_ListMethodArguments(
00507 nsIInterfaceInfo *interfaceinfo,
00508 PRUint16 methodindex
00509 )
00510 {
00511 PRUint8 i;
00512 Tcl_Obj *result;
00513 MethodInfo *minfo;
00514 PRUint16 *tclparams;
00515
00516 NS_PRECONDITION(interfaceinfo, "null pointer");
00517
00518 minfo = GetMethodInfo(interfaceinfo, methodindex);
00519 tclparams = minfo->tclparams;
00520
00521 result = Tcl_NewListObj(0, NULL);
00522
00523 for (i = 0; i < minfo->paramcount; i++)
00524 {
00525 if ((tclparams[i] & PARAM_IS_SKIPPED) ||
00526 (tclparams[i] & PARAM_IS_RETVAL))
00527 {
00528 continue;
00529 }
00530
00531 Tcl_ListObjAppendElement(NULL, result, GetParam(interfaceinfo, methodindex, &minfo->paraminfos[i]));
00532 }
00533
00534 return result;
00535 }
00536
00537
00544 Tcl_Obj *
00545 TclXPCOM_GetReturnValueType(
00546 nsIInterfaceInfo *interfaceinfo,
00547 IdentifierInfo *idinfo
00548 )
00549 {
00550 PRUint8 i;
00551 PRUint16 methodindex;
00552 MethodInfo *minfo;
00553 PRUint16 *tclparams;
00554
00555 NS_PRECONDITION(interfaceinfo, "null pointer");
00556 NS_PRECONDITION(idinfo, "null pointer");
00557
00558 methodindex = idinfo->indices.methodindex;
00559
00560 minfo = GetMethodInfo(interfaceinfo, methodindex);
00561 tclparams = minfo->tclparams;
00562
00563 for (i = 0; i < minfo->paramcount; i++)
00564 {
00565 if (tclparams[i] & PARAM_IS_RETVAL)
00566 {
00567 return GetType(interfaceinfo, methodindex, &minfo->paraminfos[i], minfo->paraminfos[i].GetType());
00568 }
00569 }
00570
00571 return Tcl_NewObj();
00572 }
00573
00574
00581 Tcl_Obj *
00582 TclXPCOM_GetAttributeType(
00583 nsIInterfaceInfo *interfaceinfo,
00584 IdentifierInfo *idinfo
00585 )
00586 {
00587 PRUint16 methodindex;
00588 MethodInfo *minfo;
00589 PRUint16 *tclparams;
00590
00591 NS_PRECONDITION(interfaceinfo, "null pointer");
00592 NS_PRECONDITION(idinfo, "null pointer");
00593
00594 if (idinfo->type & INTERFACEINFO_GETTER)
00595 {
00596 methodindex = idinfo->indices.attributeindices.getterindex;
00597 } else
00598 {
00599 methodindex = idinfo->indices.attributeindices.setterindex;
00600 }
00601
00602 minfo = GetMethodInfo(interfaceinfo, methodindex);
00603 tclparams = minfo->tclparams;
00604
00605 return GetType(interfaceinfo, methodindex, &minfo->paraminfos[0], minfo->paraminfos[0].GetType());
00606 }