blob: 491c69f52eaeffff4cc60ac11a4d14d0328d1669 [file] [log] [blame]
/**
* 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.
*/
/*
* dm_event.c
*
* \date 18 Dec 2014
* \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
* \copyright Apache License, Version 2.0
*/
#include <stdlib.h>
#include <constants.h>
#include <utils.h>
#include "dm_event.h"
celix_status_t event_create(dm_event_type_e event_type, bundle_pt bundle, bundle_context_pt context, service_reference_pt reference, void *service, dm_event_pt *event) {
celix_status_t status = CELIX_SUCCESS;
*event = calloc(1, sizeof(**event));
if (!*event) {
status = CELIX_ENOMEM;
}
char *serviceIdStr = NULL;
serviceReference_getProperty(reference, (char *)OSGI_FRAMEWORK_SERVICE_ID, &serviceIdStr);
long servId = atol(serviceIdStr);
//FIXME service ranking can dynamicly change, but service reference can be removed at any time.
char *rankingStr = NULL;
serviceReference_getProperty(reference, (char *)OSGI_FRAMEWORK_SERVICE_RANKING, &rankingStr);
long ranking = rankingStr == NULL ? 0 : atol(rankingStr);
if (status == CELIX_SUCCESS) {
(*event)->bundle = bundle;
(*event)->event_type = event_type;
(*event)->context = context;
(*event)->reference = reference;
(*event)->service = service;
(*event)->serviceId = servId;
(*event)->ranking = ranking;
}
return status;
}
celix_status_t event_destroy(dm_event_pt *event) {
celix_status_t status = CELIX_SUCCESS;
if (!*event) {
status = CELIX_ILLEGAL_ARGUMENT;
}
if (status == CELIX_SUCCESS) {
free(*event);
*event = NULL;
}
return status;
}
celix_status_t event_equals(void *a, void *b, bool *equals) {
celix_status_t status = CELIX_SUCCESS;
if (!a || !b) {
*equals = false;
} else {
dm_event_pt a_ptr = a;
dm_event_pt b_ptr = b;
*equals = a_ptr->serviceId == b_ptr->serviceId;
}
return status;
}
celix_status_t event_compareTo(dm_event_pt event, dm_event_pt compareTo, int *compare) {
celix_status_t status = CELIX_SUCCESS;
*compare = utils_compareServiceIdsAndRanking(event->serviceId, event->ranking, compareTo->serviceId, compareTo->ranking);
return status;
}
celix_status_t event_getService(dm_event_pt event, void **service) {
*service = event->service;
return CELIX_SUCCESS;
}