2323#include " uv.h"
2424#include " ibmras/monitoring/AgentExtensions.h"
2525#include " plugins/node/prof/watchdog.h"
26+ #include " headlessutils.h"
2627
2728#if NODE_VERSION_AT_LEAST(0, 11, 0) // > v0.11+
2829#include " objecttracker.hpp"
@@ -298,13 +299,27 @@ NAN_METHOD(setOption) {
298299 }
299300}
300301
302+ // get property
303+ NAN_METHOD (getOption) {
304+ if (info.Length () > 0 ) {
305+ Local<String> value = info[0 ]->ToString ();
306+ std::string property = loaderApi->getProperty (toStdString (value).c_str ());
307+ v8::Local<v8::String> v8str = v8::String::NewFromUtf8 (v8::Isolate::GetCurrent (), property.c_str ());
308+ info.GetReturnValue ().Set <v8::String>(v8str);
309+ } else {
310+ loaderApi->logMessage (warning, " Incorrect number of parameters passed to getOption" );
311+ }
312+ }
313+
301314NAN_METHOD (start) {
302315 if (!running) {
303316 running = true ;
304317
305318 loaderApi->init ();
306319
307320 loaderApi->start ();
321+
322+ headless::start ();
308323 }
309324 if (!initMonitorApi ()) {
310325 loaderApi->logMessage (warning, " Failed to initialize monitoring API" );
@@ -319,6 +334,7 @@ NAN_METHOD(stop) {
319334 running = false ;
320335 loaderApi->stop ();
321336 loaderApi->shutdown ();
337+ headless::stop ();
322338 }
323339
324340}
@@ -492,6 +508,13 @@ NAN_METHOD(sendControlCommand) {
492508
493509}
494510
511+ NAN_METHOD (setHeadlessZipFunction) {
512+ if (!info[0 ]->IsFunction ()) {
513+ return Nan::ThrowError (" First argument must be a function" );
514+ }
515+ Nan::Callback *callback = new Nan::Callback (info[0 ].As <Function>());
516+ headless::setZipFunction (callback);
517+ }
495518
496519NAN_METHOD (localConnect) {
497520 if (!isMonitorApiValid ()) {
@@ -624,6 +647,10 @@ static bool isGlobalAgentAlreadyLoaded(Local<Object> module) {
624647 return false ;
625648}
626649
650+ void zip (const char * outputDir) {
651+ headless::zip (outputDir);
652+ }
653+
627654void init (Local<Object> exports, Local<Object> module ) {
628655 /*
629656 * Throw an error if appmetrics has already been loaded globally
@@ -644,13 +671,15 @@ void init(Local<Object> exports, Local<Object> module) {
644671 /*
645672 * Set exported functions
646673 */
674+ exports->Set (Nan::New<String>(" getOption" ).ToLocalChecked (), Nan::New<FunctionTemplate>(getOption)->GetFunction ());
647675 exports->Set (Nan::New<String>(" setOption" ).ToLocalChecked (), Nan::New<FunctionTemplate>(setOption)->GetFunction ());
648676 exports->Set (Nan::New<String>(" start" ).ToLocalChecked (), Nan::New<FunctionTemplate>(start)->GetFunction ());
649677 exports->Set (Nan::New<String>(" spath" ).ToLocalChecked (), Nan::New<FunctionTemplate>(spath)->GetFunction ());
650678 exports->Set (Nan::New<String>(" stop" ).ToLocalChecked (), Nan::New<FunctionTemplate>(stop)->GetFunction ());
651679 exports->Set (Nan::New<String>(" localConnect" ).ToLocalChecked (), Nan::New<FunctionTemplate>(localConnect)->GetFunction ());
652680 exports->Set (Nan::New<String>(" nativeEmit" ).ToLocalChecked (), Nan::New<FunctionTemplate>(nativeEmit)->GetFunction ());
653681 exports->Set (Nan::New<String>(" sendControlCommand" ).ToLocalChecked (), Nan::New<FunctionTemplate>(sendControlCommand)->GetFunction ());
682+ exports->Set (Nan::New<String>(" setHeadlessZipFunction" ).ToLocalChecked (), Nan::New<FunctionTemplate>(setHeadlessZipFunction)->GetFunction ());
654683#if defined(_LINUX)
655684 exports->Set (Nan::New<String>(" lrtime" ).ToLocalChecked (), Nan::New<FunctionTemplate>(lrtime)->GetFunction ());
656685#endif
@@ -670,6 +699,7 @@ void init(Local<Object> exports, Local<Object> module) {
670699 if (!loadProperties ()) {
671700 loaderApi->logMessage (warning, " Failed to load appmetrics.properties file" );
672701 }
702+ loaderApi->registerZipFunction (&zip);
673703 loaderApi->setLogLevels ();
674704 /* changing this to pass agentcore.version and adding new appmetrics.version for use in the client */
675705 loaderApi->setProperty (" agentcore.version" , loaderApi->getAgentVersion ());
0 commit comments