1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsString.h"
#include "nsIDOMInstallVersion.h"
#include "nsIScriptNameSpaceManager.h"
#include "nsIComponentManager.h"
#include "nsDOMCID.h"
#include "nsSoftwareUpdateIIDs.h"
PR_STATIC_CALLBACK(JSBool)
GetInstallVersionProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
PR_STATIC_CALLBACK(JSBool)
SetInstallVersionProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
PR_STATIC_CALLBACK(JSBool)
EnumerateInstallVersion(JSContext *cx, JSObject *obj);
PR_STATIC_CALLBACK(JSBool)
ResolveInstallVersion(JSContext *cx, JSObject *obj, jsval id);
PR_STATIC_CALLBACK(void)
FinalizeInstallVersion(JSContext *cx, JSObject *obj);
/***********************************************************************/
//
// class for InstallVersion
//
JSClass InstallVersionClass = {
"InstallVersion",
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS,
JS_PropertyStub,
JS_PropertyStub,
GetInstallVersionProperty,
SetInstallVersionProperty,
EnumerateInstallVersion,
ResolveInstallVersion,
JS_ConvertStub,
FinalizeInstallVersion
};
extern void ConvertJSValToStr(nsString& aString,
JSContext* aContext,
jsval aValue);
extern void ConvertStrToJSVal(const nsString& aProp,
JSContext* aContext,
jsval* aReturn);
extern PRBool ConvertJSValToBool(PRBool* aProp,
JSContext* aContext,
jsval aValue);
extern PRBool ConvertJSValToObj(nsISupports** aSupports,
REFNSIID aIID,
JSClass* aClass,
JSContext* aContext,
jsval aValue);
void ConvertJSvalToVersionString(nsString& versionString, JSContext* cx, jsval* argument);
//
// InstallVersion property ids
//
enum InstallVersion_slots {
INSTALLVERSION_MAJOR = -1,
INSTALLVERSION_MINOR = -2,
INSTALLVERSION_RELEASE = -3,
INSTALLVERSION_BUILD = -4
};
/***********************************************************************/
//
// InstallVersion Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetInstallVersionProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMInstallVersion *a = (nsIDOMInstallVersion*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case INSTALLVERSION_MAJOR:
{
PRInt32 prop;
if (NS_OK == a->GetMajor(&prop)) {
*vp = INT_TO_JSVAL(prop);
}
else {
return JS_FALSE;
}
break;
}
case INSTALLVERSION_MINOR:
{
PRInt32 prop;
if (NS_OK == a->GetMinor(&prop)) {
*vp = INT_TO_JSVAL(prop);
}
else {
return JS_FALSE;
}
break;
}
case INSTALLVERSION_RELEASE:
{
PRInt32 prop;
if (NS_OK == a->GetRelease(&prop)) {
*vp = INT_TO_JSVAL(prop);
}
else {
return JS_FALSE;
}
break;
}
case INSTALLVERSION_BUILD:
{
PRInt32 prop;
if (NS_OK == a->GetBuild(&prop)) {
*vp = INT_TO_JSVAL(prop);
}
else {
return JS_FALSE;
}
break;
}
}
}
return JS_TRUE;
}
/***********************************************************************/
//
// InstallVersion Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetInstallVersionProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMInstallVersion *a = (nsIDOMInstallVersion*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case INSTALLVERSION_MAJOR:
{
PRInt32 prop;
int32 temp;
if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) {
prop = (PRInt32)temp;
}
else {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
a->SetMajor(prop);
break;
}
case INSTALLVERSION_MINOR:
{
PRInt32 prop;
int32 temp;
if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) {
prop = (PRInt32)temp;
}
else {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
a->SetMinor(prop);
break;
}
case INSTALLVERSION_RELEASE:
{
PRInt32 prop;
int32 temp;
if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) {
prop = (PRInt32)temp;
}
else {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
a->SetRelease(prop);
break;
}
case INSTALLVERSION_BUILD:
{
PRInt32 prop;
int32 temp;
if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) {
prop = (PRInt32)temp;
}
else {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
a->SetBuild(prop);
break;
}
}
}
return JS_TRUE;
}
//
// InstallVersion finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeInstallVersion(JSContext *cx, JSObject *obj)
{
nsISupports *nativeThis = (nsISupports*)JS_GetPrivate(cx, obj);
if (nsnull != nativeThis) {
// get the js object
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeThis->QueryInterface(NS_GET_IID(nsIScriptObjectOwner),
(void**)&owner)) {
owner->SetScriptObject(nsnull);
NS_RELEASE(owner);
}
// The addref was part of JSObject construction
NS_RELEASE(nativeThis);
}
}
//
// InstallVersion enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateInstallVersion(JSContext *cx, JSObject *obj)
{
return JS_TRUE;
}
//
// InstallVersion resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveInstallVersion(JSContext *cx, JSObject *obj, jsval id)
{
return JS_TRUE;
}
//
// Native method Init
//
PR_STATIC_CALLBACK(JSBool)
InstallVersionInit(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallVersion *nativeThis =
(nsIDOMInstallVersion*)JS_GetInstancePrivate(cx, obj, &InstallVersionClass,
argv);
if (!nativeThis)
return JS_FALSE;
nsAutoString b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc == 1)
{
JSString *jsstring;
if ((jsstring = JS_ValueToString(cx, argv[0])) != nsnull) {
b0.Assign(NS_REINTERPRET_CAST(const PRUnichar*,
JS_GetStringChars(jsstring)));
}
}
else
{
b0.AssignLiteral("0.0.0.0");
}
if (NS_OK != nativeThis->Init(b0))
return JS_FALSE;
*rval = JSVAL_VOID;
return JS_TRUE;
}
//
// Native method ToString
//
PR_STATIC_CALLBACK(JSBool)
InstallVersionToString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallVersion *nativeThis =
(nsIDOMInstallVersion*)JS_GetInstancePrivate(cx, obj, &InstallVersionClass,
argv);
if (!nativeThis)
return JS_FALSE;
nsAutoString nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (NS_OK != nativeThis->ToString(nativeRet)) {
return JS_TRUE;
}
JSString *jsstring =
JS_NewUCStringCopyN(cx, NS_REINTERPRET_CAST(const jschar*,
nativeRet.get()),
nativeRet.Length());
// set the return value
*rval = STRING_TO_JSVAL(jsstring);
return JS_TRUE;
}
//
// Native method CompareTo
//
PR_STATIC_CALLBACK(JSBool)
InstallVersionCompareTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallVersion *nativeThis =
(nsIDOMInstallVersion*)JS_GetInstancePrivate(cx, obj, &InstallVersionClass,
argv);
if (!nativeThis)
return JS_FALSE;
PRInt32 nativeRet;
nsString b0str;
PRInt32 b0int;
PRInt32 b1int;
PRInt32 b2int;
PRInt32 b3int;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if(argc >= 4)
{
// public int CompareTo(int major,
// int minor,
// int release,
// int build);
if(!JSVAL_IS_INT(argv[0]))
{
JS_ReportError(cx, "1st parameter must be a number");
return JS_FALSE;
}
else if(!JSVAL_IS_INT(argv[1]))
{
JS_ReportError(cx, "2nd parameter must be a number");
return JS_FALSE;
}
else if(!JSVAL_IS_INT(argv[2]))
{
JS_ReportError(cx, "3rd parameter must be a number");
return JS_FALSE;
}
else if(!JSVAL_IS_INT(argv[3]))
{
JS_ReportError(cx, "4th parameter must be a number");
return JS_FALSE;
}
b0int = JSVAL_TO_INT(argv[0]);
b1int = JSVAL_TO_INT(argv[1]);
b2int = JSVAL_TO_INT(argv[2]);
b3int = JSVAL_TO_INT(argv[3]);
if(NS_OK != nativeThis->CompareTo(b0int, b1int, b2int, b3int, &nativeRet))
{
return JS_FALSE;
}
*rval = INT_TO_JSVAL(nativeRet);
}
else if(argc >= 1)
{
// public int AddDirectory(String version); --OR-- VersionInfo version
if(JSVAL_IS_OBJECT(argv[0]))
{
nsCOMPtr<nsIDOMInstallVersion> versionObj;
if(JS_FALSE == ConvertJSValToObj(getter_AddRefs(versionObj),
NS_GET_IID(nsIDOMInstallVersion),
&InstallVersionClass,
cx,
argv[0]))
{
return JS_FALSE;
}
if (!versionObj)
{
JS_ReportError(cx, "Function compareTo expects a non null object.");
return JS_FALSE;
}
if(NS_OK != nativeThis->CompareTo(versionObj, &nativeRet))
{
return JS_FALSE;
}
}
else
{
ConvertJSValToStr(b0str, cx, argv[0]);
if(NS_OK != nativeThis->CompareTo(b0str, &nativeRet))
{
return JS_FALSE;
}
}
*rval = INT_TO_JSVAL(nativeRet);
}
else
{
JS_ReportError(cx, "Function compareTo requires 4 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// InstallVersion class properties
//
static JSPropertySpec InstallVersionProperties[] =
{
{"major", INSTALLVERSION_MAJOR, JSPROP_ENUMERATE},
{"minor", INSTALLVERSION_MINOR, JSPROP_ENUMERATE},
{"release", INSTALLVERSION_RELEASE, JSPROP_ENUMERATE},
{"build", INSTALLVERSION_BUILD, JSPROP_ENUMERATE},
{0}
};
//
// InstallVersion class methods
//
static JSFunctionSpec InstallVersionMethods[] =
{
{"init", InstallVersionInit, 1},
{"toString", InstallVersionToString, 0},
{"compareTo", InstallVersionCompareTo, 1},
{0}
};
static JSConstDoubleSpec version_constants[] =
{
{ nsIDOMInstallVersion::EQUAL, "EQUAL" },
{ nsIDOMInstallVersion::BLD_DIFF, "BLD_DIFF" },
{ nsIDOMInstallVersion::BLD_DIFF_MINUS, "BLD_DIFF_MINUS" },
{ nsIDOMInstallVersion::REL_DIFF, "REL_DIFF" },
{ nsIDOMInstallVersion::REL_DIFF_MINUS, "REL_DIFF_MINUS" },
{ nsIDOMInstallVersion::MINOR_DIFF, "MINOR_DIFF" },
{ nsIDOMInstallVersion::MINOR_DIFF_MINUS, "MINOR_DIFF_MINUS" },
{ nsIDOMInstallVersion::MAJOR_DIFF, "MAJOR_DIFF" },
{ nsIDOMInstallVersion::MAJOR_DIFF_MINUS, "MAJOR_DIFF_MINUS" },
{0}
};
//
// InstallVersion constructor
//
PR_STATIC_CALLBACK(JSBool)
InstallVersion(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsresult result;
nsIDOMInstallVersion *nativeThis;
nsIScriptObjectOwner *owner = nsnull;
static NS_DEFINE_IID(kInstallVersion_CID, NS_SoftwareUpdateInstallVersion_CID);
result = CallCreateInstance(kInstallVersion_CID, &nativeThis);
if (NS_FAILED(result)) return JS_FALSE;
result = nativeThis->QueryInterface(NS_GET_IID(nsIScriptObjectOwner),
(void **)&owner);
if (NS_FAILED(result)) {
NS_RELEASE(nativeThis);
return JS_FALSE;
}
owner->SetScriptObject((void *)obj);
JS_SetPrivate(cx, obj, nativeThis);
NS_RELEASE(owner);
jsval ignore;
InstallVersionInit(cx, obj, argc, argv, &ignore);
return JS_TRUE;
}
nsresult InitInstallVersionClass(JSContext *jscontext, JSObject *global, void** prototype)
{
JSObject *proto = nsnull;
if (prototype != nsnull)
*prototype = nsnull;
proto = JS_InitClass(jscontext, // context
global, // global object
nsnull, // parent proto
&InstallVersionClass, // JSClass
InstallVersion, // JSNative ctor
0, // ctor args
InstallVersionProperties, // proto props
InstallVersionMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto)
return NS_ERROR_FAILURE;
if ( PR_FALSE == JS_DefineConstDoubles(jscontext, proto, version_constants) )
return NS_ERROR_FAILURE;
if (prototype != nsnull)
*prototype = proto;
return NS_OK;
}
//
// InstallVersion class initialization
//
nsresult NS_InitInstallVersionClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "InstallVersion", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp))
{
nsresult rv = InitInstallVersionClass(jscontext, global, (void**)&proto);
if (NS_FAILED(rv)) return rv;
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp))
{
proto = JSVAL_TO_OBJECT(vp);
}
else
{
return NS_ERROR_FAILURE;
}
if (aPrototype)
*aPrototype = proto;
return NS_OK;
}
//
// Method for creating a new InstallVersion JavaScript object
//
nsresult
NS_NewScriptInstallVersion(nsIScriptContext *aContext, nsISupports *aSupports,
nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports &&
nsnull != aReturn,
"null argument to NS_NewScriptInstallVersion");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
nsresult result = NS_OK;
nsIDOMInstallVersion *installVersion;
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(NS_GET_IID(nsIScriptObjectOwner),
(void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitInstallVersionClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
result = aSupports->QueryInterface(NS_GET_IID(nsIDOMInstallVersion), (void **)&installVersion);
if (NS_OK != result) {
return result;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &InstallVersionClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, installVersion);
}
else {
NS_RELEASE(installVersion);
return NS_ERROR_FAILURE;
}
return NS_OK;
}
|