1fcf3ce44SJohn Forte /*
2fcf3ce44SJohn Forte  * CDDL HEADER START
3fcf3ce44SJohn Forte  *
4fcf3ce44SJohn Forte  * The contents of this file are subject to the terms of the
5fcf3ce44SJohn Forte  * Common Development and Distribution License (the "License").
6fcf3ce44SJohn Forte  * You may not use this file except in compliance with the License.
7fcf3ce44SJohn Forte  *
8fcf3ce44SJohn Forte  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fcf3ce44SJohn Forte  * or http://www.opensolaris.org/os/licensing.
10fcf3ce44SJohn Forte  * See the License for the specific language governing permissions
11fcf3ce44SJohn Forte  * and limitations under the License.
12fcf3ce44SJohn Forte  *
13fcf3ce44SJohn Forte  * When distributing Covered Code, include this CDDL HEADER in each
14fcf3ce44SJohn Forte  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fcf3ce44SJohn Forte  * If applicable, add the following below this CDDL HEADER, with the
16fcf3ce44SJohn Forte  * fields enclosed by brackets "[]" replaced with your own identifying
17fcf3ce44SJohn Forte  * information: Portions Copyright [yyyy] [name of copyright owner]
18fcf3ce44SJohn Forte  *
19fcf3ce44SJohn Forte  * CDDL HEADER END
20fcf3ce44SJohn Forte  */
21fcf3ce44SJohn Forte /*
22*ab43d050SJiri Svoboda  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
23fcf3ce44SJohn Forte  */
24fcf3ce44SJohn Forte 
25fcf3ce44SJohn Forte #include "mp_utils.h"
26fcf3ce44SJohn Forte 
27fcf3ce44SJohn Forte 
28fcf3ce44SJohn Forte /*
29fcf3ce44SJohn Forte  *	Called by the common layer to request the plugin to call
30fcf3ce44SJohn Forte  *	a client application's callback (pClientFn) when a property change
31fcf3ce44SJohn Forte  *	is detected for the given object type.
32fcf3ce44SJohn Forte  */
33fcf3ce44SJohn Forte 
34fcf3ce44SJohn Forte MP_STATUS
MP_RegisterForObjectPropertyChangesPlugin(MP_OBJECT_PROPERTY_FN pClientFn,MP_OBJECT_TYPE objectType,void * pCallerData)35fcf3ce44SJohn Forte MP_RegisterForObjectPropertyChangesPlugin(MP_OBJECT_PROPERTY_FN pClientFn,
36fcf3ce44SJohn Forte 		MP_OBJECT_TYPE objectType,
37fcf3ce44SJohn Forte 		void *pCallerData)
38fcf3ce44SJohn Forte {
39fcf3ce44SJohn Forte 	MP_BOOL hasFunc = MP_FALSE;
40fcf3ce44SJohn Forte 
41fcf3ce44SJohn Forte 
42fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_RegisterForObjectPropertyChangesPlugin()",
43*ab43d050SJiri Svoboda 	    " - enter");
44fcf3ce44SJohn Forte 
45fcf3ce44SJohn Forte 
46fcf3ce44SJohn Forte 	/* Validate the object type passes in within range */
47fcf3ce44SJohn Forte 	if (objectType > MP_OBJECT_TYPE_MAX) {
48fcf3ce44SJohn Forte 
49fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_RegisterForObjectPropertyChangesPlugin()",
50*ab43d050SJiri Svoboda 		    " - objectType is invalid");
51fcf3ce44SJohn Forte 
52fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_RegisterForObjectPropertyChangesPlugin()",
53*ab43d050SJiri Svoboda 		    " - error exit");
54fcf3ce44SJohn Forte 
55fcf3ce44SJohn Forte 		return (MP_STATUS_INVALID_PARAMETER);
56fcf3ce44SJohn Forte 	}
57fcf3ce44SJohn Forte 
58fcf3ce44SJohn Forte 	if (objectType < 1) {
59fcf3ce44SJohn Forte 
60fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_RegisterForObjectPropertyChangesPlugin()",
61*ab43d050SJiri Svoboda 		    " - objectType is invalid");
62fcf3ce44SJohn Forte 
63fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_RegisterForObjectPropertyChangesPlugin()",
64*ab43d050SJiri Svoboda 		    " - error exit");
65fcf3ce44SJohn Forte 
66fcf3ce44SJohn Forte 		return (MP_STATUS_INVALID_PARAMETER);
67fcf3ce44SJohn Forte 	}
68fcf3ce44SJohn Forte 
69*ab43d050SJiri Svoboda 	/* Init sysevents if they have not been initialized yet */
70*ab43d050SJiri Svoboda 	if (g_SysEventHandle == NULL) {
71*ab43d050SJiri Svoboda 		if (init_sysevents() != MP_STATUS_SUCCESS)
72*ab43d050SJiri Svoboda 			return (MP_STATUS_FAILED);
73*ab43d050SJiri Svoboda 	}
74*ab43d050SJiri Svoboda 
75*ab43d050SJiri Svoboda 	/* Check to see if we are going to be replacing */
76fcf3ce44SJohn Forte 	(void) pthread_mutex_lock(&g_prop_mutex);
77fcf3ce44SJohn Forte 	if (g_Property_Callback_List[objectType].pClientFn != NULL) {
78fcf3ce44SJohn Forte 
79fcf3ce44SJohn Forte 		hasFunc = MP_TRUE;
80fcf3ce44SJohn Forte 	}
81fcf3ce44SJohn Forte 
82*ab43d050SJiri Svoboda 	/* Add the registration */
83fcf3ce44SJohn Forte 	g_Property_Callback_List[objectType].pClientFn   = pClientFn;
84fcf3ce44SJohn Forte 	g_Property_Callback_List[objectType].pCallerData = pCallerData;
85fcf3ce44SJohn Forte 	(void) pthread_mutex_unlock(&g_prop_mutex);
86fcf3ce44SJohn Forte 
87fcf3ce44SJohn Forte 	if (hasFunc) {
88fcf3ce44SJohn Forte 
89fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_RegisterForObjectPropertyChangesPlugin()",
90*ab43d050SJiri Svoboda 		    " - returning MP_STATUS_FN_REPLACED");
91fcf3ce44SJohn Forte 
92fcf3ce44SJohn Forte 		return (MP_STATUS_FN_REPLACED);
93fcf3ce44SJohn Forte 	}
94fcf3ce44SJohn Forte 
95fcf3ce44SJohn Forte 
96fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_RegisterForObjectPropertyChangesPlugin()",
97*ab43d050SJiri Svoboda 	    " - exit");
98fcf3ce44SJohn Forte 
99fcf3ce44SJohn Forte 	return (MP_STATUS_SUCCESS);
100fcf3ce44SJohn Forte }
101