/**
 * mindc examples
 *
 * Copyright (C) 2010 STMicroelectronics
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 * Contact: mind@ow2.org
 *
 * Authors: Matthieu Leclercq
 */

import boot.ApplicationType;
import boot.Main;
import memory.Malloc;

/**
 * Application composite component.
 * This ADL describe the initial architecture of the application. This 
 * architecture will be updated dynamically by the instantiator component.
 */
composite factory.FactoryExample extends ApplicationType {

  /**
   * The instantiator component. Initialy, this component is bound to the 
   * simpleApp component (through the "applicationEntryPoint" required 
   * interface, but dynamically, it will instantiate a Forwarder component and
   * introduce the latter between its "applicationEntryPoint" required interface
   * and the simpleApp component.
   */
  contains Instantiator as instantiator;
  
  /**
   * The simpleApp component. 
   *
   * This component is described using a "anonymous definition". This means that
   * the architecture of the simpleApp component is not described in a separated
   * ADL file, but is in-lined in the surrounding ADL.
   * So the simpleApp component is a primitive component that extends 
   * boot.ApplicationType. Moreover, the implementation of this primitive 
   * component is also in-lined in the ADL using the "source {{ ... }}" 
   * construct.
   */
  contains ApplicationType as simpleApp primitive {
    source {{
      #include <stdio.h>
      
      // int main(int argc, string[] argv)
      int METH(entryPoint, main) (int argc, char *argv[]) {
        printf("In simpleApp.\n");
        return 0;
      }
    }}
  }

  /**
   * The forwarderFactory component is a factory of Forwarder component. This
   * component provides a "factory" interface that allows to create/destroy
   * components whose architecture is described by the Forwarder ADL.
   */
  contains Factory<Forwarder> as forwarderFactory;
  
  /**
   * The memory allocator component used by factory to allocate/free memory
   */
  contains Malloc as allocator;
  
  
  binds this.entryPoint to instantiator.entryPoint;
  binds instantiator.applicationEntryPoint to simpleApp.entryPoint;
  binds instantiator.forwarderFactory to forwarderFactory.factory;
  binds forwarderFactory.allocator to allocator.allocator;
}