001package Torello.Browser; 002 003import java.util.*; 004import javax.json.*; 005import javax.json.stream.*; 006import java.io.*; 007 008import java.lang.reflect.Method; 009import java.lang.reflect.Parameter; 010import java.util.function.Function; 011 012import Torello.Java.Additional.*; 013import Torello.Java.JSON.*; 014 015import static Torello.Java.JSON.JFlag.*; 016 017import Torello.Java.StrCmpr; 018import Torello.JavaDoc.StaticFunctional; 019import Torello.JavaDoc.JDHeaderBackgroundImg; 020import Torello.JavaDoc.Excuse; 021 022/** 023 * <SPAN CLASS=COPIEDJDK><B>The SystemInfo domain defines methods and events for querying low-level system information.</B></SPAN> 024 * 025 * <EMBED CLASS='external-html' DATA-FILE-ID=CODE_GEN_NOTE> 026 */ 027@StaticFunctional(Excused={"counter"}, Excuses={Excuse.CONFIGURATION}) 028@JDHeaderBackgroundImg(EmbedTagFileID="WOOD_PLANK_NOTE") 029public class SystemInfo 030{ 031 // ******************************************************************************************** 032 // ******************************************************************************************** 033 // Class Header Stuff 034 // ******************************************************************************************** 035 // ******************************************************************************************** 036 037 038 // No Pubic Constructors 039 private SystemInfo () { } 040 041 // These two Vector's are used by all the "Methods" exported by this class. java.lang.reflect 042 // is used to generate the JSON String's. It saves thousands of lines of Auto-Generated Code. 043 private static final Map<String, Vector<String>> parameterNames = new HashMap<>(); 044 private static final Map<String, Vector<Class<?>>> parameterTypes = new HashMap<>(); 045 046 // Some Methods do not take any parameters - for instance all the "enable()" and "disable()" 047 // I simply could not get ride of RAW-TYPES and UNCHECKED warnings... so there are now, 048 // offically, two empty-vectors. One for String's, and the other for Classes. 049 050 private static final Vector<String> EMPTY_VEC_STR = new Vector<>(); 051 private static final Vector<Class<?>> EMPTY_VEC_CLASS = new Vector<>(); 052 053 static 054 { 055 for (Method m : SystemInfo.class.getMethods()) 056 { 057 // This doesn't work! The parameter names are all "arg0" ... "argN" 058 // It works for java.lang.reflect.Field, BUT NOT java.lang.reflect.Parameter! 059 // 060 // Vector<String> parameterNamesList = new Vector<>(); -- NOPE! 061 062 Vector<Class<?>> parameterTypesList = new Vector<>(); 063 064 for (Parameter p : m.getParameters()) parameterTypesList.add(p.getType()); 065 066 parameterTypes.put( 067 m.getName(), 068 (parameterTypesList.size() > 0) ? parameterTypesList : EMPTY_VEC_CLASS 069 ); 070 } 071 } 072 073 static 074 { 075 Vector<String> v = null; 076 077 parameterNames.put("getInfo", EMPTY_VEC_STR); 078 079 parameterNames.put("getProcessInfo", EMPTY_VEC_STR); 080 } 081 082 083 // ******************************************************************************************** 084 // ******************************************************************************************** 085 // Types - Static Inner Classes 086 // ******************************************************************************************** 087 // ******************************************************************************************** 088 089 /** YUV subsampling type of the pixels of a given image. */ 090 public static final String[] SubsamplingFormat = 091 { "yuv420", "yuv422", "yuv444", }; 092 093 /** Image format of a given image. */ 094 public static final String[] ImageType = 095 { "jpeg", "webp", "unknown", }; 096 097 /** Describes a single graphics processor (GPU). */ 098 public static class GPUDevice 099 extends BaseType 100 implements java.io.Serializable 101 { 102 /** For Object Serialization. java.io.Serializable */ 103 protected static final long serialVersionUID = 1; 104 105 public boolean[] optionals() 106 { return new boolean[] { false, false, true, true, false, false, false, false, }; } 107 108 /** PCI ID of the GPU vendor, if available; 0 otherwise. */ 109 public final Number vendorId; 110 111 /** PCI ID of the GPU device, if available; 0 otherwise. */ 112 public final Number deviceId; 113 114 /** 115 * Sub sys ID of the GPU, only available on Windows. 116 * <BR /> 117 * <BR /><B>OPTIONAL</B> 118 */ 119 public final Number subSysId; 120 121 /** 122 * Revision of the GPU, only available on Windows. 123 * <BR /> 124 * <BR /><B>OPTIONAL</B> 125 */ 126 public final Number revision; 127 128 /** String description of the GPU vendor, if the PCI ID is not available. */ 129 public final String vendorString; 130 131 /** String description of the GPU device, if the PCI ID is not available. */ 132 public final String deviceString; 133 134 /** String description of the GPU driver vendor. */ 135 public final String driverVendor; 136 137 /** String description of the GPU driver version. */ 138 public final String driverVersion; 139 140 /** 141 * Constructor 142 * 143 * @param vendorId PCI ID of the GPU vendor, if available; 0 otherwise. 144 * 145 * @param deviceId PCI ID of the GPU device, if available; 0 otherwise. 146 * 147 * @param subSysId Sub sys ID of the GPU, only available on Windows. 148 * <BR /><B>OPTIONAL</B> 149 * 150 * @param revision Revision of the GPU, only available on Windows. 151 * <BR /><B>OPTIONAL</B> 152 * 153 * @param vendorString String description of the GPU vendor, if the PCI ID is not available. 154 * 155 * @param deviceString String description of the GPU device, if the PCI ID is not available. 156 * 157 * @param driverVendor String description of the GPU driver vendor. 158 * 159 * @param driverVersion String description of the GPU driver version. 160 */ 161 public GPUDevice( 162 Number vendorId, Number deviceId, Number subSysId, Number revision, 163 String vendorString, String deviceString, String driverVendor, String driverVersion 164 ) 165 { 166 // Exception-Check(s) to ensure that if any parameters which are not declared as 167 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 168 169 if (vendorId == null) BRDPC.throwNPE("vendorId"); 170 if (deviceId == null) BRDPC.throwNPE("deviceId"); 171 if (vendorString == null) BRDPC.throwNPE("vendorString"); 172 if (deviceString == null) BRDPC.throwNPE("deviceString"); 173 if (driverVendor == null) BRDPC.throwNPE("driverVendor"); 174 if (driverVersion == null) BRDPC.throwNPE("driverVersion"); 175 176 this.vendorId = vendorId; 177 this.deviceId = deviceId; 178 this.subSysId = subSysId; 179 this.revision = revision; 180 this.vendorString = vendorString; 181 this.deviceString = deviceString; 182 this.driverVendor = driverVendor; 183 this.driverVersion = driverVersion; 184 } 185 186 /** 187 * JSON Object Constructor 188 * @param jo A Json-Object having data about an instance of {@code 'GPUDevice'}. 189 */ 190 public GPUDevice (JsonObject jo) 191 { 192 this.vendorId = ReadNumberJSON.get(jo, "vendorId", false, true); 193 this.deviceId = ReadNumberJSON.get(jo, "deviceId", false, true); 194 this.subSysId = ReadNumberJSON.get(jo, "subSysId", true, false); 195 this.revision = ReadNumberJSON.get(jo, "revision", true, false); 196 this.vendorString = ReadJSON.getString(jo, "vendorString", false, true); 197 this.deviceString = ReadJSON.getString(jo, "deviceString", false, true); 198 this.driverVendor = ReadJSON.getString(jo, "driverVendor", false, true); 199 this.driverVersion = ReadJSON.getString(jo, "driverVersion", false, true); 200 } 201 202 203 /** Checks whether {@code 'this'} equals an input Java-{@code Object} */ 204 public boolean equals(Object other) 205 { 206 if (other == null) return false; 207 if (other.getClass() != this.getClass()) return false; 208 209 GPUDevice o = (GPUDevice) other; 210 211 return 212 Objects.equals(this.vendorId, o.vendorId) 213 && Objects.equals(this.deviceId, o.deviceId) 214 && Objects.equals(this.subSysId, o.subSysId) 215 && Objects.equals(this.revision, o.revision) 216 && Objects.equals(this.vendorString, o.vendorString) 217 && Objects.equals(this.deviceString, o.deviceString) 218 && Objects.equals(this.driverVendor, o.driverVendor) 219 && Objects.equals(this.driverVersion, o.driverVersion); 220 } 221 222 /** Generates a Hash-Code for {@code 'this'} instance */ 223 public int hashCode() 224 { 225 return 226 Objects.hashCode(this.vendorId) 227 + Objects.hashCode(this.deviceId) 228 + Objects.hashCode(this.subSysId) 229 + Objects.hashCode(this.revision) 230 + Objects.hashCode(this.vendorString) 231 + Objects.hashCode(this.deviceString) 232 + Objects.hashCode(this.driverVendor) 233 + Objects.hashCode(this.driverVersion); 234 } 235 } 236 237 /** Describes the width and height dimensions of an entity. */ 238 public static class Size 239 extends BaseType 240 implements java.io.Serializable 241 { 242 /** For Object Serialization. java.io.Serializable */ 243 protected static final long serialVersionUID = 1; 244 245 public boolean[] optionals() 246 { return new boolean[] { false, false, }; } 247 248 /** Width in pixels. */ 249 public final int width; 250 251 /** Height in pixels. */ 252 public final int height; 253 254 /** 255 * Constructor 256 * 257 * @param width Width in pixels. 258 * 259 * @param height Height in pixels. 260 */ 261 public Size(int width, int height) 262 { 263 this.width = width; 264 this.height = height; 265 } 266 267 /** 268 * JSON Object Constructor 269 * @param jo A Json-Object having data about an instance of {@code 'Size'}. 270 */ 271 public Size (JsonObject jo) 272 { 273 this.width = ReadPrimJSON.getInt(jo, "width"); 274 this.height = ReadPrimJSON.getInt(jo, "height"); 275 } 276 277 278 /** Checks whether {@code 'this'} equals an input Java-{@code Object} */ 279 public boolean equals(Object other) 280 { 281 if (other == null) return false; 282 if (other.getClass() != this.getClass()) return false; 283 284 Size o = (Size) other; 285 286 return 287 (this.width == o.width) 288 && (this.height == o.height); 289 } 290 291 /** Generates a Hash-Code for {@code 'this'} instance */ 292 public int hashCode() 293 { 294 return 295 this.width 296 + this.height; 297 } 298 } 299 300 /** 301 * Describes a supported video decoding profile with its associated minimum and 302 * maximum resolutions. 303 */ 304 public static class VideoDecodeAcceleratorCapability 305 extends BaseType 306 implements java.io.Serializable 307 { 308 /** For Object Serialization. java.io.Serializable */ 309 protected static final long serialVersionUID = 1; 310 311 public boolean[] optionals() 312 { return new boolean[] { false, false, false, }; } 313 314 /** Video codec profile that is supported, e.g. VP9 Profile 2. */ 315 public final String profile; 316 317 /** Maximum video dimensions in pixels supported for this |profile|. */ 318 public final SystemInfo.Size maxResolution; 319 320 /** Minimum video dimensions in pixels supported for this |profile|. */ 321 public final SystemInfo.Size minResolution; 322 323 /** 324 * Constructor 325 * 326 * @param profile Video codec profile that is supported, e.g. VP9 Profile 2. 327 * 328 * @param maxResolution Maximum video dimensions in pixels supported for this |profile|. 329 * 330 * @param minResolution Minimum video dimensions in pixels supported for this |profile|. 331 */ 332 public VideoDecodeAcceleratorCapability 333 (String profile, SystemInfo.Size maxResolution, SystemInfo.Size minResolution) 334 { 335 // Exception-Check(s) to ensure that if any parameters which are not declared as 336 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 337 338 if (profile == null) BRDPC.throwNPE("profile"); 339 if (maxResolution == null) BRDPC.throwNPE("maxResolution"); 340 if (minResolution == null) BRDPC.throwNPE("minResolution"); 341 342 this.profile = profile; 343 this.maxResolution = maxResolution; 344 this.minResolution = minResolution; 345 } 346 347 /** 348 * JSON Object Constructor 349 * @param jo A Json-Object having data about an instance of {@code 'VideoDecodeAcceleratorCapability'}. 350 */ 351 public VideoDecodeAcceleratorCapability (JsonObject jo) 352 { 353 this.profile = ReadJSON.getString(jo, "profile", false, true); 354 this.maxResolution = ReadJSON.getObject(jo, "maxResolution", SystemInfo.Size.class, false, true); 355 this.minResolution = ReadJSON.getObject(jo, "minResolution", SystemInfo.Size.class, false, true); 356 } 357 358 359 /** Checks whether {@code 'this'} equals an input Java-{@code Object} */ 360 public boolean equals(Object other) 361 { 362 if (other == null) return false; 363 if (other.getClass() != this.getClass()) return false; 364 365 VideoDecodeAcceleratorCapability o = (VideoDecodeAcceleratorCapability) other; 366 367 return 368 Objects.equals(this.profile, o.profile) 369 && Objects.equals(this.maxResolution, o.maxResolution) 370 && Objects.equals(this.minResolution, o.minResolution); 371 } 372 373 /** Generates a Hash-Code for {@code 'this'} instance */ 374 public int hashCode() 375 { 376 return 377 Objects.hashCode(this.profile) 378 + this.maxResolution.hashCode() 379 + this.minResolution.hashCode(); 380 } 381 } 382 383 /** 384 * Describes a supported video encoding profile with its associated maximum 385 * resolution and maximum framerate. 386 */ 387 public static class VideoEncodeAcceleratorCapability 388 extends BaseType 389 implements java.io.Serializable 390 { 391 /** For Object Serialization. java.io.Serializable */ 392 protected static final long serialVersionUID = 1; 393 394 public boolean[] optionals() 395 { return new boolean[] { false, false, false, false, }; } 396 397 /** Video codec profile that is supported, e.g H264 Main. */ 398 public final String profile; 399 400 /** Maximum video dimensions in pixels supported for this |profile|. */ 401 public final SystemInfo.Size maxResolution; 402 403 /** 404 * Maximum encoding framerate in frames per second supported for this 405 * |profile|, as fraction's numerator and denominator, e.g. 24/1 fps, 406 * 24000/1001 fps, etc. 407 */ 408 public final int maxFramerateNumerator; 409 410 /** <CODE>[No Description Provided by Google]</CODE> */ 411 public final int maxFramerateDenominator; 412 413 /** 414 * Constructor 415 * 416 * @param profile Video codec profile that is supported, e.g H264 Main. 417 * 418 * @param maxResolution Maximum video dimensions in pixels supported for this |profile|. 419 * 420 * @param maxFramerateNumerator 421 * Maximum encoding framerate in frames per second supported for this 422 * |profile|, as fraction's numerator and denominator, e.g. 24/1 fps, 423 * 24000/1001 fps, etc. 424 * 425 * @param maxFramerateDenominator - 426 */ 427 public VideoEncodeAcceleratorCapability( 428 String profile, SystemInfo.Size maxResolution, int maxFramerateNumerator, 429 int maxFramerateDenominator 430 ) 431 { 432 // Exception-Check(s) to ensure that if any parameters which are not declared as 433 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 434 435 if (profile == null) BRDPC.throwNPE("profile"); 436 if (maxResolution == null) BRDPC.throwNPE("maxResolution"); 437 438 this.profile = profile; 439 this.maxResolution = maxResolution; 440 this.maxFramerateNumerator = maxFramerateNumerator; 441 this.maxFramerateDenominator = maxFramerateDenominator; 442 } 443 444 /** 445 * JSON Object Constructor 446 * @param jo A Json-Object having data about an instance of {@code 'VideoEncodeAcceleratorCapability'}. 447 */ 448 public VideoEncodeAcceleratorCapability (JsonObject jo) 449 { 450 this.profile = ReadJSON.getString(jo, "profile", false, true); 451 this.maxResolution = ReadJSON.getObject(jo, "maxResolution", SystemInfo.Size.class, false, true); 452 this.maxFramerateNumerator = ReadPrimJSON.getInt(jo, "maxFramerateNumerator"); 453 this.maxFramerateDenominator = ReadPrimJSON.getInt(jo, "maxFramerateDenominator"); 454 } 455 456 457 /** Checks whether {@code 'this'} equals an input Java-{@code Object} */ 458 public boolean equals(Object other) 459 { 460 if (other == null) return false; 461 if (other.getClass() != this.getClass()) return false; 462 463 VideoEncodeAcceleratorCapability o = (VideoEncodeAcceleratorCapability) other; 464 465 return 466 Objects.equals(this.profile, o.profile) 467 && Objects.equals(this.maxResolution, o.maxResolution) 468 && (this.maxFramerateNumerator == o.maxFramerateNumerator) 469 && (this.maxFramerateDenominator == o.maxFramerateDenominator); 470 } 471 472 /** Generates a Hash-Code for {@code 'this'} instance */ 473 public int hashCode() 474 { 475 return 476 Objects.hashCode(this.profile) 477 + this.maxResolution.hashCode() 478 + this.maxFramerateNumerator 479 + this.maxFramerateDenominator; 480 } 481 } 482 483 /** 484 * Describes a supported image decoding profile with its associated minimum and 485 * maximum resolutions and subsampling. 486 */ 487 public static class ImageDecodeAcceleratorCapability 488 extends BaseType 489 implements java.io.Serializable 490 { 491 /** For Object Serialization. java.io.Serializable */ 492 protected static final long serialVersionUID = 1; 493 494 public boolean[] optionals() 495 { return new boolean[] { false, false, false, false, }; } 496 497 /** Image coded, e.g. Jpeg. */ 498 public final String imageType; 499 500 /** Maximum supported dimensions of the image in pixels. */ 501 public final SystemInfo.Size maxDimensions; 502 503 /** Minimum supported dimensions of the image in pixels. */ 504 public final SystemInfo.Size minDimensions; 505 506 /** Optional array of supported subsampling formats, e.g. 4:2:0, if known. */ 507 public final String[] subsamplings; 508 509 /** 510 * Constructor 511 * 512 * @param imageType Image coded, e.g. Jpeg. 513 * 514 * @param maxDimensions Maximum supported dimensions of the image in pixels. 515 * 516 * @param minDimensions Minimum supported dimensions of the image in pixels. 517 * 518 * @param subsamplings Optional array of supported subsampling formats, e.g. 4:2:0, if known. 519 */ 520 public ImageDecodeAcceleratorCapability( 521 String imageType, SystemInfo.Size maxDimensions, SystemInfo.Size minDimensions, 522 String[] subsamplings 523 ) 524 { 525 // Exception-Check(s) to ensure that if any parameters which are not declared as 526 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 527 528 if (imageType == null) BRDPC.throwNPE("imageType"); 529 if (maxDimensions == null) BRDPC.throwNPE("maxDimensions"); 530 if (minDimensions == null) BRDPC.throwNPE("minDimensions"); 531 if (subsamplings == null) BRDPC.throwNPE("subsamplings"); 532 533 // Exception-Check(s) to ensure that if any parameters which must adhere to a 534 // provided List of Enumerated Values, fails, then IllegalArgumentException shall throw. 535 536 BRDPC.checkIAE("imageType", imageType, "SystemInfo.ImageType", SystemInfo.ImageType); 537 538 this.imageType = imageType; 539 this.maxDimensions = maxDimensions; 540 this.minDimensions = minDimensions; 541 this.subsamplings = subsamplings; 542 } 543 544 /** 545 * JSON Object Constructor 546 * @param jo A Json-Object having data about an instance of {@code 'ImageDecodeAcceleratorCapability'}. 547 */ 548 public ImageDecodeAcceleratorCapability (JsonObject jo) 549 { 550 this.imageType = ReadJSON.getString(jo, "imageType", false, true); 551 this.maxDimensions = ReadJSON.getObject(jo, "maxDimensions", SystemInfo.Size.class, false, true); 552 this.minDimensions = ReadJSON.getObject(jo, "minDimensions", SystemInfo.Size.class, false, true); 553 this.subsamplings = (jo.getJsonArray("subsamplings") == null) 554 ? null 555 : ReadArrJSON.DimN.strArr(jo.getJsonArray("subsamplings"), null, 0, String[].class); 556 557 } 558 559 560 /** Checks whether {@code 'this'} equals an input Java-{@code Object} */ 561 public boolean equals(Object other) 562 { 563 if (other == null) return false; 564 if (other.getClass() != this.getClass()) return false; 565 566 ImageDecodeAcceleratorCapability o = (ImageDecodeAcceleratorCapability) other; 567 568 return 569 Objects.equals(this.imageType, o.imageType) 570 && Objects.equals(this.maxDimensions, o.maxDimensions) 571 && Objects.equals(this.minDimensions, o.minDimensions) 572 && Arrays.deepEquals(this.subsamplings, o.subsamplings); 573 } 574 575 /** Generates a Hash-Code for {@code 'this'} instance */ 576 public int hashCode() 577 { 578 return 579 Objects.hashCode(this.imageType) 580 + this.maxDimensions.hashCode() 581 + this.minDimensions.hashCode() 582 + Arrays.deepHashCode(this.subsamplings); 583 } 584 } 585 586 /** Provides information about the GPU(s) on the system. */ 587 public static class GPUInfo 588 extends BaseType 589 implements java.io.Serializable 590 { 591 /** For Object Serialization. java.io.Serializable */ 592 protected static final long serialVersionUID = 1; 593 594 public boolean[] optionals() 595 { return new boolean[] { false, true, true, false, false, false, false, }; } 596 597 /** The graphics devices on the system. Element 0 is the primary GPU. */ 598 public final SystemInfo.GPUDevice[] devices; 599 600 /** 601 * An optional dictionary of additional GPU related attributes. 602 * <BR /> 603 * <BR /><B>OPTIONAL</B> 604 */ 605 public final JsonObject auxAttributes; 606 607 /** 608 * An optional dictionary of graphics features and their status. 609 * <BR /> 610 * <BR /><B>OPTIONAL</B> 611 */ 612 public final JsonObject featureStatus; 613 614 /** An optional array of GPU driver bug workarounds. */ 615 public final String[] driverBugWorkarounds; 616 617 /** Supported accelerated video decoding capabilities. */ 618 public final SystemInfo.VideoDecodeAcceleratorCapability[] videoDecoding; 619 620 /** Supported accelerated video encoding capabilities. */ 621 public final SystemInfo.VideoEncodeAcceleratorCapability[] videoEncoding; 622 623 /** Supported accelerated image decoding capabilities. */ 624 public final SystemInfo.ImageDecodeAcceleratorCapability[] imageDecoding; 625 626 /** 627 * Constructor 628 * 629 * @param devices The graphics devices on the system. Element 0 is the primary GPU. 630 * 631 * @param auxAttributes An optional dictionary of additional GPU related attributes. 632 * <BR /><B>OPTIONAL</B> 633 * 634 * @param featureStatus An optional dictionary of graphics features and their status. 635 * <BR /><B>OPTIONAL</B> 636 * 637 * @param driverBugWorkarounds An optional array of GPU driver bug workarounds. 638 * 639 * @param videoDecoding Supported accelerated video decoding capabilities. 640 * 641 * @param videoEncoding Supported accelerated video encoding capabilities. 642 * 643 * @param imageDecoding Supported accelerated image decoding capabilities. 644 */ 645 public GPUInfo( 646 SystemInfo.GPUDevice[] devices, JsonObject auxAttributes, JsonObject featureStatus, 647 String[] driverBugWorkarounds, 648 SystemInfo.VideoDecodeAcceleratorCapability[] videoDecoding, 649 SystemInfo.VideoEncodeAcceleratorCapability[] videoEncoding, 650 SystemInfo.ImageDecodeAcceleratorCapability[] imageDecoding 651 ) 652 { 653 // Exception-Check(s) to ensure that if any parameters which are not declared as 654 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 655 656 if (devices == null) BRDPC.throwNPE("devices"); 657 if (driverBugWorkarounds == null) BRDPC.throwNPE("driverBugWorkarounds"); 658 if (videoDecoding == null) BRDPC.throwNPE("videoDecoding"); 659 if (videoEncoding == null) BRDPC.throwNPE("videoEncoding"); 660 if (imageDecoding == null) BRDPC.throwNPE("imageDecoding"); 661 662 this.devices = devices; 663 this.auxAttributes = auxAttributes; 664 this.featureStatus = featureStatus; 665 this.driverBugWorkarounds = driverBugWorkarounds; 666 this.videoDecoding = videoDecoding; 667 this.videoEncoding = videoEncoding; 668 this.imageDecoding = imageDecoding; 669 } 670 671 /** 672 * JSON Object Constructor 673 * @param jo A Json-Object having data about an instance of {@code 'GPUInfo'}. 674 */ 675 public GPUInfo (JsonObject jo) 676 { 677 this.devices = (jo.getJsonArray("devices") == null) 678 ? null 679 : ReadArrJSON.DimN.objArr(jo.getJsonArray("devices"), null, 0, SystemInfo.GPUDevice[].class); 680 681 this.auxAttributes = jo.getJsonObject("auxAttributes"); 682 this.featureStatus = jo.getJsonObject("featureStatus"); 683 this.driverBugWorkarounds = (jo.getJsonArray("driverBugWorkarounds") == null) 684 ? null 685 : ReadArrJSON.DimN.strArr(jo.getJsonArray("driverBugWorkarounds"), null, 0, String[].class); 686 687 this.videoDecoding = (jo.getJsonArray("videoDecoding") == null) 688 ? null 689 : ReadArrJSON.DimN.objArr(jo.getJsonArray("videoDecoding"), null, 0, SystemInfo.VideoDecodeAcceleratorCapability[].class); 690 691 this.videoEncoding = (jo.getJsonArray("videoEncoding") == null) 692 ? null 693 : ReadArrJSON.DimN.objArr(jo.getJsonArray("videoEncoding"), null, 0, SystemInfo.VideoEncodeAcceleratorCapability[].class); 694 695 this.imageDecoding = (jo.getJsonArray("imageDecoding") == null) 696 ? null 697 : ReadArrJSON.DimN.objArr(jo.getJsonArray("imageDecoding"), null, 0, SystemInfo.ImageDecodeAcceleratorCapability[].class); 698 699 } 700 701 702 /** Checks whether {@code 'this'} equals an input Java-{@code Object} */ 703 public boolean equals(Object other) 704 { 705 if (other == null) return false; 706 if (other.getClass() != this.getClass()) return false; 707 708 GPUInfo o = (GPUInfo) other; 709 710 return 711 Arrays.deepEquals(this.devices, o.devices) 712 && Objects.equals(this.auxAttributes, o.auxAttributes) 713 && Objects.equals(this.featureStatus, o.featureStatus) 714 && Arrays.deepEquals(this.driverBugWorkarounds, o.driverBugWorkarounds) 715 && Arrays.deepEquals(this.videoDecoding, o.videoDecoding) 716 && Arrays.deepEquals(this.videoEncoding, o.videoEncoding) 717 && Arrays.deepEquals(this.imageDecoding, o.imageDecoding); 718 } 719 720 /** Generates a Hash-Code for {@code 'this'} instance */ 721 public int hashCode() 722 { 723 return 724 Arrays.deepHashCode(this.devices) 725 + Objects.hashCode(this.auxAttributes) 726 + Objects.hashCode(this.featureStatus) 727 + Arrays.deepHashCode(this.driverBugWorkarounds) 728 + Arrays.deepHashCode(this.videoDecoding) 729 + Arrays.deepHashCode(this.videoEncoding) 730 + Arrays.deepHashCode(this.imageDecoding); 731 } 732 } 733 734 /** Represents process info. */ 735 public static class ProcessInfo 736 extends BaseType 737 implements java.io.Serializable 738 { 739 /** For Object Serialization. java.io.Serializable */ 740 protected static final long serialVersionUID = 1; 741 742 public boolean[] optionals() 743 { return new boolean[] { false, false, false, }; } 744 745 /** Specifies process type. */ 746 public final String type; 747 748 /** Specifies process id. */ 749 public final int id; 750 751 /** 752 * Specifies cumulative CPU usage in seconds across all threads of the 753 * process since the process start. 754 */ 755 public final Number cpuTime; 756 757 /** 758 * Constructor 759 * 760 * @param type Specifies process type. 761 * 762 * @param id Specifies process id. 763 * 764 * @param cpuTime 765 * Specifies cumulative CPU usage in seconds across all threads of the 766 * process since the process start. 767 */ 768 public ProcessInfo(String type, int id, Number cpuTime) 769 { 770 // Exception-Check(s) to ensure that if any parameters which are not declared as 771 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 772 773 if (type == null) BRDPC.throwNPE("type"); 774 if (cpuTime == null) BRDPC.throwNPE("cpuTime"); 775 776 this.type = type; 777 this.id = id; 778 this.cpuTime = cpuTime; 779 } 780 781 /** 782 * JSON Object Constructor 783 * @param jo A Json-Object having data about an instance of {@code 'ProcessInfo'}. 784 */ 785 public ProcessInfo (JsonObject jo) 786 { 787 this.type = ReadJSON.getString(jo, "type", false, true); 788 this.id = ReadPrimJSON.getInt(jo, "id"); 789 this.cpuTime = ReadNumberJSON.get(jo, "cpuTime", false, true); 790 } 791 792 793 /** Checks whether {@code 'this'} equals an input Java-{@code Object} */ 794 public boolean equals(Object other) 795 { 796 if (other == null) return false; 797 if (other.getClass() != this.getClass()) return false; 798 799 ProcessInfo o = (ProcessInfo) other; 800 801 return 802 Objects.equals(this.type, o.type) 803 && (this.id == o.id) 804 && Objects.equals(this.cpuTime, o.cpuTime); 805 } 806 807 /** Generates a Hash-Code for {@code 'this'} instance */ 808 public int hashCode() 809 { 810 return 811 Objects.hashCode(this.type) 812 + this.id 813 + Objects.hashCode(this.cpuTime); 814 } 815 } 816 817 818 // Counter for keeping the WebSocket Request ID's distinct. 819 private static int counter = 1; 820 821 /** 822 * Returns information about the system. 823 * 824 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 825 * {@link Ret4}></CODE> 826 * 827 * <BR /><BR />This {@link Script} may be <B STYLE='color:red'>executed</B> (using 828 * {@link Script#exec()}), and a {@link Promise} returned. 829 * 830 * <BR /><BR />When the {@code Promise} is <B STYLE='color: red'>awaited</B> 831 * (using {@link Promise#await()}), the {@code Ret4} will subsequently 832 * be returned from that call. 833 * 834 * <BR /><BR />The <B STYLE='color: red'>returned</B> values are encapsulated 835 * in an instance of <B>{@link Ret4}</B> 836 * 837 * <BR /><BR /><UL CLASS=JDUL> 838 * <LI><CODE><B>Ret4.a:</B> {@link SystemInfo.GPUInfo} (<B>gpu</B>)</CODE> 839 * <BR />Information about the GPUs on the system. 840 * <BR /><BR /></LI> 841 * <LI><CODE><B>Ret4.b:</B> String (<B>modelName</B>)</CODE> 842 * <BR />A platform-dependent description of the model of the machine. On Mac OS, this is, for 843 * example, 'MacBookPro'. Will be the empty string if not supported. 844 * <BR /><BR /></LI> 845 * <LI><CODE><B>Ret4.c:</B> String (<B>modelVersion</B>)</CODE> 846 * <BR />A platform-dependent description of the version of the machine. On Mac OS, this is, for 847 * example, '10.1'. Will be the empty string if not supported. 848 * <BR /><BR /></LI> 849 * <LI><CODE><B>Ret4.d:</B> String (<B>commandLine</B>)</CODE> 850 * <BR />The command line string used to launch the browser. Will be the empty string if not 851 * supported. 852 * </LI> 853 * </UL> 854 */ 855 public static Script<String, JsonObject, Ret4<SystemInfo.GPUInfo, String, String, String>> getInfo() 856 { 857 final int webSocketID = 38000000 + counter++; 858 final boolean[] optionals = new boolean[0]; 859 860 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 861 String requestJSON = WriteJSON.get( 862 parameterTypes.get("getInfo"), 863 parameterNames.get("getInfo"), 864 optionals, webSocketID, 865 "SystemInfo.getInfo" 866 ); 867 868 // 'JSON Binding' ... Converts Browser Response-JSON into Java-Type 'Ret4' 869 Function<JsonObject, Ret4<SystemInfo.GPUInfo, String, String, String>> 870 responseProcessor = (JsonObject jo) -> new Ret4<>( 871 ReadJSON.getObject(jo, "gpu", SystemInfo.GPUInfo.class, false, true), 872 ReadJSON.getString(jo, "modelName", false, true), 873 ReadJSON.getString(jo, "modelVersion", false, true), 874 ReadJSON.getString(jo, "commandLine", false, true) 875 ); 876 877 // Pass the 'defaultSender' to Script-Constructor 878 // The sender that is used can be changed before executing script. 879 return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor); 880 } 881 882 /** 883 * Returns information about all running processes. 884 * 885 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 886 * {@link SystemInfo.ProcessInfo}[]></CODE> 887 * 888 * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using 889 * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE><JsonObject, 890 * {@link SystemInfo.ProcessInfo}[]></CODE> will be returned. 891 * 892 * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>, 893 * using {@link Promise#await()}, <I>and the returned result of this Browser Function may 894 * may be retrieved.</I> 895 * 896 * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B> 897 * <BR /><BR /><UL CLASS=JDUL> 898 * <LI><CODE>{@link SystemInfo.ProcessInfo}[] (<B>processInfo</B></CODE>) 899 * <BR />An array of process info blocks. 900 * </LI> 901 * </UL> */ 902 public static Script<String, JsonObject, SystemInfo.ProcessInfo[]> getProcessInfo() 903 { 904 final int webSocketID = 38001000 + counter++; 905 final boolean[] optionals = new boolean[0]; 906 907 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 908 String requestJSON = WriteJSON.get( 909 parameterTypes.get("getProcessInfo"), 910 parameterNames.get("getProcessInfo"), 911 optionals, webSocketID, 912 "SystemInfo.getProcessInfo" 913 ); 914 915 // 'JSON Binding' ... Converts Browser Response-JSON to 'SystemInfo.ProcessInfo[]' 916 Function<JsonObject, SystemInfo.ProcessInfo[]> responseProcessor = (JsonObject jo) -> 917 (jo.getJsonArray("processInfo") == null) 918 ? null 919 : ReadArrJSON.DimN.objArr(jo.getJsonArray("processInfo"), null, 0, SystemInfo.ProcessInfo[].class); 920 921 // Pass the 'defaultSender' to Script-Constructor 922 // The sender that is used can be changed before executing script. 923 return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor); 924 } 925 926}