/* * Copyright (C) 2013 Red Hat, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Authors: Roman Rakus */ #include #include #include #include // callback functions typedef bool (*IMInstGather) (CMPIInstance **old, CMPIInstance **new, void *data); typedef bool (*IMFilterChecker) (const CMPISelectExp *filter); typedef bool (*IMEventSpawner) (void *data); // Indication types // Only one type supported per instance of manager typedef enum { // for instance indications IM_IND_CREATION, // instance creation IM_IND_DELETION, // instance deletion IM_IND_MODIFICATION, // instance modification } IMIndType; /* * Definition of IMFilter * Linked list of all filters */ typedef struct _IMFilter { struct _IMFilter *next; CMPISelectExp *select_exp; } IMFilter; typedef struct _IMFilters { IMFilter *first; } IMFilters; /* * Linked list of polled enumeration pairs of instances * enumerations are converted to arrays */ typedef struct _IMEnumerationPair { struct _IMEnumerationPair *next; CMPIObjectPath *op; CMPIArray *prev_enum; CMPIArray *this_enum; } IMEnumerationPair; typedef struct _IMEnumerations { IMEnumerationPair *first; } IMEnumerations; typedef struct _IMManager { // callback functions IMEventSpawner spawner; IMInstGather gather; IMFilterChecker f_checker; // filters container IMFilters *filters; // others IMIndType type; bool running; bool polling; CMPIBroker *broker; const CMPIContext *context; /* main thread */ CMPIContext *context2; /* manage thread */ IMEnumerations *enums; // passed data, used for communication between gather/spawn/etc. void *data; } IMManager; typedef enum { IM_ERR_OK, IM_ERR_GATHER, // bad or null gather callback IM_ERR_FILTER_CHECKER, // bad or null filter checker callback IM_ERR_SPAWNER, // bad or null spawner callback IM_ERR_MALLOC, // memory allocation error IM_ERR_FILTER, // bad or null filter IM_ERR_MANAGER, // bad or null manager IM_ERR_BROKER, // bad or null broker IM_ERR_CONTEXT, // bad or null context IM_ERR_NOT_FOUND, // specified data were not found IM_ERR_THREAD, // some error on threading } IMError; // Create manager with given properties and callbacks. // gather may not be specified if you want to use polling // Return newly created IMManager or NULL and appropiate IMError is set IMManager* im_create_manager(IMInstGather gather, IMFilterChecker f_checker, bool polling, IMEventSpawner spawner, IMIndType type, CMPIBroker *broker, IMError *err); // Destroy given manager. // Return true when ok or false and IMError is set bool im_destroy_manager(IMManager *manager, const CMPIContext *ctx, IMError *err); // Call verification callback on given manager and filter. // Return true if filter is verified. False if not. // IMError will be set to to other value than IM_ERR_OK // if verification failed bool im_verify_filter(IMManager *manager, const CMPISelectExp *filter, const CMPIContext *ctx, IMError *err); // add given filter to manager. // Return true when all is ok, otherwise false and IMError // is as appropriate. bool im_add_filter(IMManager *manager, CMPISelectExp *filter, const CMPIContext *ctx, IMError *err); // Remove given filter from manager. // Return true when removed, false if not and appropriate IMError is set. bool im_remove_filter(IMManager *manager, const CMPISelectExp *filter, const CMPIContext *ctx, IMError *err); // Start indications. // Return true when correctly started, false if not and // appropriate IMError is set, bool im_start_ind(IMManager *manager, const CMPIContext *ctx, IMError *err); // Stop indications. // Return true when correctly stopped, false if not and // appropriate IMError is set, bool im_stop_ind(IMManager *manager, const CMPIContext *ctx, IMError *err);