corba.js 0.1.13 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/idl/idl.cjs CHANGED
@@ -2006,6 +2006,19 @@ function writeTSInterfaceDefinitions(out, specification, prefix = "", indent = 0
2006
2006
  }
2007
2007
  break;
2008
2008
  case Type.TKN_ATTRIBUTE:
2009
+ {
2010
+ const readonly = _export.child[0]?.type == Type.TKN_READONLY;
2011
+ const param_type_spec = _export.child[1];
2012
+ const attr_declarator = _export.child[2];
2013
+ const type = typeIDLtoTS(param_type_spec, FileType.INTERFACE);
2014
+ for (const n of attr_declarator.child) {
2015
+ const identifier = n.text;
2016
+ if (!readonly) {
2017
+ out.write(` ${identifier}(value: ${type}): Promise<void>\n`);
2018
+ }
2019
+ out.write(` ${identifier}(): Promise<${type}>\n`);
2020
+ }
2021
+ }
2009
2022
  break;
2010
2023
  default:
2011
2024
  throw Error("yikes");
@@ -2248,6 +2261,26 @@ function writeTSSkeletonDefinitions(out, specification, prefix = "", indent = 0)
2248
2261
  }
2249
2262
  break;
2250
2263
  case Type.TKN_ATTRIBUTE:
2264
+ {
2265
+ const readonly = _export.child[0]?.type == Type.TKN_READONLY;
2266
+ const param_type_spec = _export.child[1];
2267
+ const attr_declarator = _export.child[2];
2268
+ const type = typeIDLtoTS(param_type_spec, FileType.INTERFACE);
2269
+ for (const n of attr_declarator.child) {
2270
+ const identifier = n.text;
2271
+ out.write(` abstract ${identifier}(): Promise<${type}>\n`);
2272
+ if (!readonly) {
2273
+ out.write(` abstract ${identifier}(value: ${type}): Promise<void>\n`);
2274
+ out.write(` abstract ${identifier}(value?: ${type}): Promise<void | ${type}>\n`);
2275
+ out.write(` private async _orb__set_${identifier}(decoder: GIOPDecoder, encoder: GIOPEncoder) {\n`);
2276
+ out.write(` this.${identifier}(${typeIDLtoGIOPTS(param_type_spec)})\n`);
2277
+ out.write(` }\n`);
2278
+ }
2279
+ out.write(` private async _orb__get_${identifier}(decoder: GIOPDecoder, encoder: GIOPEncoder) {\n`);
2280
+ out.write(` ${typeIDLtoGIOPTS(param_type_spec, `await this.${identifier}()`)}\n`);
2281
+ out.write(` }\n`);
2282
+ }
2283
+ }
2251
2284
  break;
2252
2285
  default:
2253
2286
  throw Error("yikes");
@@ -2331,10 +2364,10 @@ function writeTSStubDefinitions(out, specification, prefix = "", indent = 0) {
2331
2364
  if (!oneway)
2332
2365
  out.write("await ");
2333
2366
  if (oneway) {
2334
- out.write(`this.orb.onewayCall(this, "${identifier}", `);
2367
+ out.write(`this._orb.onewayCall(this, "${identifier}", `);
2335
2368
  }
2336
2369
  else {
2337
- out.write(`this.orb.twowayCall(this, "${identifier}", `);
2370
+ out.write(`this._orb.twowayCall(this, "${identifier}", `);
2338
2371
  }
2339
2372
  out.write(`(encoder) => {\n`);
2340
2373
  for (let parameter_dcl of parameter_decls) {
@@ -2359,6 +2392,40 @@ function writeTSStubDefinitions(out, specification, prefix = "", indent = 0) {
2359
2392
  }
2360
2393
  break;
2361
2394
  case Type.TKN_ATTRIBUTE:
2395
+ {
2396
+ const readonly = _export.child[0]?.type == Type.TKN_READONLY;
2397
+ const param_type_spec = _export.child[1];
2398
+ const attr_declarator = _export.child[2];
2399
+ for (const n of attr_declarator.child) {
2400
+ const identifier = n.text;
2401
+ const type = typeIDLtoTS(param_type_spec, FileType.INTERFACE);
2402
+ if (readonly) {
2403
+ out.write(` async ${identifier}(): Promise<${type}> {\n`);
2404
+ out.write(` return this._orb.twowayCall(this, "_get_${identifier}",\n`);
2405
+ out.write(` (encoder) => { },\n`);
2406
+ out.write(` (decoder) => decoder.string()\n`);
2407
+ out.write(` )\n`);
2408
+ out.write(` }\n`);
2409
+ }
2410
+ else {
2411
+ out.write(` async ${identifier}(): Promise<${type}>\n`);
2412
+ out.write(` async ${identifier}(value: ${type}): Promise<void>\n`);
2413
+ out.write(` async ${identifier}(value?: ${type}): Promise<void | ${type}> {\n`);
2414
+ out.write(` if (value === undefined) {\n`);
2415
+ out.write(` return this._orb.twowayCall(this, "_get_${identifier}",\n`);
2416
+ out.write(` (encoder) => { },\n`);
2417
+ out.write(` (decoder) => decoder.string()\n`);
2418
+ out.write(` )\n`);
2419
+ out.write(` } else {\n`);
2420
+ out.write(` return this._orb.twowayCall(this, "_set_${identifier}",\n`);
2421
+ out.write(` (encoder) => { encoder.string(value) },\n`);
2422
+ out.write(` (decoder) => { }\n`);
2423
+ out.write(` )\n`);
2424
+ out.write(` }\n`);
2425
+ out.write(` }\n`);
2426
+ }
2427
+ }
2428
+ }
2362
2429
  break;
2363
2430
  default:
2364
2431
  throw Error("yikes");
@@ -2822,6 +2889,7 @@ var Direction;
2822
2889
  (function (Direction) {
2823
2890
  Direction[Direction["IN"] = 0] = "IN";
2824
2891
  Direction[Direction["OUT"] = 1] = "OUT";
2892
+ Direction[Direction["NESTED"] = 1] = "NESTED";
2825
2893
  })(Direction || (Direction = {}));
2826
2894
  function typeIDLtoCC(type, direction) {
2827
2895
  if (type === undefined)
@@ -2930,7 +2998,8 @@ function typeIDLtoCC(type, direction) {
2930
2998
  default:
2931
2999
  throw Error("yikes");
2932
3000
  }
2933
- default:
3001
+ case Type.TKN_FLOAT:
3002
+ case Type.TKN_DOUBLE:
2934
3003
  switch (direction) {
2935
3004
  case Direction.IN:
2936
3005
  return `const std::span<${typeIDLtoCC(type.child[0], direction)}> &`;
@@ -2939,6 +3008,15 @@ function typeIDLtoCC(type, direction) {
2939
3008
  default:
2940
3009
  throw Error("yikes");
2941
3010
  }
3011
+ default:
3012
+ switch (direction) {
3013
+ case Direction.IN:
3014
+ return `const std::vector<${typeIDLtoCC(type.child[0], Direction.NESTED)}> &`;
3015
+ case Direction.OUT:
3016
+ return `std::vector<${typeIDLtoCC(type.child[0], Direction.NESTED)}>`;
3017
+ default:
3018
+ throw Error("yikes");
3019
+ }
2942
3020
  }
2943
3021
  default:
2944
3022
  throw Error(`no mapping from IDL type to C++ type for ${type.toString()}`);
@@ -2956,7 +3034,12 @@ function typeIDLtoGIOPCC(type, arg, direction) {
2956
3034
  case Type.TKN_VALUETYPE:
2957
3035
  return arg === undefined ? `decoder.value("${type.text}")` : `encoder.value(${arg})`;
2958
3036
  case Type.SYN_INTERFACE:
2959
- return arg === undefined ? `co_await ${type.text}::_narrow(decoder.readObject(obj->get_ORB()))` : `encoder.writeObject(${arg}.get())`;
3037
+ switch (direction) {
3038
+ case Direction.IN:
3039
+ return arg === undefined ? `${type.text}::_narrow(decoder.readObject(obj->get_ORB()))` : `encoder.writeObject(${arg}.get())`;
3040
+ case Direction.OUT:
3041
+ return arg === undefined ? `${type.text}::_narrow(decoder.readObject(get_ORB()))` : `encoder.writeObject(${arg}.get())`;
3042
+ }
2960
3043
  case Type.TKN_UNION:
2961
3044
  throw Error("union is not implemented yet");
2962
3045
  case Type.TKN_STRUCT: {
@@ -3055,15 +3138,18 @@ function typeIDLtoGIOPCC(type, arg, direction) {
3055
3138
  switch (direction) {
3056
3139
  case Direction.IN:
3057
3140
  return arg === undefined
3058
- ? `decoder.readSequenceVector<std::string_view>([&] { return decoder.readStringView(); })`
3141
+ ? `decoder.readSequence<std::string_view>([&] { return decoder.readStringView(); })`
3059
3142
  : `encoder.writeSequence<std::string_view>(${arg}, [&](auto item) { encoder.writeString(item);})`;
3060
3143
  case Direction.OUT:
3061
3144
  return arg === undefined
3062
- ? `decoder.readSequenceVector<std::string>([&] { return decoder.readString(); })`
3145
+ ? `decoder.readSequence<std::string>([&] { return decoder.readString(); })`
3063
3146
  : `encoder.writeSequence<std::string>(${arg}, [&](auto item) { encoder.writeString(item);})`;
3064
3147
  }
3148
+ default:
3149
+ return arg === undefined
3150
+ ? `decoder.readSequence<${typeIDLtoCC(type.child[0], Direction.NESTED)}>([&] { return ${typeIDLtoGIOPCC(type.child[0], undefined, direction)}; })`
3151
+ : `encoder.writeSequence<${typeIDLtoCC(type.child[0], Direction.NESTED)}>(${arg}, [&](auto item) { ${typeIDLtoGIOPCC(type.child[0], "item", direction)}; })`;
3065
3152
  }
3066
- throw Error(`this sequence type is not implemented yet`);
3067
3153
  default:
3068
3154
  type.printTree();
3069
3155
  throw Error(`no mapping from IDL type '${type.toString()}' to GIOP encoder/decoder`);
@@ -3079,10 +3165,11 @@ function writeCCInterface(specification) {
3079
3165
  out.write(`#include <corba/giop.hh>\n`);
3080
3166
  out.write(`#include <corba/coroutine.hh>\n`);
3081
3167
  out.write(`#include <corba/corba.hh>\n`);
3168
+ out.write(`#include <memory>\n`);
3082
3169
  out.write(`#include <string>\n`);
3170
+ out.write(`#include <utility>\n`);
3083
3171
  out.write(`#include <vector>\n`);
3084
3172
  out.write(`#include <span>\n`);
3085
- out.write(`#include <utility>\n`);
3086
3173
  if (hasValueType(specification)) {
3087
3174
  out.write("import * as valuetype from \"./" + filenameLocal + "_valuetype\"\n");
3088
3175
  }
@@ -3147,13 +3234,25 @@ function writeCCInterfaceDefinitions(out, specification, prefix = "", indent = 0
3147
3234
  }
3148
3235
  break;
3149
3236
  case Type.TKN_ATTRIBUTE:
3237
+ {
3238
+ const readonly = _export.child[0]?.type == Type.TKN_READONLY;
3239
+ const param_type_spec = _export.child[1];
3240
+ const attr_declarator = _export.child[2];
3241
+ for (const n of attr_declarator.child) {
3242
+ const identifier = n.text;
3243
+ out.write(` virtual CORBA::async<${typeIDLtoCC(param_type_spec, Direction.OUT)}> ${identifier}() = 0;\n`);
3244
+ if (!readonly) {
3245
+ out.write(` virtual CORBA::async<void> ${identifier}(${typeIDLtoCC(param_type_spec, Direction.IN)}) = 0;\n`);
3246
+ }
3247
+ }
3248
+ }
3150
3249
  break;
3151
3250
  default:
3152
3251
  throw Error("yikes");
3153
3252
  }
3154
3253
  }
3155
3254
  out.write(` std::string_view repository_id() const override;\n`);
3156
- out.write(` static CORBA::async<std::shared_ptr<${identifier}>> _narrow(std::shared_ptr<CORBA::Object> pointer);\n`);
3255
+ out.write(` static std::shared_ptr<${identifier}> _narrow(std::shared_ptr<CORBA::Object> pointer);\n`);
3157
3256
  out.write("};\n\n");
3158
3257
  }
3159
3258
  break;
@@ -3294,7 +3393,7 @@ function writeCCSkeletonDefinitions(out, specification, prefix = "", indent = 0)
3294
3393
  interface_dcl.child[1];
3295
3394
  out.write(`class ${identifier}_skel: public CORBA::Skeleton, public ${prefix}${identifier} {\n`);
3296
3395
  out.write(`public:\n`);
3297
- out.write(` ${identifier}_skel(std::shared_ptr<CORBA::ORB> orb) : Skeleton(orb) {}\n`);
3396
+ out.write(` ${identifier}_skel() : Skeleton() {}\n`);
3298
3397
  out.write(`private:\n`);
3299
3398
  out.write(` CORBA::async<> _call(const std::string_view &operation, CORBA::GIOPDecoder &decoder, CORBA::GIOPEncoder &encoder) override;\n`);
3300
3399
  out.write("};\n\n");
@@ -3334,7 +3433,7 @@ function writeCCStubDefinitions(out, specification, prefix = "", indent = 0) {
3334
3433
  let interface_body = interface_dcl.child[1];
3335
3434
  out.write(`class ${identifier}_stub: public ${prefix}${identifier}, public CORBA::Stub {\n`);
3336
3435
  out.write(`public:\n`);
3337
- out.write(` ${identifier}_stub(std::shared_ptr<CORBA::ORB> orb, CORBA::blob_view objectKey, CORBA::detail::Connection *connection): Stub(orb, objectKey, connection) {}\n`);
3436
+ out.write(` ${identifier}_stub(std::shared_ptr<CORBA::ORB> orb, CORBA::blob_view objectKey, std::shared_ptr<CORBA::detail::Connection> connection): Stub(orb, objectKey, connection) {}\n`);
3338
3437
  for (let _export of interface_body.child) {
3339
3438
  switch (_export.type) {
3340
3439
  case Type.SYN_OPERATION_DECLARATION:
@@ -3377,6 +3476,18 @@ function writeCCStubDefinitions(out, specification, prefix = "", indent = 0) {
3377
3476
  }
3378
3477
  break;
3379
3478
  case Type.TKN_ATTRIBUTE:
3479
+ {
3480
+ const readonly = _export.child[0]?.type == Type.TKN_READONLY;
3481
+ const param_type_spec = _export.child[1];
3482
+ const attr_declarator = _export.child[2];
3483
+ for (const n of attr_declarator.child) {
3484
+ const identifier = n.text;
3485
+ out.write(` virtual CORBA::async<${typeIDLtoCC(param_type_spec, Direction.OUT)}> ${identifier}() override;\n`);
3486
+ if (!readonly) {
3487
+ out.write(` virtual CORBA::async<void> ${identifier}(${typeIDLtoCC(param_type_spec, Direction.IN)}) override;\n`);
3488
+ }
3489
+ }
3490
+ }
3380
3491
  break;
3381
3492
  default:
3382
3493
  throw Error("yikes");
@@ -3536,6 +3647,36 @@ function writeCCCodeDefinitions(out, specification, prefix = "", indent = 0) {
3536
3647
  }
3537
3648
  break;
3538
3649
  case Type.TKN_ATTRIBUTE:
3650
+ {
3651
+ const readonly = _export.child[0]?.type == Type.TKN_READONLY;
3652
+ const param_type_spec = _export.child[1];
3653
+ const attr_declarator = _export.child[2];
3654
+ for (const n of attr_declarator.child) {
3655
+ const identifier = n.text;
3656
+ out.write(`static CORBA::async<> _${if_identifier}_get_${identifier}(${if_identifier} *obj, CORBA::GIOPDecoder &decoder, CORBA::GIOPEncoder &encoder) {\n`);
3657
+ out.write(` ${typeIDLtoGIOPCC(param_type_spec, `co_await obj->${identifier}()`, Direction.OUT)};\n`);
3658
+ out.write(` co_return;\n`);
3659
+ out.write(`}\n`);
3660
+ out.write(`CORBA::async<${typeIDLtoCC(param_type_spec, Direction.OUT)}> ${if_identifier}_stub::${identifier}() {\n`);
3661
+ out.write(` return get_ORB()->twowayCall<${typeIDLtoCC(param_type_spec, Direction.OUT)}>(\n`);
3662
+ out.write(` this, "_get_${identifier}",\n`);
3663
+ out.write(` [&](CORBA::GIOPEncoder &encoder) { },\n`);
3664
+ out.write(` [&](CORBA::GIOPDecoder &decoder) { return ${typeIDLtoGIOPCC(param_type_spec, undefined, Direction.OUT)}; }\n`);
3665
+ out.write(` );\n`);
3666
+ out.write(`}\n`);
3667
+ if (!readonly) {
3668
+ out.write(`static CORBA::async<> _${if_identifier}_set_${identifier}(${if_identifier} *obj, CORBA::GIOPDecoder &decoder, CORBA::GIOPEncoder &encoder) {\n`);
3669
+ out.write(` return obj->${identifier}(${typeIDLtoGIOPCC(param_type_spec, undefined, Direction.IN)});\n`);
3670
+ out.write(`}\n`);
3671
+ out.write(`CORBA::async<void> ${if_identifier}_stub::${identifier}(${typeIDLtoCC(param_type_spec, Direction.IN)} _v) {\n`);
3672
+ out.write(` return get_ORB()->twowayCall(\n`);
3673
+ out.write(` this, "_set_${identifier}",\n`);
3674
+ out.write(` [&](CORBA::GIOPEncoder &encoder) { ${typeIDLtoGIOPCC(param_type_spec, "_v", Direction.IN)}; }\n`);
3675
+ out.write(` );\n`);
3676
+ out.write(`}\n`);
3677
+ }
3678
+ }
3679
+ }
3539
3680
  break;
3540
3681
  default:
3541
3682
  throw Error("yikes");
@@ -3554,6 +3695,18 @@ function writeCCCodeDefinitions(out, specification, prefix = "", indent = 0) {
3554
3695
  }
3555
3696
  break;
3556
3697
  case Type.TKN_ATTRIBUTE:
3698
+ {
3699
+ const readonly = _export.child[0]?.type == Type.TKN_READONLY;
3700
+ _export.child[1];
3701
+ const attr_declarator = _export.child[2];
3702
+ for (const n of attr_declarator.child) {
3703
+ const identifier = n.text;
3704
+ if (!readonly) {
3705
+ out.write(` {"_set_${identifier}", _${if_identifier}_set_${identifier}},\n`);
3706
+ }
3707
+ out.write(` {"_get_${identifier}", _${if_identifier}_get_${identifier}},\n`);
3708
+ }
3709
+ }
3557
3710
  break;
3558
3711
  default:
3559
3712
  throw Error("yikes");
@@ -3569,23 +3722,23 @@ function writeCCCodeDefinitions(out, specification, prefix = "", indent = 0) {
3569
3722
  out.write("};\n\n");
3570
3723
  out.write(`std::string_view ${if_identifier}::_rid("IDL:${if_identifier}:1.0");\n`);
3571
3724
  out.write(`std::string_view ${if_identifier}::repository_id() const { return _rid;}\n\n`);
3572
- out.write(`CORBA::async<std::shared_ptr<${if_identifier}>> ${if_identifier}::_narrow(std::shared_ptr<CORBA::Object> pointer) {\n`);
3725
+ out.write(`std::shared_ptr<${if_identifier}> ${if_identifier}::_narrow(std::shared_ptr<CORBA::Object> pointer) {\n`);
3573
3726
  out.write(` auto ptr = pointer.get();\n`);
3574
3727
  out.write(` auto ref = dynamic_cast<CORBA::IOR *>(ptr);\n`);
3575
3728
  out.write(` if (ref) {\n`);
3576
3729
  out.write(` if (ref->repository_id() != "IDL:${if_identifier}:1.0") {\n`);
3577
- out.write(` co_return std::shared_ptr<${if_identifier}>();\n`);
3730
+ out.write(` return std::shared_ptr<${if_identifier}>();\n`);
3578
3731
  out.write(` }\n`);
3579
3732
  out.write(` std::shared_ptr<CORBA::ORB> orb = ref->get_ORB();\n`);
3580
- out.write(` CORBA::detail::Connection *conn = co_await orb->getConnection(ref->host, ref->port);\n`);
3733
+ out.write(` auto conn = orb->getConnection(ref->host, ref->port);\n`);
3581
3734
  out.write(` auto stub = std::make_shared<${if_identifier}_stub>(orb, CORBA::blob_view(ref->objectKey), conn);\n`);
3582
- out.write(` co_return std::dynamic_pointer_cast<${if_identifier}>(stub);\n`);
3735
+ out.write(` return std::dynamic_pointer_cast<${if_identifier}>(stub);\n`);
3583
3736
  out.write(` }\n`);
3584
3737
  out.write(` auto obj = dynamic_cast<${if_identifier}*>(ptr);\n`);
3585
3738
  out.write(` if (obj) {\n`);
3586
- out.write(` co_return std::dynamic_pointer_cast<${if_identifier}>(pointer);\n`);
3739
+ out.write(` return std::dynamic_pointer_cast<${if_identifier}>(pointer);\n`);
3587
3740
  out.write(` }\n`);
3588
- out.write(` co_return std::shared_ptr<${if_identifier}>();\n`);
3741
+ out.write(` return std::shared_ptr<${if_identifier}>();\n`);
3589
3742
  out.write(`}\n\n`);
3590
3743
  }
3591
3744
  break;