You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2015/11/03 12:09:47 UTC
[10/21] celix git commit: CELIX-210: Fixed an issue that state update
when to for a a instiated_waiting_for_required state. Added state info to dm
shell command
CELIX-210: Fixed an issue that state update when to for a a instiated_waiting_for_required state. Added state info to dm shell command
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/8f279cbc
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/8f279cbc
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/8f279cbc
Branch: refs/heads/develop
Commit: 8f279cbcfdc17119bade662b2a22e3beda7fb639
Parents: 664845c
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Thu Oct 22 20:30:32 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Thu Oct 22 20:30:32 2015 +0200
----------------------------------------------------------------------
.../private/include/dm_component_impl.h | 10 ++---
.../private/src/dm_component_impl.c | 45 ++++++++++++++------
.../private/src/dm_shell_list_command.c | 4 +-
dependency_manager/public/include/dm_info.h | 1 +
.../tracker_depman/private/src/tracker.c | 6 +--
5 files changed, 45 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/8f279cbc/dependency_manager/private/include/dm_component_impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_component_impl.h b/dependency_manager/private/include/dm_component_impl.h
index 3e86d62..42857d2 100644
--- a/dependency_manager/private/include/dm_component_impl.h
+++ b/dependency_manager/private/include/dm_component_impl.h
@@ -35,10 +35,10 @@
typedef enum dm_component_state {
DM_CMP_STATE_INACTIVE = 1,
- DM_CMP_STATE_WAITING_FOR_REQUIRED,
- DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED,
- DM_CMP_STATE_TRACKING_OPTIONAL,
-} dm_component_state_pt;
+ DM_CMP_STATE_WAITING_FOR_REQUIRED = 2,
+ DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED = 3,
+ DM_CMP_STATE_TRACKING_OPTIONAL = 4,
+} dm_component_state_t;
typedef struct dm_executor * dm_executor_pt;
@@ -64,7 +64,7 @@ struct dm_component {
array_list_pt dependencies;
pthread_mutex_t mutex;
- dm_component_state_pt state;
+ dm_component_state_t state;
bool isStarted;
bool active;
http://git-wip-us.apache.org/repos/asf/celix/blob/8f279cbc/dependency_manager/private/src/dm_component_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_component_impl.c b/dependency_manager/private/src/dm_component_impl.c
index 9b8ee54..5aeae6b 100644
--- a/dependency_manager/private/src/dm_component_impl.c
+++ b/dependency_manager/private/src/dm_component_impl.c
@@ -77,8 +77,8 @@ static celix_status_t component_invokeAutoConfigDependencies(dm_component_pt com
static celix_status_t component_configureImplementation(dm_component_pt component, dm_service_dependency_pt dependency);
static celix_status_t component_allInstanceBoundAvailable(dm_component_pt component, bool *available);
static celix_status_t component_allRequiredAvailable(dm_component_pt component, bool *available);
-static celix_status_t component_performTransition(dm_component_pt component, dm_component_state_pt oldState, dm_component_state_pt newState, bool *transition);
-static celix_status_t component_calculateNewState(dm_component_pt component, dm_component_state_pt currentState, dm_component_state_pt *newState);
+static celix_status_t component_performTransition(dm_component_pt component, dm_component_state_t oldState, dm_component_state_t newState, bool *transition);
+static celix_status_t component_calculateNewState(dm_component_pt component, dm_component_state_t currentState, dm_component_state_t *newState);
static celix_status_t component_handleChange(dm_component_pt component);
static celix_status_t component_startDependencies(dm_component_pt component __attribute__((unused)), array_list_pt dependencies);
static celix_status_t component_getDependencyEvent(dm_component_pt component, dm_service_dependency_pt dependency, dm_event_pt *event_pptr);
@@ -645,21 +645,21 @@ celix_status_t component_stopDependencies(dm_component_pt component) {
celix_status_t component_handleChange(dm_component_pt component) {
celix_status_t status = CELIX_SUCCESS;
- dm_component_state_pt oldState;
- dm_component_state_pt newState;
+ dm_component_state_t oldState;
+ dm_component_state_t newState;
- bool cont = false;
+ bool transition = false;
do {
oldState = component->state;
component_calculateNewState(component, oldState, &newState);
component->state = newState;
- component_performTransition(component, oldState, newState, &cont);
- } while (cont);
+ component_performTransition(component, oldState, newState, &transition);
+ } while (transition);
return status;
}
-celix_status_t component_calculateNewState(dm_component_pt component, dm_component_state_pt currentState, dm_component_state_pt *newState) {
+celix_status_t component_calculateNewState(dm_component_pt component, dm_component_state_t currentState, dm_component_state_t *newState) {
celix_status_t status = CELIX_SUCCESS;
if (currentState == DM_CMP_STATE_INACTIVE) {
@@ -698,7 +698,9 @@ celix_status_t component_calculateNewState(dm_component_pt component, dm_compone
*newState = currentState;
return status;
}
- *newState = DM_CMP_STATE_WAITING_FOR_REQUIRED;
+
+ *newState = component->isStarted ? DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED :
+ DM_CMP_STATE_WAITING_FOR_REQUIRED;
return status;
}
if (currentState == DM_CMP_STATE_TRACKING_OPTIONAL) {
@@ -722,8 +724,9 @@ celix_status_t component_calculateNewState(dm_component_pt component, dm_compone
return status;
}
-celix_status_t component_performTransition(dm_component_pt component, dm_component_state_pt oldState, dm_component_state_pt newState, bool *transition) {
+celix_status_t component_performTransition(dm_component_pt component, dm_component_state_t oldState, dm_component_state_t newState, bool *transition) {
celix_status_t status = CELIX_SUCCESS;
+ printf("performing transition from %i to %i\n", oldState, newState);
if (oldState == DM_CMP_STATE_INACTIVE && newState == DM_CMP_STATE_WAITING_FOR_REQUIRED) {
component_startDependencies(component, component->dependencies);
@@ -738,7 +741,7 @@ celix_status_t component_performTransition(dm_component_pt component, dm_compone
// component_instantiateComponent(component);
component_invokeAddRequiredDependencies(component);
component_invokeAutoConfigDependencies(component);
- dm_component_state_pt stateBeforeCallingInit = component->state;
+ dm_component_state_t stateBeforeCallingInit = component->state;
if (component->callbackInit) {
component->callbackInit(component->implementation);
}
@@ -1318,8 +1321,26 @@ celix_status_t component_getComponentInfo(dm_component_pt component, dm_componen
if (info != NULL) {
arrayList_create(&info->dependency_list);
component_getInterfaces(component, &info->interfaces);
- info->active = component->active;
+ info->active = false;
info->id = strdup(component->id);
+ switch (component->state) {
+ case DM_CMP_STATE_INACTIVE :
+ info->state = strdup("INACTIVE");
+ break;
+ case DM_CMP_STATE_WAITING_FOR_REQUIRED :
+ info->state = strdup("WAITING_FOR_REQUIRED");
+ break;
+ case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED :
+ info->state = strdup("INSTANTIATED_AND_WAITING_FOR_REQUIRED");
+ break;
+ case DM_CMP_STATE_TRACKING_OPTIONAL :
+ info->state = strdup("TRACKING_OPTIONAL");
+ info->active = true;
+ break;
+ default :
+ info->state = strdup("UNKNOWN");
+ break;
+ }
} else {
status = CELIX_ENOMEM;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/8f279cbc/dependency_manager/private/src/dm_shell_list_command.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_shell_list_command.c b/dependency_manager/private/src/dm_shell_list_command.c
index 3c2c43d..59f748f 100644
--- a/dependency_manager/private/src/dm_shell_list_command.c
+++ b/dependency_manager/private/src/dm_shell_list_command.c
@@ -76,7 +76,7 @@ void dmListCommand_execute(command_pt command, char * line, void (*out)(char *),
startColors = compInfo->active ? "\033[92m" : "\033[91m";
endColors = "\033[m";
}
- sprintf(outString, "Component: ID=%s, %sActive=%s%s\n", compInfo->id, startColors, compInfo->active ? "true " : "false", endColors);
+ sprintf(outString, "Component: ID=%s, %sActive=%s%s, State=%s\n", compInfo->id, startColors, compInfo->active ? "true " : "false", endColors, compInfo->state);
out(outString);
int interfCnt;
@@ -114,6 +114,8 @@ void dmListCommand_execute(command_pt command, char * line, void (*out)(char *),
free(dependency->filter);
free(dependency);
}
+
+ //TODO free compInfo
arrayList_destroy(compInfo->dependency_list);
}
}
http://git-wip-us.apache.org/repos/asf/celix/blob/8f279cbc/dependency_manager/public/include/dm_info.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_info.h b/dependency_manager/public/include/dm_info.h
index f010387..ee6a4d8 100644
--- a/dependency_manager/public/include/dm_info.h
+++ b/dependency_manager/public/include/dm_info.h
@@ -42,6 +42,7 @@ typedef struct dm_service_dependency_info {
typedef struct dm_component_info {
char *id;
bool active;
+ char * state;
array_list_pt interfaces; // type char*
array_list_pt dependency_list; // type interface_info_pt
} * dm_component_info_pt;
http://git-wip-us.apache.org/repos/asf/celix/blob/8f279cbc/examples/whiteboard/tracker_depman/private/src/tracker.c
----------------------------------------------------------------------
diff --git a/examples/whiteboard/tracker_depman/private/src/tracker.c b/examples/whiteboard/tracker_depman/private/src/tracker.c
index 0ada638..5688810 100644
--- a/examples/whiteboard/tracker_depman/private/src/tracker.c
+++ b/examples/whiteboard/tracker_depman/private/src/tracker.c
@@ -62,7 +62,7 @@ celix_status_t service_init(void * userData) {
celix_status_t service_start(void * userData) {
struct data * data = (struct data *) userData;
- fprintf(stderr, "Service started");
+ fprintf(stderr, "Service started\n");
data->running = true;
pthread_create(&data->sender, NULL, dp_send, data);
return CELIX_SUCCESS;
@@ -70,14 +70,14 @@ celix_status_t service_start(void * userData) {
celix_status_t service_stop(void * userData) {
struct data * data = (struct data *) userData;
- fprintf(stderr, "Service stopped");
+ fprintf(stderr, "Service stopped\n");
data->running = false;
pthread_join(data->sender, NULL);
return CELIX_SUCCESS;
}
celix_status_t service_deinit(void * userData) {
- fprintf(stderr, "Service deinit");
+ fprintf(stderr, "Service deinit\n");
return CELIX_SUCCESS;
}