components/visual-panels/core/src/cmd/rad/mod/files/mod_files.c
branchs11-update
changeset 2805 4888f6212f94
parent 901 19b502ccabc8
equal deleted inserted replaced
2804:7546c836fd87 2805:4888f6212f94
    18  *
    18  *
    19  * CDDL HEADER END
    19  * CDDL HEADER END
    20  */
    20  */
    21 
    21 
    22 /*
    22 /*
    23  * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
    23  * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
    24  */
    24  */
    25 
    25 
    26 /*
    26 /*
    27  * Unfortunately, the behavior this module has inherited is not one
    27  * Unfortunately, the behavior this module has inherited is not one
    28  * of "get me information about file X or directory Y", but "tell me
    28  * of "get me information about file X or directory Y", but "tell me
   133     adr_data_t **data, adr_data_t **error)
   133     adr_data_t **data, adr_data_t **error)
   134 {
   134 {
   135 	adr_data_t *result = adr_data_new_array(&t_array__FileSnapshot, 1);
   135 	adr_data_t *result = adr_data_new_array(&t_array__FileSnapshot, 1);
   136 	(void) adr_array_add(result, read_file("/", NULL));
   136 	(void) adr_array_add(result, read_file("/", NULL));
   137 	*data = adr_data_purify(result);
   137 	*data = adr_data_purify(result);
   138 	return (ce_ok);
   138 	return (CE_OK);
   139 }
   139 }
   140 
   140 
   141 /* ARGSUSED */
   141 /* ARGSUSED */
   142 conerr_t
   142 conerr_t
   143 interface_FileBrowser_invoke_getFile(rad_instance_t *inst, adr_method_t *meth,
   143 interface_FileBrowser_invoke_getFile(rad_instance_t *inst, adr_method_t *meth,
   144     adr_data_t **ret, adr_data_t **args, int count, adr_data_t **error)
   144     adr_data_t **ret, adr_data_t **args, int count, adr_data_t **error)
   145 {
   145 {
   146 	*ret = read_file(adr_data_to_string(args[0]), NULL);
   146 	*ret = read_file(adr_data_to_string(args[0]), NULL);
   147 	return (ce_ok);
   147 	return (CE_OK);
   148 }
   148 }
   149 
   149 
   150 /* ARGSUSED */
   150 /* ARGSUSED */
   151 conerr_t
   151 conerr_t
   152 interface_FileBrowser_invoke_getFiles(rad_instance_t *inst, adr_method_t *meth,
   152 interface_FileBrowser_invoke_getFiles(rad_instance_t *inst, adr_method_t *meth,
   156 	DIR *d = opendir(path);
   156 	DIR *d = opendir(path);
   157 	struct dirent *ent;
   157 	struct dirent *ent;
   158 	adr_data_t *result;
   158 	adr_data_t *result;
   159 
   159 
   160 	if (d == NULL)
   160 	if (d == NULL)
   161 		return (ce_object);
   161 		return (CE_OBJECT);
   162 
   162 
   163 	result = adr_data_new_array(&t_array__FileSnapshot, 1);
   163 	result = adr_data_new_array(&t_array__FileSnapshot, 1);
   164 	while ((ent = readdir(d)) != NULL) {
   164 	while ((ent = readdir(d)) != NULL) {
   165 		char buf[PATH_MAX];
   165 		char buf[PATH_MAX];
   166 		if (strcmp(ent->d_name, ".") == 0 ||
   166 		if (strcmp(ent->d_name, ".") == 0 ||
   176 			(void) adr_array_add(result, file);
   176 			(void) adr_array_add(result, file);
   177 	}
   177 	}
   178 	(void) closedir(d);
   178 	(void) closedir(d);
   179 	*ret = adr_data_purify(result);
   179 	*ret = adr_data_purify(result);
   180 
   180 
   181 	return (ce_ok);
   181 	return (CE_OK);
   182 }
   182 }
   183 
       
   184 static rad_modinfo_t modinfo = { "files", "File Browser module" };
       
   185 
   183 
   186 int
   184 int
   187 _rad_init(void *handle)
   185 _rad_init(void)
   188 {
   186 {
   189 	if (rad_module_register(handle, RAD_MODVERSION, &modinfo) == -1)
   187 	adr_name_t *aname = adr_name_vcreate(
       
   188 	    MOD_DOMAIN, 1, "type", "FileBrowser");
       
   189 	conerr_t cerr =  rad_cont_insert_singleton(rad_container, aname,
       
   190 	    &modinfo, &interface_FileBrowser_svr);
       
   191 	adr_name_rele(aname);
       
   192 	if (cerr != CE_OK) {
       
   193 		rad_log(RL_ERROR, "(mod_files) failed to insert FileBrowser");
   190 		return (-1);
   194 		return (-1);
   191 
   195 	}
   192 	if (rad_isproxy)
       
   193 		return (0);
       
   194 
       
   195 	(void) cont_insert_singleton(rad_container, adr_name_fromstr(
       
   196 	    "com.oracle.solaris.vp.panel.common.api.file:type=FileBrowser"),
       
   197 	    &interface_FileBrowser_svr);
       
   198 
   196 
   199 	return (0);
   197 	return (0);
   200 }
   198 }
       
   199 
       
   200 /*
       
   201  * _rad_fini is called by the RAD daemon when the module is unloaded. Any
       
   202  * module finalisation is completed here.
       
   203  */
       
   204 /*ARGSUSED*/
       
   205 void
       
   206 _rad_fini(void *unused)
       
   207 {
       
   208 }