Return-Path: X-Original-To: apmail-celix-commits-archive@www.apache.org Delivered-To: apmail-celix-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D8F1018E2D for ; Thu, 14 Jan 2016 07:40:08 +0000 (UTC) Received: (qmail 83206 invoked by uid 500); 14 Jan 2016 07:40:08 -0000 Delivered-To: apmail-celix-commits-archive@celix.apache.org Received: (qmail 83180 invoked by uid 500); 14 Jan 2016 07:40:08 -0000 Mailing-List: contact commits-help@celix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@celix.apache.org Delivered-To: mailing list commits@celix.apache.org Received: (qmail 83171 invoked by uid 99); 14 Jan 2016 07:40:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jan 2016 07:40:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 69CC1E0A96; Thu, 14 Jan 2016 07:40:08 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: bpetri@apache.org To: commits@celix.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: celix git commit: CELIX-236: adapted celix-bootstrap to use yaml instead of json to be able to cog the yaml files as well. Added auto completion for the celix installation directory as well as the include files, service names and serivce types. Added ser Date: Thu, 14 Jan 2016 07:40:08 +0000 (UTC) Repository: celix Updated Branches: refs/heads/feature/CELIX-236_celix-boostrap 5d703d3ae -> 4feeabc59 CELIX-236: adapted celix-bootstrap to use yaml instead of json to be able to cog the yaml files as well. Added auto completion for the celix installation directory as well as the include files, service names and serivce types. Added service header generation for bundle services. Added error handling in case no provided/depended services are given. Project: http://git-wip-us.apache.org/repos/asf/celix/repo Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/4feeabc5 Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/4feeabc5 Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/4feeabc5 Branch: refs/heads/feature/CELIX-236_celix-boostrap Commit: 4feeabc5999466be41eb28de30015af05a91adc9 Parents: 5d703d3 Author: Bjoern Petri Authored: Thu Jan 14 08:24:18 2016 +0100 Committer: Bjoern Petri Committed: Thu Jan 14 08:24:18 2016 +0100 ---------------------------------------------------------------------- .../celix/bootstrap/argument_parser.py | 17 +-- celix-bootstrap/celix/bootstrap/generators.py | 71 +++++------ .../bootstrap/templates/bundle/CMakeLists.txt | 8 +- .../bootstrap/templates/bundle/bundle.json | 18 --- .../bootstrap/templates/bundle/bundle.yaml | 66 ++++++++++ .../templates/bundle/bundle_activator.c | 126 ++++++++++--------- .../bootstrap/templates/bundle/component.c | 22 +++- .../bootstrap/templates/bundle/component.h | 21 +++- .../bootstrap/templates/bundle/deploy.cmake | 4 +- .../celix/bootstrap/templates/bundle/service.h | 58 +++++++++ .../bootstrap/templates/project/CMakeLists.txt | 21 ++-- .../bootstrap/templates/project/project.json | 4 - .../bootstrap/templates/project/project.yaml | 19 +++ .../bootstrap/templates/services/service.h | 48 ------- .../bootstrap/templates/services/services.json | 4 - 15 files changed, 305 insertions(+), 202 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/celix/blob/4feeabc5/celix-bootstrap/celix/bootstrap/argument_parser.py ---------------------------------------------------------------------- diff --git a/celix-bootstrap/celix/bootstrap/argument_parser.py b/celix-bootstrap/celix/bootstrap/argument_parser.py index 6919e9a..922d98c 100644 --- a/celix-bootstrap/celix/bootstrap/argument_parser.py +++ b/celix-bootstrap/celix/bootstrap/argument_parser.py @@ -3,15 +3,11 @@ import os import argparse from . import generators -#TODO add support to add licence text to all created files -#TODO add support to select pthread or celix_threads - def main() : parser = argparse.ArgumentParser("celix-bootstrap") CREATE_PROJECT_COMMAND = "create_project" CREATE_BUNDLE_COMMAND = "create_bundle" - CREATE_SERVICE_COMMAND = "create_services" UPDATE_COMMAND = "update" @@ -31,8 +27,6 @@ def main() : gm.createBundle() elif args.command == CREATE_PROJECT_COMMAND : gm.createProject() - elif args.command == CREATE_SERVICE_COMMAND : - gm.createServices() elif args.command == UPDATE_COMMAND : gm.update() else : @@ -44,13 +38,11 @@ class GeneratorMediator : gendir = None bundleGenerator = None projectGenerator = None - servicesGenerator = None def __init__(self, gendir, erase, template_dir) : self.gendir = gendir self.bundleGenerator = generators.Bundle(gendir, erase, template_dir) self.projectGenerator = generators.Project(gendir, erase, template_dir) - self.servicesGenerator = generators.Services(gendir, erase, template_dir) def createBundle(self) : self.bundleGenerator.create() @@ -58,16 +50,11 @@ class GeneratorMediator : def createProject(self) : self.projectGenerator.create() - def createServices(self) : - self.servicesGenerator.create() def update(self) : - if os.path.isfile(os.path.join(self.gendir, "bundle.json")) : + if os.path.isfile(os.path.join(self.gendir, "bundle.yaml")) : print("Generating/updating bundle code") self.bundleGenerator.update() - if os.path.isfile(os.path.join(self.gendir, "project.json")) : + if os.path.isfile(os.path.join(self.gendir, "project.yaml")) : print("Generating/updating project code") self.projectGenerator.update() - if os.path.isfile(os.path.join(self.gendir, "services.json")) : - print("Generating/updating services code") - self.servicesGenerator.update() http://git-wip-us.apache.org/repos/asf/celix/blob/4feeabc5/celix-bootstrap/celix/bootstrap/generators.py ---------------------------------------------------------------------- diff --git a/celix-bootstrap/celix/bootstrap/generators.py b/celix-bootstrap/celix/bootstrap/generators.py index 58e13df..7854f3f 100644 --- a/celix-bootstrap/celix/bootstrap/generators.py +++ b/celix-bootstrap/celix/bootstrap/generators.py @@ -1,10 +1,10 @@ import shutil import os import sys -import json +import yaml import cogapp -class BaseGenerator: +class BaseGenerator(object): gendir = None descriptor = None erase_cog = False @@ -15,7 +15,7 @@ class BaseGenerator: def __init__(self, gendir, profile, erase, template_dir) : self.gendir = gendir - self.descriptor = "%s/%s.json" % (gendir, profile) + self.descriptor = "%s/%s.yaml" % (gendir, profile) self.template_dir = os.path.join(os.getcwd(), os.path.dirname(__file__), "templates") self.profile = profile self.erase_cog = erase @@ -36,11 +36,11 @@ class BaseGenerator: def create(self) : if os.path.exists(self.descriptor) : - print("%s Already exists. Will not override existing %s.json" % (self.descriptor, self.profile)) + print("%s Already exists. Will not override existing %s.yaml" % (self.descriptor, self.profile)) else : if not os.path.exists(self.gendir) : os.makedirs(self.gendir) - shutil.copyfile(os.path.join(self.template_dir, self.profile, "%s.json" % self.profile), self.descriptor) + shutil.copyfile(os.path.join(self.template_dir, self.profile, "%s.yaml" % self.profile), self.descriptor) print("Edit the %s file and run 'celix-bootstrap update %s' to generate the source files" % (self.descriptor, self.gendir)) @@ -48,13 +48,15 @@ class BaseGenerator: if os.path.isdir(self.gendir) and os.path.exists(self.descriptor) : with open(self.descriptor) as inputFile : try : - return json.load(inputFile) + return yaml.load(inputFile) except ValueError as e: - print("ERROR: %s is not a valid json file: %s" % (self.descriptor, e)) + print("ERROR: %s is not a valid yaml file: %s" % (self.descriptor, e)) sys.exit(1) def update_file(self, template, targetFile, options=[], commentsPrefix="//") : + print("Creating file %s %s" % (self.gendir, targetFile)) cog_file = os.path.join(self.gendir, targetFile) +# cog_file = os.path.join('.', targetFile) if not os.path.exists(cog_file) : print("Creating file %s" % cog_file) if not os.path.exists(os.path.dirname(cog_file)) : @@ -77,7 +79,11 @@ class BaseGenerator: if self.erase_cog : cog_options += ["-d", "-o", cog_file, backup_cog_file] else : - cog_options += ["-r", "-e", "-s", " %s%s" %(commentsPrefix, self.gen_code_suffix), cog_file] + cog_options += ["-r", "-e" ] + if commentsPrefix is not None: + cog_options += [ "-s", " %s%s" %(commentsPrefix, self.gen_code_suffix)] + cog_options += [cog_file] + cog.main(cog_options) @@ -109,17 +115,29 @@ class Bundle(BaseGenerator): options = ["-D", "bundleFile=%s" % self.descriptor, "-D", "componentName=%s" % componentName] self.update_file("component.c", genfile, options) + def update_service_header(self, componentName, service) : + genfile = "public/include/%s" % service['include'] + options = ["-D", "bundleFile=%s" % self.descriptor, "-D", "componentName=%s" % componentName, "-D", "serviceName=%s" % service['name']] + self.update_file("service.h", genfile, options) + + def create(self) : + self.update_file(os.path.join(self.template_dir, self.profile, "%s.yaml" % self.profile), "%s.yaml" % self.profile, [], None) + def update(self) : bd = self.read_descriptor() if bd is None : - print("%s does not exist or does not contain a bundle.json file" % self.gendir) + print("%s does not exist or does not contain a bundle.yaml file" % self.gendir) else : self.update_cmakelists() self.update_deploy_file() self.update_activator() - for comp in bd['components'] : - self.update_component_header(comp['name']) - self.update_component_source(comp['name']) + if 'components' in bd and bd['components'] is not None: + for comp in bd['components'] : + self.update_component_header(comp['name']) + self.update_component_source(comp['name']) + if 'providedServices' in comp and comp['providedServices'] is not None: + for service in comp['providedServices']: + self.update_service_header(comp['name'], service) class Project(BaseGenerator): @@ -131,33 +149,12 @@ class Project(BaseGenerator): options = ["-D", "projectFile=%s" % self.descriptor] self.update_file("CMakeLists.txt", "CMakeLists.txt", options, "#") - def update(self) : - descriptor = self.read_descriptor() - if descriptor is None : - print("%s does not exist or does not contain a project.json file" % self.gendir) - else : - self.update_cmakelists() - - -class Services(BaseGenerator): - - def __init__(self, gendir, erase, template_dir) : - BaseGenerator.__init__(self, gendir, "services", erase, template_dir) - #python3 super(Services, self).__init__(gendir, "services") - - def update_cmakelists(self) : - options = ["-D", "projectFile=%s" % self.descriptor] - self.update_file("CMakeLists.txt", "CMakeLists.txt", options, "#") - - def update_service_header(self, serviceName) : - genfile = "public/include/%s.h" % serviceName - options = ["-D", "descriptorFile=%s" % self.descriptor, "-D", "serviceName=%s" % serviceName] - self.update_file("service.h", genfile, options) + def create(self) : + self.update_file(os.path.join(self.template_dir, self.profile, "%s.yaml" % self.profile), "%s.yaml" % self.profile, [], None) def update(self) : descriptor = self.read_descriptor() if descriptor is None : - print("%s does not exist or does not contain a services.json file" % self.gendir) + print("%s does not exist or does not contain a project.yaml file" % self.gendir) else : - for serv in descriptor : - self.update_service_header(serv['name']) + self.update_cmakelists() http://git-wip-us.apache.org/repos/asf/celix/blob/4feeabc5/celix-bootstrap/celix/bootstrap/templates/bundle/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/celix-bootstrap/celix/bootstrap/templates/bundle/CMakeLists.txt b/celix-bootstrap/celix/bootstrap/templates/bundle/CMakeLists.txt index 5bc1979..98c45f5 100644 --- a/celix-bootstrap/celix/bootstrap/templates/bundle/CMakeLists.txt +++ b/celix-bootstrap/celix/bootstrap/templates/bundle/CMakeLists.txt @@ -1,8 +1,12 @@ #{{ -#import json +#import yaml #bundle = None #with open(bundleFile) as input : -# bundle = json.load(input) +# bundle = yaml.load(input) +# +#if not 'components' in bundle or bundle['components'] is None: +# bundle['components'] = [] +# #}} #{{end}} http://git-wip-us.apache.org/repos/asf/celix/blob/4feeabc5/celix-bootstrap/celix/bootstrap/templates/bundle/bundle.json ---------------------------------------------------------------------- diff --git a/celix-bootstrap/celix/bootstrap/templates/bundle/bundle.json b/celix-bootstrap/celix/bootstrap/templates/bundle/bundle.json deleted file mode 100644 index 558bd72..0000000 --- a/celix-bootstrap/celix/bootstrap/templates/bundle/bundle.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name" : "mybundle", - "symbolicName": "org.example.mybundle", - "components" : [ - { - "name" : "example", - "serviceDependencies" : [ - { "include" : "log_service/log_service.h" , "name" : "logger", "service_name" : "OSGI_LOGSERVICE_NAME", "type" : "log_service_pt", "cardinality" : "one" }, - { "include" : "log_service/log_service.h" , "name" : "loggerOptional", "service_name" : "OSGI_LOGSERVICE_NAME", "type" : "log_service_pt", "cardinality" : "optional" }, - { "include" : "log_service/log_service.h" , "name" : "loggerMany", "filter" : "(objectClass=log_service)", "type" : "log_service_pt", "cardinality" : "many" } - ], - "providedServices" : [ - { "include" : "shell/command.h" , "name" : "command", "service_name" : "\"commandService\"", "type" : "command_service_pt" }, - { "include" : "shell/command.h" , "name" : "command2", "service_name" : "\"commandService\"", "type" : "command_service_pt" } - ] - } - ] -} http://git-wip-us.apache.org/repos/asf/celix/blob/4feeabc5/celix-bootstrap/celix/bootstrap/templates/bundle/bundle.yaml ---------------------------------------------------------------------- diff --git a/celix-bootstrap/celix/bootstrap/templates/bundle/bundle.yaml b/celix-bootstrap/celix/bootstrap/templates/bundle/bundle.yaml new file mode 100644 index 0000000..d85030d --- /dev/null +++ b/celix-bootstrap/celix/bootstrap/templates/bundle/bundle.yaml @@ -0,0 +1,66 @@ +#{{ +#from celix.bootstrap.celix_utils import * +#}} +#{{end}} + + +#{{ +# name = checkInput('\nPlease enter bundleName', '([a-zA-Z_][a-zA-Z0-9_]*)', 'mybundle') +# cog.out('name : \'%s\'' % name ) +#}} +name: 'mybundle' +#{{end}} + +#{{ +# symName = checkInput('\nPlease enter symbolicName', '([a-zA-Z_][a-zA-Z0-9_.]*)', 'org.example.mybundle') +# cog.out('symbolicName: \'%s\'' % symName ) +#}} +symbolicName: 'org.example.mybundle' +#{{end}} + +components: + #{{ + # + #while yn('Do you want to add ' + ('a' if 'componentName' not in vars() else 'another') + ' component?'): + # componentName = checkInput('\nPlease enter componentName', '([a-zA-Z_][a-zA-Z0-9_]*)', 'example') + # cog.outl('- name: \'%s\'' % componentName ) + # cog.outl(' providedServices:') + # while yn('Should component \'%s\' provide %s service?' % (componentName, 'a' if 'psInclude' not in vars() else 'another')): + # psServiceName1 = checkInput('(1) Please enter a name, which can be used for the filename and the include guards', '([a-zA-Z_][a-zA-Z0-9_]*)'); + # psServiceName2 = checkInput('(2) Please enter a name, which is used to register and lookup the service', '([a-zA-Z_][a-zA-Z0-9_]*)', (psServiceName1.lower() + ('_service' if not psServiceName1.endswith('_service') else ''))); + # psServiceType = checkInput('(3) Please enter a type', '([a-zA-Z_][a-zA-Z0-9_]*)', (psServiceName1.lower() + ('_service_pt' if not psServiceName1.endswith('_service_pt') else '')) ); + # psInclude = checkInput('(4) Please enter the name of the include file', '(.+?)(\.[^.]*$|$)', psServiceName1.lower() + '.h'); + # + # print("\n Summary:") + # print("\tname :\t%s" % (psServiceName1)) + # print("\tservice_name:\t%s" % (psServiceName2)) + # print("\tservice_type:\t%s" % (psServiceType)) + # print("\tinclude file:\t%s" % (psInclude)) + # if yn('Are those information correct?'): + # cog.outl(' - {include: \'%s\', name: \'%s\', service_name: \'%s\', type: \'%s\'}' % (psInclude, psServiceName1, psServiceName2, psServiceType)) + # else: + # print("Service was not added.") + # + # cog.outl(' serviceDependencies:') + # while yn('Should component \'%s\' depend on %s service?' % (componentName, 'a' if 'sdInclude' not in vars() else 'another')): + # sdInclude = checkInclude('(1) Please enter the include filename, which describes the service', '(.+?)(\.[^.]*$|$)'); + # sdServiceName1 = checkInput('(2) Please enter a name, which is used to generate the code', '([a-zA-Z_][a-zA-Z0-9_]*)'); + # sdServiceName2 = checkIncludeContent('(3) Please enter the variable/constants, which is used to register the service within the framework', sdInclude); + # sdServiceType = checkIncludeContent('(4) Please enter the type of the service', sdInclude); + # sdCardinality = checkInput('(5) Please enter the cardinality (one|many|optional)', '(one)|(many)|(optional)'); + # + # print("\n Summary:") + # print("\tname :\t%s" % (sdServiceName1)) + # print("\tservice_name:\t%s" % (sdServiceName2)) + # print("\tservice_type:\t%s" % (sdServiceType)) + # print("\tcardinality:\t%s" % (sdCardinality)) + # print("\tinclude file:\t%s" % (sdInclude)) + # if yn('Are those information correct?'): + # cog.outl(' - {include: \'%s\', name: \'%s\', service_name: \'%s\', type: \'%s\', cardinality: \'%s\'}' % (sdInclude, sdServiceName1, sdServiceName2, sdServiceType, sdCardinality)) + # else: + # print("Service dependency was not added.") + #}} + #{{end}} + + + http://git-wip-us.apache.org/repos/asf/celix/blob/4feeabc5/celix-bootstrap/celix/bootstrap/templates/bundle/bundle_activator.c ---------------------------------------------------------------------- diff --git a/celix-bootstrap/celix/bootstrap/templates/bundle/bundle_activator.c b/celix-bootstrap/celix/bootstrap/templates/bundle/bundle_activator.c index b946961..a62b1f0 100644 --- a/celix-bootstrap/celix/bootstrap/templates/bundle/bundle_activator.c +++ b/celix-bootstrap/celix/bootstrap/templates/bundle/bundle_activator.c @@ -1,10 +1,19 @@ //TODO update fields from Type to ForType //TODO improve names to camel case (e.g. from _add_logger_for_example to _addLoggerToExample) //{{ -//import json +//import yaml //bundle = None //with open(bundleFile) as input : -// bundle = json.load(input) +// bundle = yaml.load(input) +// +//if not 'components' in bundle or bundle['components'] is None: +// bundle['components'] = [] +//else: +// for comp in bundle['components'] : +// if not 'serviceDependencies' in comp or comp['serviceDependencies'] is None: +// comp['serviceDependencies'] = [] +// if not 'providedServices' in comp or comp['providedServices'] is None: +// comp['providedServices'] = [] //}} //{{end}} #include @@ -20,17 +29,11 @@ //{{ //for comp in bundle['components'] : // cog.outl("#include \"%s.h\"" % comp['name']) -// for service in comp['serviceDependencies'] : -// cog.outl("#include <%s>" % service['include']) // for service in comp['providedServices'] : // cog.outl("#include <%s>" % service['include']) +// for service in comp['serviceDependencies'] : +// cog.outl("#include <%s>" % service['include']) //}} -#include "example.h" //do not edit, generated code -#include //do not edit, generated code -#include //do not edit, generated code -#include //do not edit, generated code -#include //do not edit, generated code -#include //do not edit, generated code //{{end}} @@ -115,6 +118,7 @@ celix_status_t bundleActivator_create(bundle_context_pt context, void **userData // cog.outl("\t\t%s_create(&activator->%s);" % (comp['name'], comp['name'])) // cog.outl("\t\tactivator->%sState = COMPONENT_STATE_CREATED;" % (comp['name'])) // cog.outl("\t\tpthread_mutex_init(&activator->%sLock, NULL);" % comp['name']) +// // for service in comp['serviceDependencies'] : // cog.outl("\t\tactivator->%sServiceTracker = NULL;" % service['name']) // cog.outl("\t\tserviceTrackerCustomizer_create(activator, NULL, bundleActivator_add_%s_for_%s, NULL, bundleActivator_remove_%s_for_%s, &activator->%sCustomizer);" % (service['name'], comp['name'], service['name'], comp['name'], service['name'])) @@ -125,6 +129,7 @@ celix_status_t bundleActivator_create(bundle_context_pt context, void **userData // if service['cardinality'] == "one" or service['cardinality'] == "optional" : // cog.outl("\t\tactivator->%s_services_for_%s = hashMap_create(NULL, NULL, NULL, NULL);" % (service['name'], comp['name'])) // cog.outl("\t\tactivator->current_%s_service_for_%s = NULL;" % (service['name'], comp['name'])) +// // for service in comp['providedServices'] : // cog.outl("\t\tactivator->%s = NULL;" % service['name']) // cog.outl("\t\tactivator->%sServiceRegistry = NULL;" % service['name']) @@ -182,7 +187,7 @@ celix_status_t bundleActivator_start(void *userData, bundle_context_pt context) // cog.outl("\tserviceTracker_open(activator->%sServiceTracker);" % service['name']) // for service in comp['providedServices'] : // cog.outl("\tif (activator->%s != NULL) {" % service['name']) -// cog.outl("\t\tbundleContext_registerService(context, (char *)%s, activator->%s, NULL, &activator->%sServiceRegistry);" % (service['service_name'], service['name'], service['name'])) +// cog.outl("\t\tbundleContext_registerService(context, (char *) %s_SERVICE_NAME, activator->%s, NULL, &activator->%sServiceRegistry);" % (service['name'].upper(), service['name'], service['name'])) // cog.outl("\t}") //}} //indent marker //do not edit, generated code @@ -213,9 +218,10 @@ celix_status_t bundleActivator_stop(void *userData, bundle_context_pt context) { // cog.outl("\tif (activator->%s != NULL) {" % service['name']) // cog.outl("\t\tserviceRegistration_unregister(activator->%sServiceRegistry);" % (service['name'])) // cog.outl("\t}") +// // for service in comp['serviceDependencies'] : // cog.outl("\tserviceTracker_close(activator->%sServiceTracker);" % service['name']) -// cog.outl("\t%s_stop(activator->%s);" % (comp['name'], comp['name'])) +// cog.outl("\t%s_stop(activator->%s);" % (comp['name'], comp['name'])) //}} //indent marker //do not edit, generated code if (activator->command != NULL) { //do not edit, generated code @@ -313,17 +319,22 @@ static celix_status_t bundleActivator_getFirst(hash_map_pt services, void **resu // cog.outl("static bundleActivator_resolveState_for_%s(struct activator *activator) {" % comp['name']) // cog.outl("\tcelix_status_t status = CELIX_SUCCESS;") // -// cog.out("\tif (activator->%sState == COMPONENT_STATE_CREATED && " % comp['name']) +// cog.out("\tif (activator->%sState == COMPONENT_STATE_CREATED " % comp['name']) // conditions = [("activator->current_%s_service_for_%s != NULL" % (serv['name'], comp['name'])) for serv in comp['serviceDependencies'] if serv['cardinality'] == "one"] -// cog.out(" && ".join(conditions)) +// if len(conditions) > 0: +// cog.out(" && ") +// cog.out(" && ".join(conditions)) // cog.outl(") {") // cog.outl("\t\t%s_start(activator->%s);" % (comp['name'], comp['name'])) // cog.outl("\t}") // -// cog.out("\tif (activator->%sState == COMPONENT_STATE_STARTED && (" % comp['name']) -// conditions = [("activator->current_%s_service_for_%s == NULL" % (serv['name'], comp['name'])) for serv in comp['serviceDependencies'] if serv['cardinality'] == "one"] -// cog.out(" || ".join(conditions)) -// cog.outl(")) {") +// cog.out("\tif (activator->%sState == COMPONENT_STATE_STARTED " % comp['name']) +// conditions = [("activator->current_%s_service_for_%s == NULL" % (serv['name'], comp['name'])) for serv in comp['serviceDependencies'] if serv['cardinality'] == "one"] +// if len(conditions) > 0: +// cog.out(" && ("); +// cog.out(" || ".join(conditions)) +// cog.out(")"); +// cog.outl(") {") // cog.outl("\t\t%s_stop(activator->%s);" % (comp['name'], comp['name'])) // cog.outl("\t}") // @@ -346,45 +357,46 @@ static bundleActivator_resolveState_for_example(struct activator *activator) { / //{{ //for comp in bundle['components'] : // for service in comp['serviceDependencies'] : -// cog.outl("static celix_status_t bundleActivator_add_%s_for_%s(void *handle, service_reference_pt ref, void *service) {" % (service['name'], comp['name'])) -// cog.outl("\tcelix_status_t status = CELIX_SUCCESS;") -// cog.outl("\tstruct activator *activator = handle;") -// cog.outl("\t%s %s = service;" % (service['type'], service['name'])) -// if service['cardinality'] == "many" : -// cog.outl("\t%s_add_%s(activator->%s, %s);" % (comp['name'], service['name'], comp['name'], service['name'])) -// else : -// cog.outl("\tpthread_mutex_lock(&activator->%sLock);" % comp['name']); -// cog.outl("\t%s highest = NULL;" % service['type']); -// cog.outl("\tbundleActivator_getFirst(activator->%s_services_for_%s, (void **)&highest);" % (service['name'], comp['name'])) -// cog.outl("\tif (highest != activator->current_%s_service_for_%s) {" % (service['name'], comp['name'])) -// cog.outl("\t\tactivator->current_%s_service_for_%s = highest;" % (service['name'], comp['name'])) -// cog.outl("\t\t%s_set_%s(activator->%s, highest);" % (comp['name'], service['name'], comp['name'])) -// cog.outl("\t\tbundleActivator_resolveState_for_%s(activator);" % comp['name']); -// cog.outl("\t}") -// cog.outl("\tpthread_mutex_unlock(&activator->%sLock);" % comp['name']); -// cog.outl("\treturn status;") -// cog.outl("}") -// cog.outl("") -// cog.outl("static celix_status_t bundleActivator_remove_%s_for_%s(void *handle, service_reference_pt ref, void *service) {" % (service['name'], comp['name'])) -// cog.outl("\tcelix_status_t status = CELIX_SUCCESS;") -// cog.outl("\tstruct activator *activator = handle;") -// cog.outl("\t%s %s = service;" % (service['type'], service['name'])) -// if service['cardinality'] == "many" : -// cog.outl("\t%s_remove_%s(activator->%s, %s);" % (comp['name'], service['name'], comp['name'], service['name'])) -// else : -// cog.outl("\tpthread_mutex_lock(&activator->%sLock);" % comp['name']); -// cog.outl("\thashMap_remove(activator->%s_services_for_%s, ref);" % (service['name'], comp['name'])) -// cog.outl("\tif (activator->current_%s_service_for_%s == service) { " % (service['name'], comp['name'])) -// cog.outl("\t\t%s highest = NULL;" % service['type']); -// cog.outl("\t\tbundleActivator_getFirst(activator->%s_services_for_%s, (void **)&highest);" % (service['name'], comp['name'])) -// cog.outl("\t\tactivator->current_%s_service_for_%s = highest;" % (service['name'], comp['name'])) -// cog.outl("\t\tbundleActivator_resolveState_for_%s(activator);" % comp['name']); -// cog.outl("\t\t%s_set_%s(activator->%s, highest);" % (comp['name'], service['name'], comp['name'])) -// cog.outl("\t}") -// cog.outl("\tpthread_mutex_unlock(&activator->%sLock);" % comp['name']); -// cog.outl("\treturn status;") -// cog.outl("}") -// cog.outl("") +// cog.outl("static celix_status_t bundleActivator_add_%s_for_%s(void *handle, service_reference_pt ref, void *service) {" % (service['name'], comp['name'])) +// cog.outl("\tcelix_status_t status = CELIX_SUCCESS;") +// cog.outl("\tstruct activator *activator = handle;") +// cog.outl("\t%s %s = service;" % (service['type'], service['name'])) +// if service['cardinality'] == "many" : +// cog.outl("\t%s_add_%s(activator->%s, %s);" % (comp['name'], service['name'], comp['name'], service['name'])) +// else : +// cog.outl("\tpthread_mutex_lock(&activator->%sLock);" % comp['name']); +// cog.outl("\t%s highest = NULL;" % service['type']); +// cog.outl("\tbundleActivator_getFirst(activator->%s_services_for_%s, (void **)&highest);" % (service['name'], comp['name'])) +// cog.outl("\tif (highest != activator->current_%s_service_for_%s) {" % (service['name'], comp['name'])) +// cog.outl("\t\tactivator->current_%s_service_for_%s = highest;" % (service['name'], comp['name'])) +// cog.outl("\t\t%s_set_%s(activator->%s, highest);" % (comp['name'], service['name'], comp['name'])) +// cog.outl("\t\tbundleActivator_resolveState_for_%s(activator);" % comp['name']); +// cog.outl("\t}") +// cog.outl("\tpthread_mutex_unlock(&activator->%sLock);" % comp['name']); +// cog.outl("\treturn status;") +// cog.outl("}") +// cog.outl("") +// cog.outl("static celix_status_t bundleActivator_remove_%s_for_%s(void *handle, service_reference_pt ref, void *service) {" % (service['name'], comp['name'])) +// cog.outl("\tcelix_status_t status = CELIX_SUCCESS;") +// cog.outl("\tstruct activator *activator = handle;") +// cog.outl("\t%s %s = service;" % (service['type'], service['name'])) +// +// if service['cardinality'] == "many" : +// cog.outl("\t%s_remove_%s(activator->%s, %s);" % (comp['name'], service['name'], comp['name'], service['name'])) +// else : +// cog.outl("\tpthread_mutex_lock(&activator->%sLock);" % comp['name']); +// cog.outl("\thashMap_remove(activator->%s_services_for_%s, ref);" % (service['name'], comp['name'])) +// cog.outl("\tif (activator->current_%s_service_for_%s == service) { " % (service['name'], comp['name'])) +// cog.outl("\t\t%s highest = NULL;" % service['type']); +// cog.outl("\t\tbundleActivator_getFirst(activator->%s_services_for_%s, (void **)&highest);" % (service['name'], comp['name'])) +// cog.outl("\t\tactivator->current_%s_service_for_%s = highest;" % (service['name'], comp['name'])) +// cog.outl("\t\tbundleActivator_resolveState_for_%s(activator);" % comp['name']); +// cog.outl("\t\t%s_set_%s(activator->%s, highest);" % (comp['name'], service['name'], comp['name'])) +// cog.outl("\t}") +// cog.outl("\tpthread_mutex_unlock(&activator->%sLock);" % comp['name']); +// cog.outl("\treturn status;") +// cog.outl("}") +// cog.outl("") //}} static celix_status_t bundleActivator_add_logger_for_example(void *handle, service_reference_pt ref, void *service) { //do not edit, generated code celix_status_t status = CELIX_SUCCESS; //do not edit, generated code http://git-wip-us.apache.org/repos/asf/celix/blob/4feeabc5/celix-bootstrap/celix/bootstrap/templates/bundle/component.c ---------------------------------------------------------------------- diff --git a/celix-bootstrap/celix/bootstrap/templates/bundle/component.c b/celix-bootstrap/celix/bootstrap/templates/bundle/component.c index 4be4e9a..68b0a17 100644 --- a/celix-bootstrap/celix/bootstrap/templates/bundle/component.c +++ b/celix-bootstrap/celix/bootstrap/templates/bundle/component.c @@ -1,9 +1,19 @@ //{{ -//import json +//import yaml //bundle = None //component = None //with open(bundleFile) as input : -// bundle = json.load(input) +// bundle = yaml.load(input) +// +//if not 'components' in bundle or bundle['components'] is None: +// bundle['components'] = [] +//else: +// for comp in bundle['components'] : +// if not 'serviceDependencies' in comp or comp['serviceDependencies'] is None: +// comp['serviceDependencies'] = [] +// if not 'providedServices' in comp or comp['providedServices'] is None: +// comp['providedServices'] = [] +// //for comp in bundle['components'] : // if comp['name'] == componentName : // component = comp @@ -45,6 +55,7 @@ struct example { //do not edit, generated code //{{ //cog.outl("celix_status_t %s_create(%s_pt *result) {" % (componentName, componentName)) //cog.outl("\tcelix_status_t status = CELIX_SUCCESS;") +//cog.outl("printf(\" %s_create called.\\n\");" % (componentName)) //cog.outl("\t%s_pt component = calloc(1, sizeof(*component));" % componentName) //cog.outl("\tif (component != NULL) {") //for service in component['serviceDependencies'] : @@ -79,6 +90,7 @@ celix_status_t example_create(example_pt *result) { //do not edit, generated cod //Destroy function //{{ //cog.outl("celix_status_t %s_destroy(%s_pt component) {" % (componentName,componentName)) +//cog.outl("printf(\" %s_destroy called.\\n\");" % (componentName)) //}} celix_status_t example_destroy(example_pt component) { //do not edit, generated code //{{end}} @@ -94,6 +106,7 @@ celix_status_t example_destroy(example_pt component) { //do not edit, generated //Start function //{{ //cog.outl("celix_status_t %s_start(%s_pt component) {" % (componentName,componentName)) +//cog.outl("printf(\" %s_start called.\\n\");" % (componentName)) //}} celix_status_t example_start(example_pt component) { //do not edit, generated code //{{end}} @@ -104,6 +117,7 @@ celix_status_t example_start(example_pt component) { //do not edit, generated co //Stop function //{{ //cog.outl("celix_status_t %s_stop(%s_pt component) {" % (componentName,componentName)) +//cog.outl("printf(\" %s_stop called.\\n\");" % (componentName)) //}} celix_status_t example_stop(example_pt component) { //do not edit, generated code //{{end}} @@ -116,6 +130,7 @@ celix_status_t example_stop(example_pt component) { //do not edit, generated cod // if service['cardinality'] == "many" : // cog.outl("celix_status_t %s_add_%s(%s_pt component, %s %s) {" % (componentName, service['name'], componentName, service['type'], service['name'])) // cog.outl("\tcelix_status_t status = CELIX_SUCCESS;") +// cog.outl("printf(\" %s_add_%s called.\\n\");" % (componentName, service['name'])) // cog.outl("\tpthread_mutex_lock(&component->mutex_for_%sServices);" % service['name']) // cog.outl("\tarrayList_add(component->%sServices, %s);" % (service['name'], service['name'])) // cog.outl("\tpthread_mutex_unlock(&component->mutex_for_%sServices);" % service['name']) @@ -132,12 +147,13 @@ celix_status_t example_stop(example_pt component) { //do not edit, generated cod // else : // cog.outl("celix_status_t %s_set_%s(%s_pt component, %s %s) {" % (componentName, service['name'], componentName, service['type'], service['name'])) // cog.outl("\tcelix_status_t status = CELIX_SUCCESS;") +// cog.outl("printf(\" %s_set_%s called.\\n\");" % (componentName, service['name'])) // cog.outl("\tpthread_mutex_lock(&component->mutex_for_%s);" % service['name']) // cog.outl("\tcomponent->%s == %s;" % (service['name'], service['name'])) // cog.outl("\tpthread_mutex_unlock(&component->mutex_for_%s);" % service['name']) // cog.outl("\treturn status;") // cog.outl("}") -// cog.outl("") +// cog.outl("") //}} celix_status_t example_set_logger(example_pt component, log_service_pt logger) { //do not edit, generated code celix_status_t status = CELIX_SUCCESS; //do not edit, generated code http://git-wip-us.apache.org/repos/asf/celix/blob/4feeabc5/celix-bootstrap/celix/bootstrap/templates/bundle/component.h ---------------------------------------------------------------------- diff --git a/celix-bootstrap/celix/bootstrap/templates/bundle/component.h b/celix-bootstrap/celix/bootstrap/templates/bundle/component.h index 15fdfba..e036bbd 100644 --- a/celix-bootstrap/celix/bootstrap/templates/bundle/component.h +++ b/celix-bootstrap/celix/bootstrap/templates/bundle/component.h @@ -1,9 +1,19 @@ //{{ -//import json +//import yaml //bundle = None //component = None //with open(bundleFile) as input : -// bundle = json.load(input) +// bundle = yaml.load(input) +// +//if not 'components' in bundle or bundle['components'] is None: +// bundle['components'] = [] +//else: +// for comp in bundle['components'] : +// if not 'serviceDependencies' in comp or comp['serviceDependencies'] is None: +// comp['serviceDependencies'] = [] +// if not 'providedServices' in comp or comp['providedServices'] is None: +// comp['providedServices'] = [] +// //for comp in bundle['components'] : // if comp['name'] == componentName : // component = comp @@ -13,9 +23,10 @@ //cog.outl("#define __%s_H_" % componentName.upper()) //cog.outl("") // -//for service in component['serviceDependencies'] : -// cog.outl("#include <%s>" % service['include']) -//cog.outl("") +//if 'serviceDependencies' in comp and comp['serviceDependencies'] is not None: +// for service in component['serviceDependencies'] : +// cog.outl("#include <%s>" % service['include']) +// cog.outl("") // //}} #ifndef __EXAMPLE_H_ //do not edit, generated code http://git-wip-us.apache.org/repos/asf/celix/blob/4feeabc5/celix-bootstrap/celix/bootstrap/templates/bundle/deploy.cmake ---------------------------------------------------------------------- diff --git a/celix-bootstrap/celix/bootstrap/templates/bundle/deploy.cmake b/celix-bootstrap/celix/bootstrap/templates/bundle/deploy.cmake index 6157f1d..2dbf2cc 100644 --- a/celix-bootstrap/celix/bootstrap/templates/bundle/deploy.cmake +++ b/celix-bootstrap/celix/bootstrap/templates/bundle/deploy.cmake @@ -1,8 +1,8 @@ #{{ -#import json +#import yaml #bundle = None #with open(bundleFile) as input : -# bundle = json.load(input) +# bundle = yaml.load(input) #cog.outl("deploy( \"%s\" BUNDLES" % bundle['name']) #cog.outl("\t${CELIX_BUNDLES_DIR}/shell.zip") #cog.outl("\t${CELIX_BUNDLES_DIR}/shell_tui.zip") http://git-wip-us.apache.org/repos/asf/celix/blob/4feeabc5/celix-bootstrap/celix/bootstrap/templates/bundle/service.h ---------------------------------------------------------------------- diff --git a/celix-bootstrap/celix/bootstrap/templates/bundle/service.h b/celix-bootstrap/celix/bootstrap/templates/bundle/service.h new file mode 100644 index 0000000..a6b1fd8 --- /dev/null +++ b/celix-bootstrap/celix/bootstrap/templates/bundle/service.h @@ -0,0 +1,58 @@ +//{{ +//import yaml +//bundle = None +//with open(bundleFile) as input : +// bundle = yaml.load(input) +//if not 'components' in bundle or bundle['components'] is None: +// bundle['components'] = [] +//else: +// for comp in bundle['components'] : +// if not 'providedServices' in comp or comp['providedServices'] is None: +// comp['providedServices'] = [] +// +//for comp in bundle['components'] : +// if comp['name'] == componentName : +// component = comp +// +// for serv in comp['providedServices'] : +// if serv['name'] == serviceName : +// service = serv +// break +// +//cog.outl("#ifndef __%s_H_" % service['name'].upper()) +//cog.outl("#define __%s_H_" % service['name'].upper()) +//cog.outl("") +// +//}} +#ifndef __EXAMPLE_H_ //do not edit, generated code +#define __EXAMPLE_H_ //do not edit, generated code +//{{end}} + +//TODO add needed includes + +//{{ +//cog.outl("#define %s_SERVICE_NAME \"%s_service\"" % (service['name'].upper(), service['service_name'])) +//cog.outl("") +//cog.outl("typedef struct %s_service* %s;" % (service['name'], service['type'])) +//cog.outl("") +//cog.outl("struct %s_service {" % service['name']) +//cog.outl("\tvoid *handle;") +//}} +#define BENCHMARK_SERVICE_NAME "benchmark_service" +typedef struct benchmark_service *benchmark_service_pt; + +struct benchmark_service { + benchmark_handler_pt handler; +//{{end}}} + + //TODO add service methods + +//{{ +//cog.outl("};") +//cog.outl("") +//cog.outl("") +//cog.outl("#endif /* __%s_H_ */" % service['name']) +//}} +}; +#endif /* BENCHMARK_SERVICE_H_ */ +//{{end}} http://git-wip-us.apache.org/repos/asf/celix/blob/4feeabc5/celix-bootstrap/celix/bootstrap/templates/project/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/celix-bootstrap/celix/bootstrap/templates/project/CMakeLists.txt b/celix-bootstrap/celix/bootstrap/templates/project/CMakeLists.txt index 04fea0b..b6f7958 100644 --- a/celix-bootstrap/celix/bootstrap/templates/project/CMakeLists.txt +++ b/celix-bootstrap/celix/bootstrap/templates/project/CMakeLists.txt @@ -1,8 +1,10 @@ #{{ -# import json -# project = None -# with open(projectFile) as input : -# project = json.load(input) +#import fnmatch +#import os +#import yaml +#project = None +#with open(projectFile) as input : +# project = yaml.load(input) #}} #{{end}} @@ -23,8 +25,13 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "/usr/local/share/celix/cmake/modules find_package(CELIX REQUIRED) include_directories(${CELIX_INCLUDE_DIRS}) -#TODO add sub directory for every bundle -#e.g. -#add_subdirectory(mybundle) + +#{{ +#for root, dirs, filenames in os.walk('.'): +# for foundFile in fnmatch.filter(filenames, 'bundle.yaml'): +# cog.outl("add_subdirectory(%s)" % root) +#}} +# +#{{end}} deploy_targets() http://git-wip-us.apache.org/repos/asf/celix/blob/4feeabc5/celix-bootstrap/celix/bootstrap/templates/project/project.json ---------------------------------------------------------------------- diff --git a/celix-bootstrap/celix/bootstrap/templates/project/project.json b/celix-bootstrap/celix/bootstrap/templates/project/project.json deleted file mode 100644 index db48217..0000000 --- a/celix-bootstrap/celix/bootstrap/templates/project/project.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name" : "myproject", - "celix_install_dir": "/usr/local" -} http://git-wip-us.apache.org/repos/asf/celix/blob/4feeabc5/celix-bootstrap/celix/bootstrap/templates/project/project.yaml ---------------------------------------------------------------------- diff --git a/celix-bootstrap/celix/bootstrap/templates/project/project.yaml b/celix-bootstrap/celix/bootstrap/templates/project/project.yaml new file mode 100644 index 0000000..a7832a9 --- /dev/null +++ b/celix-bootstrap/celix/bootstrap/templates/project/project.yaml @@ -0,0 +1,19 @@ +#{{ +#from celix.bootstrap.celix_utils import * +#}} +#{{end}} + + +# {{ +# name = checkInput('\nPlease enter projectname', '([a-zA-Z_][a-zA-Z0-9_]*)', 'myproject') +# cog.outl('name: \"%s\"' % name ) +# }} +name: "myproject" +# {{end}} + +# {{ +# install = checkCelixInstallation() +# cog.outl('celix_install_dir: \"%s\"' % install ) +# }} +celix_install_dir: "/usr/local" +# {{end}} http://git-wip-us.apache.org/repos/asf/celix/blob/4feeabc5/celix-bootstrap/celix/bootstrap/templates/services/service.h ---------------------------------------------------------------------- diff --git a/celix-bootstrap/celix/bootstrap/templates/services/service.h b/celix-bootstrap/celix/bootstrap/templates/services/service.h deleted file mode 100644 index 9a8aae9..0000000 --- a/celix-bootstrap/celix/bootstrap/templates/services/service.h +++ /dev/null @@ -1,48 +0,0 @@ -//{{ -//import json -//services = None -//service = None -//with open(descriptorFile) as input : -// services = json.load(input) -//for serv in services : -// if serv['name'] == serviceName : -// service = serv -// break -// -//cog.outl("#ifndef __%s_H_" % serviceName.upper()) -//cog.outl("#define __%s_H_" % serviceName.upper()) -//cog.outl("") -// -//}} -#ifndef __EXAMPLE_H_ //do not edit, generated code -#define __EXAMPLE_H_ //do not edit, generated code -//{{end}} - -//TODO add needed includes - -//{{ -//cog.outl("#define %s_SERVICE_NAME \"%s_service\"" % (serviceName.upper(), serviceName)) -//cog.outl("") -//cog.outl("typedef struct %s_service *%s_service_pt;" % (serviceName, serviceName)) -//cog.outl("") -//cog.outl("struct %s_service {" % serviceName) -//cog.outl("\tvoid *handle;") -//}} -#define BENCHMARK_SERVICE_NAME "benchmark_service" -typedef struct benchmark_service *benchmark_service_pt; - -struct benchmark_service { - benchmark_handler_pt handler; -//{{end}}} - - //TODO add service methods - -//{{ -//cog.outl("};") -//cog.outl("") -//cog.outl("") -//cog.outl("#endif /* __%s_H_ */" % serviceName) -//}} -}; -#endif /* BENCHMARK_SERVICE_H_ */ -//{{end}} http://git-wip-us.apache.org/repos/asf/celix/blob/4feeabc5/celix-bootstrap/celix/bootstrap/templates/services/services.json ---------------------------------------------------------------------- diff --git a/celix-bootstrap/celix/bootstrap/templates/services/services.json b/celix-bootstrap/celix/bootstrap/templates/services/services.json deleted file mode 100644 index f6efc03..0000000 --- a/celix-bootstrap/celix/bootstrap/templates/services/services.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - { "name" : "example1" }, - { "name" : "example2" } -]