Skip to content
This repository was archived by the owner on Dec 4, 2021. It is now read-only.

Commit 441e7b5

Browse files
authored
Add 2D Printer HealthCheck RPC (#52)
1 parent 287a61c commit 441e7b5

7 files changed

Lines changed: 523 additions & 36 deletions

File tree

client/printing/print_client.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@ const fs = require('fs');
33
const messages = require('./print_pb');
44
const services = require('./print_grpc_pb');
55

6+
function healthCheck() {
7+
const client = new services.PrinterClient(
8+
'localhost:50051', grpc.credentials.createInsecure()
9+
);
10+
const healthCheckRequest = new messages.PrintRequest();
11+
return new Promise(function(resolve, reject) {
12+
client.healthCheck(healthCheckRequest, function(err, response) {
13+
if (err || !response) {
14+
reject({ message: 'Printer is down', error: true });
15+
} else {
16+
resolve({ message: response, error: false });
17+
}
18+
});
19+
});
20+
}
21+
622
function sendPrintRequest(raw, copies, sides, pageRanges, destination) {
723
printOptions = {
824
'sides': sides,
@@ -30,4 +46,4 @@ function sendPrintRequest(raw, copies, sides, pageRanges, destination) {
3046
});
3147
}
3248

33-
module.exports = { sendPrintRequest };
49+
module.exports = { sendPrintRequest, healthCheck };

client/printing/print_grpc_pb.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44
var grpc = require('grpc');
55
var print_pb = require('./print_pb.js');
66

7+
function serialize_HealthCheckUpRequest(arg) {
8+
if (!(arg instanceof print_pb.HealthCheckUpRequest)) {
9+
throw new Error('Expected argument of type HealthCheckUpRequest');
10+
}
11+
return Buffer.from(arg.serializeBinary());
12+
}
13+
14+
function deserialize_HealthCheckUpRequest(buffer_arg) {
15+
return print_pb.HealthCheckUpRequest.deserializeBinary(new Uint8Array(buffer_arg));
16+
}
17+
718
function serialize_PrintRequest(arg) {
819
if (!(arg instanceof print_pb.PrintRequest)) {
920
throw new Error('Expected argument of type PrintRequest');
@@ -26,6 +37,17 @@ function deserialize_PrintResponse(buffer_arg) {
2637
return print_pb.PrintResponse.deserializeBinary(new Uint8Array(buffer_arg));
2738
}
2839

40+
function serialize_PrinterHealthStatus(arg) {
41+
if (!(arg instanceof print_pb.PrinterHealthStatus)) {
42+
throw new Error('Expected argument of type PrinterHealthStatus');
43+
}
44+
return Buffer.from(arg.serializeBinary());
45+
}
46+
47+
function deserialize_PrinterHealthStatus(buffer_arg) {
48+
return print_pb.PrinterHealthStatus.deserializeBinary(new Uint8Array(buffer_arg));
49+
}
50+
2951

3052
var PrinterService = exports.PrinterService = {
3153
printPage: {
@@ -39,6 +61,17 @@ var PrinterService = exports.PrinterService = {
3961
responseSerialize: serialize_PrintResponse,
4062
responseDeserialize: deserialize_PrintResponse,
4163
},
64+
healthCheck: {
65+
path: '/Printer/HealthCheck',
66+
requestStream: false,
67+
responseStream: false,
68+
requestType: print_pb.HealthCheckUpRequest,
69+
responseType: print_pb.PrinterHealthStatus,
70+
requestSerialize: serialize_HealthCheckUpRequest,
71+
requestDeserialize: deserialize_HealthCheckUpRequest,
72+
responseSerialize: serialize_PrinterHealthStatus,
73+
responseDeserialize: deserialize_PrinterHealthStatus,
74+
},
4275
};
4376

4477
exports.PrinterClient = grpc.makeGenericClientConstructor(PrinterService);

client/printing/print_pb.js

Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ var jspb = require('google-protobuf');
1111
var goog = jspb;
1212
var global = Function('return this')();
1313

14+
goog.exportSymbol('proto.HealthCheckUpRequest', null, global);
1415
goog.exportSymbol('proto.PrintRequest', null, global);
1516
goog.exportSymbol('proto.PrintResponse', null, global);
17+
goog.exportSymbol('proto.PrinterHealthStatus', null, global);
1618

1719
/**
1820
* Generated by JsPbCodeGenerator.
@@ -404,4 +406,288 @@ proto.PrintResponse.prototype.setMessage = function(value) {
404406
};
405407

406408

409+
410+
/**
411+
* Generated by JsPbCodeGenerator.
412+
* @param {Array=} opt_data Optional initial data array, typically from a
413+
* server response, or constructed directly in Javascript. The array is used
414+
* in place and becomes part of the constructed object. It is not cloned.
415+
* If no data is provided, the constructed object will be empty, but still
416+
* valid.
417+
* @extends {jspb.Message}
418+
* @constructor
419+
*/
420+
proto.HealthCheckUpRequest = function(opt_data) {
421+
jspb.Message.initialize(this, opt_data, 0, -1, null, null);
422+
};
423+
goog.inherits(proto.HealthCheckUpRequest, jspb.Message);
424+
if (goog.DEBUG && !COMPILED) {
425+
proto.HealthCheckUpRequest.displayName = 'proto.HealthCheckUpRequest';
426+
}
427+
428+
429+
if (jspb.Message.GENERATE_TO_OBJECT) {
430+
/**
431+
* Creates an object representation of this proto suitable for use in Soy templates.
432+
* Field names that are reserved in JavaScript and will be renamed to pb_name.
433+
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
434+
* For the list of reserved names please see:
435+
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
436+
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance
437+
* for transitional soy proto support: http://goto/soy-param-migration
438+
* @return {!Object}
439+
*/
440+
proto.HealthCheckUpRequest.prototype.toObject = function(opt_includeInstance) {
441+
return proto.HealthCheckUpRequest.toObject(opt_includeInstance, this);
442+
};
443+
444+
445+
/**
446+
* Static version of the {@see toObject} method.
447+
* @param {boolean|undefined} includeInstance Whether to include the JSPB
448+
* instance for transitional soy proto support:
449+
* http://goto/soy-param-migration
450+
* @param {!proto.HealthCheckUpRequest} msg The msg instance to transform.
451+
* @return {!Object}
452+
* @suppress {unusedLocalVariables} f is only used for nested messages
453+
*/
454+
proto.HealthCheckUpRequest.toObject = function(includeInstance, msg) {
455+
var f, obj = {
456+
memberName: jspb.Message.getFieldWithDefault(msg, 1, "")
457+
};
458+
459+
if (includeInstance) {
460+
obj.$jspbMessageInstance = msg;
461+
}
462+
return obj;
463+
};
464+
}
465+
466+
467+
/**
468+
* Deserializes binary data (in protobuf wire format).
469+
* @param {jspb.ByteSource} bytes The bytes to deserialize.
470+
* @return {!proto.HealthCheckUpRequest}
471+
*/
472+
proto.HealthCheckUpRequest.deserializeBinary = function(bytes) {
473+
var reader = new jspb.BinaryReader(bytes);
474+
var msg = new proto.HealthCheckUpRequest;
475+
return proto.HealthCheckUpRequest.deserializeBinaryFromReader(msg, reader);
476+
};
477+
478+
479+
/**
480+
* Deserializes binary data (in protobuf wire format) from the
481+
* given reader into the given message object.
482+
* @param {!proto.HealthCheckUpRequest} msg The message object to deserialize into.
483+
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
484+
* @return {!proto.HealthCheckUpRequest}
485+
*/
486+
proto.HealthCheckUpRequest.deserializeBinaryFromReader = function(msg, reader) {
487+
while (reader.nextField()) {
488+
if (reader.isEndGroup()) {
489+
break;
490+
}
491+
var field = reader.getFieldNumber();
492+
switch (field) {
493+
case 1:
494+
var value = /** @type {string} */ (reader.readString());
495+
msg.setMemberName(value);
496+
break;
497+
default:
498+
reader.skipField();
499+
break;
500+
}
501+
}
502+
return msg;
503+
};
504+
505+
506+
/**
507+
* Serializes the message to binary data (in protobuf wire format).
508+
* @return {!Uint8Array}
509+
*/
510+
proto.HealthCheckUpRequest.prototype.serializeBinary = function() {
511+
var writer = new jspb.BinaryWriter();
512+
proto.HealthCheckUpRequest.serializeBinaryToWriter(this, writer);
513+
return writer.getResultBuffer();
514+
};
515+
516+
517+
/**
518+
* Serializes the given message to binary data (in protobuf wire
519+
* format), writing to the given BinaryWriter.
520+
* @param {!proto.HealthCheckUpRequest} message
521+
* @param {!jspb.BinaryWriter} writer
522+
* @suppress {unusedLocalVariables} f is only used for nested messages
523+
*/
524+
proto.HealthCheckUpRequest.serializeBinaryToWriter = function(message, writer) {
525+
var f = undefined;
526+
f = message.getMemberName();
527+
if (f.length > 0) {
528+
writer.writeString(
529+
1,
530+
f
531+
);
532+
}
533+
};
534+
535+
536+
/**
537+
* optional string member_name = 1;
538+
* @return {string}
539+
*/
540+
proto.HealthCheckUpRequest.prototype.getMemberName = function() {
541+
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, ""));
542+
};
543+
544+
545+
/** @param {string} value */
546+
proto.HealthCheckUpRequest.prototype.setMemberName = function(value) {
547+
jspb.Message.setProto3StringField(this, 1, value);
548+
};
549+
550+
551+
552+
/**
553+
* Generated by JsPbCodeGenerator.
554+
* @param {Array=} opt_data Optional initial data array, typically from a
555+
* server response, or constructed directly in Javascript. The array is used
556+
* in place and becomes part of the constructed object. It is not cloned.
557+
* If no data is provided, the constructed object will be empty, but still
558+
* valid.
559+
* @extends {jspb.Message}
560+
* @constructor
561+
*/
562+
proto.PrinterHealthStatus = function(opt_data) {
563+
jspb.Message.initialize(this, opt_data, 0, -1, null, null);
564+
};
565+
goog.inherits(proto.PrinterHealthStatus, jspb.Message);
566+
if (goog.DEBUG && !COMPILED) {
567+
proto.PrinterHealthStatus.displayName = 'proto.PrinterHealthStatus';
568+
}
569+
570+
571+
if (jspb.Message.GENERATE_TO_OBJECT) {
572+
/**
573+
* Creates an object representation of this proto suitable for use in Soy templates.
574+
* Field names that are reserved in JavaScript and will be renamed to pb_name.
575+
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
576+
* For the list of reserved names please see:
577+
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
578+
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance
579+
* for transitional soy proto support: http://goto/soy-param-migration
580+
* @return {!Object}
581+
*/
582+
proto.PrinterHealthStatus.prototype.toObject = function(opt_includeInstance) {
583+
return proto.PrinterHealthStatus.toObject(opt_includeInstance, this);
584+
};
585+
586+
587+
/**
588+
* Static version of the {@see toObject} method.
589+
* @param {boolean|undefined} includeInstance Whether to include the JSPB
590+
* instance for transitional soy proto support:
591+
* http://goto/soy-param-migration
592+
* @param {!proto.PrinterHealthStatus} msg The msg instance to transform.
593+
* @return {!Object}
594+
* @suppress {unusedLocalVariables} f is only used for nested messages
595+
*/
596+
proto.PrinterHealthStatus.toObject = function(includeInstance, msg) {
597+
var f, obj = {
598+
message: jspb.Message.getFieldWithDefault(msg, 1, "")
599+
};
600+
601+
if (includeInstance) {
602+
obj.$jspbMessageInstance = msg;
603+
}
604+
return obj;
605+
};
606+
}
607+
608+
609+
/**
610+
* Deserializes binary data (in protobuf wire format).
611+
* @param {jspb.ByteSource} bytes The bytes to deserialize.
612+
* @return {!proto.PrinterHealthStatus}
613+
*/
614+
proto.PrinterHealthStatus.deserializeBinary = function(bytes) {
615+
var reader = new jspb.BinaryReader(bytes);
616+
var msg = new proto.PrinterHealthStatus;
617+
return proto.PrinterHealthStatus.deserializeBinaryFromReader(msg, reader);
618+
};
619+
620+
621+
/**
622+
* Deserializes binary data (in protobuf wire format) from the
623+
* given reader into the given message object.
624+
* @param {!proto.PrinterHealthStatus} msg The message object to deserialize into.
625+
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
626+
* @return {!proto.PrinterHealthStatus}
627+
*/
628+
proto.PrinterHealthStatus.deserializeBinaryFromReader = function(msg, reader) {
629+
while (reader.nextField()) {
630+
if (reader.isEndGroup()) {
631+
break;
632+
}
633+
var field = reader.getFieldNumber();
634+
switch (field) {
635+
case 1:
636+
var value = /** @type {string} */ (reader.readString());
637+
msg.setMessage(value);
638+
break;
639+
default:
640+
reader.skipField();
641+
break;
642+
}
643+
}
644+
return msg;
645+
};
646+
647+
648+
/**
649+
* Serializes the message to binary data (in protobuf wire format).
650+
* @return {!Uint8Array}
651+
*/
652+
proto.PrinterHealthStatus.prototype.serializeBinary = function() {
653+
var writer = new jspb.BinaryWriter();
654+
proto.PrinterHealthStatus.serializeBinaryToWriter(this, writer);
655+
return writer.getResultBuffer();
656+
};
657+
658+
659+
/**
660+
* Serializes the given message to binary data (in protobuf wire
661+
* format), writing to the given BinaryWriter.
662+
* @param {!proto.PrinterHealthStatus} message
663+
* @param {!jspb.BinaryWriter} writer
664+
* @suppress {unusedLocalVariables} f is only used for nested messages
665+
*/
666+
proto.PrinterHealthStatus.serializeBinaryToWriter = function(message, writer) {
667+
var f = undefined;
668+
f = message.getMessage();
669+
if (f.length > 0) {
670+
writer.writeString(
671+
1,
672+
f
673+
);
674+
}
675+
};
676+
677+
678+
/**
679+
* optional string message = 1;
680+
* @return {string}
681+
*/
682+
proto.PrinterHealthStatus.prototype.getMessage = function() {
683+
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, ""));
684+
};
685+
686+
687+
/** @param {string} value */
688+
proto.PrinterHealthStatus.prototype.setMessage = function(value) {
689+
jspb.Message.setProto3StringField(this, 1, value);
690+
};
691+
692+
407693
goog.object.extend(exports, proto);

0 commit comments

Comments
 (0)