#!/usr/bin/env python
# -*- coding: utf-8 -*-


import sys

import RTC
import OpenRTM_aist

confcallback_spec = ["implementation_id", "ConfCallback",
                  "type_name",         "ConfCallback",
                  "description",       "Console input component",
                  "version",           "1.0",
                  "vendor",            "Sample",
                  "category",          "example",
                  "activity_type",     "DataFlowComponent",
                  "max_instance",      "10",
                  "language",          "Python",
                  "lang_type",         "script",
                  "conf.default.test", "10",
                  
                  ""]





class MyConfigurationSetListener(OpenRTM_aist.ConfigurationSetListener):

   def __init__(self, name):
        print name
        self.name = name

   def __call__(self, config_param_name):
        print self.name, str(config_param_name)


class MyConfigurationParamListener(OpenRTM_aist.ConfigurationParamListener):

   def __init__(self, name):
        self.name = name

   def __call__(self, config_set_name, config_param_name):
        print self.name ,str(config_set_name), str(config_param_name)


class MyConfigurationSetNameListener(OpenRTM_aist.ConfigurationSetNameListener):

   def __init__(self, name):
        self.name = name

   def __call__(self, config_set_name):
        print self.name ,str(config_set_name)
  

class ConfCallback(OpenRTM_aist.DataFlowComponentBase):
  def __init__(self, manager):
    OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
    self.test = ["10"]
    self.test2 = ["10"]

    
    return

  def onInitialize(self):
    self.addConfigurationSetListener(OpenRTM_aist.ConfigurationSetListenerType.ON_SET_CONFIG_SET, MyConfigurationSetListener("ON_SET_CONFIG_SET"))
    self.addConfigurationSetListener(OpenRTM_aist.ConfigurationSetListenerType.ON_ADD_CONFIG_SET , MyConfigurationSetListener("ON_ADD_CONFIG_SET"))

    self.addConfigurationParamListener(OpenRTM_aist.ConfigurationParamListenerType.ON_UPDATE_CONFIG_PARAM, MyConfigurationParamListener("ON_UPDATE_CONFIG_PARAM"))

    
    self.addConfigurationSetNameListener(OpenRTM_aist.ConfigurationSetNameListenerType.ON_UPDATE_CONFIG_SET, MyConfigurationSetNameListener("ON_UPDATE_CONFIG_SET"))
    self.addConfigurationSetNameListener(OpenRTM_aist.ConfigurationSetNameListenerType.ON_REMOVE_CONFIG_SET, MyConfigurationSetNameListener("ON_REMOVE_CONFIG_SET"))
    self.addConfigurationSetNameListener(OpenRTM_aist.ConfigurationSetNameListenerType.ON_ACTIVATE_CONFIG_SET, MyConfigurationSetNameListener("ON_ACTIVATE_CONFIG_SET"))

    self.bindParameter("test", self.test, "10")
    
    

    
    
    return RTC.RTC_OK

        
  def onExecute(self, ec_id):
    
    return RTC.RTC_OK

  

  


def ConfCallbackInit(manager):
  profile = OpenRTM_aist.Properties(defaults_str=confcallback_spec)
  manager.registerFactory(profile,
                          ConfCallback,
                          OpenRTM_aist.Delete)


def MyModuleInit(manager):
  ConfCallbackInit(manager)

  # Create a component
  comp = manager.createComponent("ConfCallback")

def main():

  mgr = OpenRTM_aist.Manager.init(sys.argv)


  mgr.setModuleInitProc(MyModuleInit)


  mgr.activateManager()

  mgr.runManager()


if __name__ == "__main__":
  main()
