示例#1
0
文件: service.c 项目: p1rate5s/c-icap
void init_extra_data(ci_service_xdata_t * srv_xdata, char *service)
{
     char buf[1024];
     char stat_group[1024];
     ci_thread_rwlock_init(&srv_xdata->lock);
     strcpy(srv_xdata->ISTag, "ISTag: ");
     strcat(srv_xdata->ISTag, ISTAG "-XXXXXXXXX");
     memset(srv_xdata->xincludes, 0, XINCLUDES_SIZE + 1);
     memset(srv_xdata->TransferPreview, 0, MAX_HEADER_SIZE + 1);
     memset(srv_xdata->TransferIgnore, 0, MAX_HEADER_SIZE + 1);
     memset(srv_xdata->TransferComplete, 0, MAX_HEADER_SIZE + 1);
     srv_xdata->preview_size = 0;
     srv_xdata->allow_204 = 0;
     srv_xdata->max_connections = 0;
     srv_xdata->xopts = 0;

     snprintf(stat_group, 1023, "Service %s", service);
     stat_group[1023] = '\0';

     buf[1023] = '\0';
     snprintf(buf, 1023, "Service %s REQMODS", service);
     srv_xdata->stat_reqmods = ci_stat_entry_register(buf, STAT_INT64_T, stat_group);

     snprintf(buf, 1023, "Service %s RESPMODS", service);
     srv_xdata->stat_respmods = ci_stat_entry_register(buf, STAT_INT64_T, stat_group);

     snprintf(buf, 1023, "Service %s OPTIONS", service);
     srv_xdata->stat_options = ci_stat_entry_register(buf, STAT_INT64_T, stat_group);

     snprintf(buf, 1023, "Service %s ALLOW 204", service);
     srv_xdata->stat_allow204 = ci_stat_entry_register(buf, STAT_INT64_T, stat_group);

     snprintf(buf, 1023, "Service %s BYTES IN", service);
     srv_xdata->stat_bytes_in = ci_stat_entry_register(buf, STAT_KBS_T, stat_group);

     snprintf(buf, 1023, "Service %s BYTES OUT", service);
     srv_xdata->stat_bytes_out = ci_stat_entry_register(buf, STAT_KBS_T, stat_group);

     snprintf(buf, 1023, "Service %s HTTP BYTES IN", service);
     srv_xdata->stat_http_bytes_in = ci_stat_entry_register(buf, STAT_KBS_T, stat_group);
     
     snprintf(buf, 1023, "Service %s HTTP BYTES OUT", service);
     srv_xdata->stat_http_bytes_out = ci_stat_entry_register(buf, STAT_KBS_T, stat_group);
     
     snprintf(buf, 1023, "Service %s BODY BYTES IN", service);
     srv_xdata->stat_body_bytes_in = ci_stat_entry_register(buf, STAT_KBS_T, stat_group);

     snprintf(buf, 1023, "Service %s BODY BYTES OUT", service);
     srv_xdata->stat_body_bytes_out = ci_stat_entry_register(buf, STAT_KBS_T, stat_group);
}
int postInitImageClassificationService(void)
{
uint16_t category;
	ci_thread_rwlock_init(&imageclassify_rwlock);
	ci_thread_rwlock_wrlock(&imageclassify_rwlock);

	/*Initialize object pools*/
	IMAGEDETECTED_POOL = ci_object_pool_register("image_detected_t", sizeof(image_detected_t) * num_image_categories);

	if(IMAGEDETECTED_POOL < 0) {
		ci_debug_printf(1, " srvclassify_init_service: error registering object_pool image_detected_t\n");
		ci_thread_rwlock_unlock(&imageclassify_rwlock);
		return CI_ERROR;
	}

	IMAGEDETECTEDCOUNT_POOL = ci_object_pool_register("image_detected_count_t", sizeof(image_detected_count_t) * num_image_categories);

	if(IMAGEDETECTEDCOUNT_POOL < 0) {
		ci_debug_printf(1, " srvclassify_init_service: error registering object_pool image_detected_count_t\n");
		ci_object_pool_unregister(IMAGEDETECTED_POOL);
		ci_thread_rwlock_unlock(&imageclassify_rwlock);
		return CI_ERROR;
	}

	if(num_image_categories)
	{
		for(category = 0; category < num_image_categories; category++)
		{
			if(ci_thread_mutex_init(&imageCategories[category].mutex) != 0)
			{
				ci_debug_printf(1, "srv_classify_image: Couldn't init category mutex\n");
			}
			if(ci_thread_cond_init(&imageCategories[category].cond) != 0)
			{
				ci_debug_printf(1, "srv_classify_image: Couldn't init category condition lock variable\n");
			}
		}
	}

	ci_thread_rwlock_unlock(&imageclassify_rwlock);
	return CI_OK;
}