/*
 * Autopsy Forensic Browser
 * 
 * Copyright 2011 Basis Technology Corp.
 * Contact: carrier <at> sleuthkit <dot> org
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package org.sleuthkit.autopsy.ingest;

import org.sleuthkit.autopsy.coreutils.Logger;


/**
 * Services available to ingest modules via singleton instance,
 * e.g. for logging, interacting with the ingest manager
 * sending data events notifications, ingest messages, getting configurations, etc.
 * 
 */
public class IngestServices {
    
    private IngestManager manager;
    
    private static IngestServices instance;
    
    private IngestServices() {
        this.manager = IngestManager.getDefault();
    }
    
    /**
     * Get handle to module services
     * @return the services handle
     */
    public static synchronized IngestServices getDefault() {
        if (instance == null) {
            instance = new IngestServices();
        }
        return instance;
    }
    
    
    /**
     * Get a logger to be used by the module to log messages to log files
     * @param module module to get the logger for
     * @return logger object
     */
    public Logger getLogger(IngestModuleAbstract module) {
        return Logger.getLogger(module.getName());
    }
    
    /**
     * Post ingest message
     * @param message ingest message to be posted by ingest module
     */
    public void postMessage(final IngestMessage message) {
        manager.postMessage(message);
    }
    
    /**
     * Fire module event to notify registered module event listeners
     * @param eventType the event type, defined in IngestManager.IngestManagerEvents
     * @param moduleName the module name
     */
    public void fireModuleEvent(String eventType, String moduleName) {
        IngestManager.fireModuleEvent(eventType, moduleName);
    }

    
    /**
     * Fire module data event to notify registered module data event listeners
     * @param moduleDataEvent module data event, encapsulating blackboard artifact data
     */
    public void fireModuleDataEvent(ModuleDataEvent moduleDataEvent) {
        IngestManager.fireModuleDataEvent(moduleDataEvent);
    }
    
    
    
    /**
     * Facility for a file ingest module to check a return value from another file ingest module
     * that executed for the same file earlier in the file ingest pipeline
     * The module return value can be used as a guideline to skip processing the file
     * 
     * @param moduleName registered module name of the module to check the return value of
     * @return the return value of the previously executed module for the currently processed file in the file ingest pipeline
     */
    public IngestModuleAbstractFile.ProcessResult getAbstractFileModuleResult(String moduleName) {
        return manager.getAbstractFileModuleResult(moduleName);
    }
    
    
    
    
    
}

@@ -720,16 +720,38 @@
 ngest;%0A%0A
+import java.util.Map;%0A
 import o
@@ -789,16 +789,71 @@
 Logger;%0A
+import org.sleuthkit.autopsy.coreutils.ModuleSettings;%0A
 %0A%0A/**%0A *
@@ -921,16 +921,15 @@
 %0A * 
-e.g. for
+for:%0A *
  log
@@ -1007,24 +1007,32 @@
 cations,
+ sending
  ingest 
 messages
@@ -1019,24 +1019,30 @@
 ding ingest 
+inbox 
 messages, ge
@@ -1038,16 +1038,19 @@
 essages,
+%0A *
  getting
@@ -1050,16 +1050,35 @@
 getting 
+and setting module 
 configur
@@ -1087,14 +1087,8 @@
 ions
-, etc.
 %0A * 
@@ -3451,32 +3451,1648 @@
 me);%0A    %7D%0A    %0A
+    /**%0A     * Gets a configuration setting for a module%0A     * @param moduleName moduleName identifier unique to that module%0A     * @param settingName setting name to retrieve%0A     * @return setting value for the module / setting name%0A     */%0A    public String getConfigSetting(String moduleName, String settingName) %7B%0A        return ModuleSettings.getConfigSetting(moduleName, settingName);%0A    %7D%0A    %0A    /**%0A     * Sets a configuration setting for a module%0A     * @param moduleName moduleName identifier unique to that module%0A     * @param settingName setting name to set%0A     * @param settingVal setting value to set%0A     */%0A    public void setConfigSetting(String moduleName, String settingName, String settingVal) %7B%0A        ModuleSettings.setConfigSetting(moduleName, settingName, settingVal);%0A    %7D%0A    %0A    /**%0A     * Gets configuration settings for a module%0A     * @param moduleName moduleName identifier unique to that module%0A     * @return settings for the module / setting name%0A     */%0A    public Map%3CString,String%3E getConfigSettings(String moduleName) %7B%0A        return ModuleSettings.getConfigSettings(moduleName);%0A    %7D%0A    %0A   /**%0A     * Sets configuration settings for a module, while preserving the module settings not specified%0A     * to be set.%0A     * @param moduleName moduleName identifier unique to that module%0A     * @param settings settings to set and replace old settings, keeping settings not specified in the map.%0A     * %0A     */%0A    public void setConfigSettings(String moduleName, Map%3CString,String%3Esettings) %7B%0A        ModuleSettings.setConfigSettings(moduleName, settings);%0A    %7D%0A    %0A
     %0A    %0A    %0A 

add settings support to ingest services