C++ API Reference
autoLoader/autoLoader.cpp
//
// Copyright 2012 Autodesk, Inc. All rights reserved.
//
// Use of this software is subject to the terms of the Autodesk license
// agreement provided at the time of installation or download, or which
// otherwise accompanies this software in either electronic or hard copy form.
//
//-----------------------------------------------------------------------------
#include <maya/MFnPlugin.h>
#include <maya/MTypes.h>
#include <maya/MSceneMessage.h>
#include <maya/MGlobal.h>
#include <maya/MCommonSystemUtils.h>
#include "threadData.h"
#include "moduleLogic.h"
#include "moduleLogicCmd.h"
namespace {
bool isAutoLoaderPollingEnabled()
{
// Default is OFF. This avoids periodic background command execution which can
// prevent Maya from reaching a pure license-idle state.
MString val = MCommonSystemUtils::getEnv("AUTOLOADER_ENABLE_POLLING");
val = val.toLowerCase();
return (val == "1" || val == "true" || val == "yes" || val == "on");
}
}
//-----------------------------------------------------------------------------
MCallbackId mayaExitingId =0 ;
void mayaExitingCB (void *clientData) {
#ifdef AUTOLOADER_THREAD
{
threadData::stopThread () ;
}
#endif
}
//-----------------------------------------------------------------------------
//- initializePlugin is called when the plug-in is loaded into Maya. It
//- registers all of the services that this plug-in provides with Maya.
//- obj - a handle to the plug-in object (use MFnPlugin to access it)
MStatus initializePlugin (MObject obj) {
MFnPlugin plugin (obj, PLUGIN_COMPANY, _T("1.0"), _T("Any")) ;
// Before launching the module detection, we need to collected the ones
// already present.
MModuleLogic::ModuleDetectionLogicInit (threadData::getThreadData ()) ;
plugin.registerCommand (kmoduleLogicCmdName, moduleLogicCmd::creator) ;
plugin.registerCommand (kautoLoaderRescanCmdName, moduleLogicCmd::creator) ;
{
// Run a single scan on startup to discover packaged modules/plugins without
// enabling periodic background polling by default.
MModuleLogic::ModuleDetectionLogicCmdExecute (threadData::getThreadData ()) ;
#ifdef AUTOLOADER_THREAD
// Opt-in: re-enable the legacy polling thread for debugging/regression triage.
if (isAutoLoaderPollingEnabled())
{
threadData::startThread () ;
}
#endif
}
mayaExitingId =MSceneMessage::addCallback (MSceneMessage::kMayaExiting, mayaExitingCB) ;
return (MS::kSuccess) ;
}
//- uninitializePlugin is called when the plug-in is unloaded from Maya. It
//- deregisters all of the services that it was providing.
//- obj - a handle to the plug-in object (use MFnPlugin to access it)
MStatus uninitializePlugin (MObject obj) {
MFnPlugin plugin (obj) ;
#ifdef AUTOLOADER_THREAD
{
threadData::stopThread () ;
}
#endif
plugin.deregisterCommand (kautoLoaderRescanCmdName) ;
plugin.deregisterCommand (kmoduleLogicCmdName) ;
return (MS::kSuccess) ;
}