## Getting Carbide Project Information

The following example code fragment demonstrates the use of Carbide.c++ APIs to access Carbide project information.

NOTE There are two perspective IDs that may be useful when using the Carbide APIs. The perspective ID for the Carbide.c++ perspective is com.nokia.carbide.cpp.CarbideCppPerspective and for the Debug view it is org.eclipse.debug.ui.DebugPerspective.

Retrieving Carbide.c++ project information starts with knowing your org.eclipse.core.resources.IProject resource and retrieving the com.nokia.carbide.cdt.builder.ICarbideBuildManager instance:

ICarbideBuildManager buildMgr = ICarbideBuilderPlugin.getBuildManager();

Now with your IProject resource you can grab the actual Carbide project in com.nokia.carbide.cdt.builder.ICarbideProjectInfo:

// Assumes IProject (project) is known.
ICarbideProjectInfo cpi = null;
if (buildMgr.isCarbideProject(project)){
// check to make sure this is a Carbide project
cpi = buildMgr.getProjectInfo(project);
}

Once you get the ICarbideProjectInfo object you can access all the project data, such as environment variables and SIS builder information via the com.nokia.carbide.cdt.builder.ICarbideBuildConfiguration interface. You can retrieve either the default configuration or the full list:

// Get the default build configuration
ICarbideBuildConfiguration defaultConfig = cpi.getDefaultConfiguration();
// Get all configurations for this project.
List<ICarbideBuildConfiguration> configList = cpi.getBuildConfigurations();

It is important to note that the data retrieved by the ICarbideBuildConfiguration object is what you see in the project properties pages under the Carbide.c++ group. This is separate from the data in the INF and MMP files.

### Retrieving INF/MMP Project Information

All Carbide build stages, with the exception of the post-link SIS Builder stage get their data from INF and MMP files. So naturally Carbide needs a way to retrieve and store this data for doing things like setting up the source indexer and displaying the visual INF and MMP editors. The com.nokia.carbide.cdt.builder.EpocEngineHelper class is a good first stop to retrieve this information. For example, if you want to get all the source files in the first MMP file:

    // ...assumes ICarbideProjectInformation (cpi) is known.
    List<IPath> mmpPaths = EpocEngineHelper.getMMPFilesForProject(cpi);
    // array length check omitted for brevity....
    List<IPath> srcFilesTest = EpocEngineHelper.getSourceFilesForConfiguration(defultConfig, mmpPaths.get(0));

### SDK Management

Each SDK entry in devices.xml is analogous to a com.nokia.carbide.cpp.sdk.core.ISymbianSDK object. If you want to get the entire list of ISymbianSDK objects (same list and properties from the SDK Preferences page) you simply invoke:

    ISDKManager sdkMgr = SDKCorePlugin.getSDKManager();
    List<ISymbianSDK> sdkList = sdkMgr.getSDKList();

Now you can iterate the list and get whatever information you want out of the installed SDKs. For example, using Java 5 iterators we can get the EPOCROOT values of all the SDKs:

    for (ISymbianSDK currSDK : sdkList){
       String epocRootStr = currSDK.getEPOCROOT();
    }

### Reading MMP Statements with the EpocEngine and IMMPData

This topic demonstrates how you can read the MMP data for any build configuration (ICarbideBuildConfiguration). The main interface for retrieving MMP data is com.nokia.carbide.cpp.epoc.engine.model.mmp.IMMPData. Once you get access to this interface you can learn anything you want about a particular MMP file.

Prerequisite: All MMP and bld.inf parsing requires a dependency to the plugin com.nokia.carbide.cpp.epoc.engine.

Typically most keywords of interest are either single string settings (TARGETTYPE, TARGET, EPOCSTACKSIZE) or list of settings (MACRO, CAPABILITY, LANG). Other types can be directly retrieved from IMMPData routines. Check the API documentation for specifics.

The example provided simply iterates through all the MMP files of a particular build configuration and grabs a list value and single item setting. You'll need to get the particular MMP file you are interested in. Play around with the IMMPData object in the run method and you can quickly get the idea.

    // Assumes buildConfig (ICarbideBuildConfiguration) is known
    for (IPath mmpPath : EpocEngineHelper.getMMPFilesForBuildConfiguration(buildConfig)) {
         Object data = EpocEnginePlugin.runWithMMPData(mmpPath,  new
                                  DefaultMMPViewConfiguration(buildConfig.getCarbideProject().getProject(),
                                  buildConfig, new AcceptedNodesViewFilter()),  new MMPDataRunnableAdapter() {
                            public Object run(IMMPData mmpData) {
                              // Example, getting a keyword as a list of strings
                              List macros = mmpData.getListArgumentSettings().get(EMMPStatement.MACRO);
                              // The real return value, getting a single argument setting
                             return mmpData.getSingleArgumentSettings().get(EMMPStatement.TARGETTYPE);
    		  	                }
          });
    // Make sure to test for and cast to proper Object type!
    String mmpStatement = (String)data;  // Now we should have the TARGETTYPE
    }