-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CELIX-341: fixed & refactored shell_tui
- Loading branch information
Showing
4 changed files
with
224 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
*Licensed to the Apache Software Foundation (ASF) under one | ||
*or more contributor license agreements. See the NOTICE file | ||
*distributed with this work for additional information | ||
*regarding copyright ownership. The ASF licenses this file | ||
*to you under the Apache License, Version 2.0 (the | ||
*"License"); you may not use this file except in compliance | ||
*with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
*Unless required by applicable law or agreed to in writing, | ||
*software distributed under the License is distributed on an | ||
*"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
*specific language governing permissions and limitations | ||
*under the License. | ||
*/ | ||
/* | ||
* shell_tui.h | ||
* | ||
* \date Jan 16, 2016 | ||
* \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a> | ||
* \copyright Apache License, Version 2.0 | ||
*/ | ||
|
||
#ifndef SHELL_TUI_H_ | ||
#define SHELL_TUI_H_ | ||
|
||
#include <stdlib.h> | ||
|
||
#include "bundle_context.h" | ||
#include "celix_threads.h" | ||
#include "service_reference.h" | ||
#include "shell.h" | ||
|
||
struct shellTuiActivator { | ||
bundle_context_pt context; | ||
shell_service_pt shell; | ||
service_reference_pt reference; | ||
struct serviceListener * listener; | ||
bool running; | ||
celix_thread_t runnable; | ||
}; | ||
|
||
typedef struct shellTuiActivator * shell_tui_activator_pt; | ||
|
||
celix_status_t shellTui_initializeService(shell_tui_activator_pt activator); | ||
celix_status_t shellTui_serviceChanged(service_listener_pt listener, service_event_pt event); | ||
|
||
#endif /* SHELL_TUI_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/** | ||
*Licensed to the Apache Software Foundation (ASF) under one | ||
*or more contributor license agreements. See the NOTICE file | ||
*distributed with this work for additional information | ||
*regarding copyright ownership. The ASF licenses this file | ||
*to you under the Apache License, Version 2.0 (the | ||
*"License"); you may not use this file except in compliance | ||
*with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
*Unless required by applicable law or agreed to in writing, | ||
*software distributed under the License is distributed on an | ||
*"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
*specific language governing permissions and limitations | ||
*under the License. | ||
*/ | ||
/* | ||
* activator.c | ||
* | ||
* \date Jan 15, 2016 | ||
* \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a> | ||
* \copyright Apache License, Version 2.0 | ||
*/ | ||
#include <stdlib.h> | ||
|
||
#include "bundle_context.h" | ||
#include "bundle_activator.h" | ||
|
||
|
||
#include "shell_tui.h" | ||
|
||
|
||
|
||
celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) { | ||
celix_status_t status = CELIX_SUCCESS; | ||
|
||
shell_tui_activator_pt activator = (shell_tui_activator_pt) calloc(1, sizeof(*activator)); | ||
|
||
if (activator) { | ||
activator->shell = NULL; | ||
(*userData) = activator; | ||
} | ||
else { | ||
status = CELIX_ENOMEM; | ||
} | ||
|
||
return status; | ||
} | ||
|
||
celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { | ||
celix_status_t status; | ||
|
||
shell_tui_activator_pt act = (shell_tui_activator_pt) userData; | ||
service_listener_pt listener = (service_listener_pt) calloc(1, sizeof(*listener)); | ||
|
||
act->context = context; | ||
act->running = true; | ||
|
||
act->listener = listener; | ||
act->listener->handle = act; | ||
act->listener->serviceChanged = (void *) shellTui_serviceChanged; | ||
status = bundleContext_addServiceListener(context, act->listener, "(objectClass=shellService)"); | ||
|
||
if (status == CELIX_SUCCESS) { | ||
shellTui_initializeService(act); | ||
} | ||
|
||
return status; | ||
} | ||
|
||
celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) { | ||
celix_status_t status; | ||
shell_tui_activator_pt activator = (shell_tui_activator_pt) userData; | ||
|
||
bundleContext_ungetService(activator->context,activator->reference,NULL); | ||
bundleContext_ungetServiceReference(activator->context,activator->reference); | ||
|
||
status = bundleContext_removeServiceListener(context, activator->listener); | ||
|
||
if (status == CELIX_SUCCESS) { | ||
free(activator->listener); | ||
|
||
activator->running = false; | ||
activator->listener = NULL; | ||
activator->context = NULL; | ||
activator->running = false; | ||
|
||
celixThread_join(activator->runnable, NULL); | ||
} | ||
|
||
return status; | ||
} | ||
|
||
celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) { | ||
shell_tui_activator_pt activator = (shell_tui_activator_pt) userData; | ||
|
||
free(activator); | ||
|
||
return CELIX_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters