static void reserve_state_check(struct work_struct *work)
{
	struct otg_booting_delay *o_b_d = container_of(work,
			struct otg_booting_delay, booting_work.work);
	struct usb_notify *u_noti = container_of(o_b_d,
			struct usb_notify, b_delay);
	int enable = 1;
	unsigned long state = 0;

	state = u_noti->b_delay.reserve_state;
	u_noti->o_notify->booting_delay_sec = 0;
	pr_info("%s booting delay finished\n", __func__);

	if (u_noti->b_delay.reserve_state != NOTIFY_EVENT_NONE) {
		pr_info("%s event=%s(%lu) enable=%d\n", __func__,
				event_string(state), state, enable);
		if (check_event_type(state) & NOTIFY_EVENT_EXTRA)
			blocking_notifier_call_chain
				(&u_noti->o_notify->extra_notifier,
						state, &enable);
		else
			atomic_notifier_call_chain
				(&u_noti->o_notify->otg_notifier,
						state, &enable);
	}
}
示例#2
0
void cli_event_error_str(cli_events_t *ctx, const char *str)
{
    if (!ctx)
	return;
    cli_warnmsg("events: %s\n", str);
    event_string(ctx, &ctx->errors, str);
}
static int otg_notifier_callback(struct notifier_block *nb,
		unsigned long event, void *param)
{
	struct otg_state_work *state_work;

	pr_info("%s event=%s(%lu)\n", __func__,
			event_string(event), event);

	if (!u_notify) {
		pr_err("u_notify is NULL\n");
		return NOTIFY_DONE;
	}

	if (event > NOTIFY_EVENT_VBUSPOWER) {
		pr_err("%s event is invalid\n", __func__);
		return NOTIFY_DONE;
	}

	state_work = kmalloc(sizeof(struct otg_state_work), GFP_ATOMIC);
	if (!state_work) {
		pr_err("unable to allocate state_work\n");
		return notifier_from_errno(-ENOMEM);
	}
	INIT_WORK(&state_work->otg_work, otg_notify_work);
	state_work->event = event;
	state_work->enable = *(int *)param;
	queue_work(u_notify->notifier_wq, &state_work->otg_work);
	return NOTIFY_OK;
}
示例#4
0
void cli_event_string(cli_events_t *ctx, unsigned id, const char *str)
{
    struct cli_event *ev = get_event(ctx, id);
    if (!ev)
	return;
    if (ev->type != ev_string) {
	cli_event_error_str(ctx, "cli_event_string must be called with ev_string type");
	return;
    }
    event_string(ctx, ev, str);
}
示例#5
0
文件: sock.c 项目: ngmon/ngmon
int main(int argc, char *argv[])
{
    int sock;                        	/* Socket descriptor */
    struct sockaddr_in echoServAddr; 	/* Echo server address */
    unsigned short echoServPort = 5000; /* Echo server port */
    char *servIP = "127.0.0.1";      	/* Server IP address (dotted quad) */
    char *echoString;                	/* String to send */
    unsigned int echoStringLen;      	/* Length of string */
    int loops;
    int sleep_time;

    if ((argc < 3) || (argc > 3))    	/* Test for correct number of arguments */
    {
       fprintf(stderr, "Usage: %s <loops> <sleep_time_milis>\n",
               argv[0]);
       exit(1);
    }
	
	loops = atoi(argv[1]);
	sleep_time = atoi(argv[2]);	

    /* Create a reliable, stream socket using TCP */
    if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) error("socket() failed");

    /* Construct the server address structure */
    memset(&echoServAddr, 0, sizeof(echoServAddr));     /* Zero out structure */
    echoServAddr.sin_family      = AF_INET;             /* Internet address family */
    echoServAddr.sin_addr.s_addr = inet_addr(servIP);   /* Server IP address */
    echoServAddr.sin_port        = htons(echoServPort); /* Server port */

    /* Establish the connection to the echo server */
    if (connect(sock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0) error("connect() failed");


	int avg = sleep_time;		
	int i;
	
	for (i = 0; i < loops; i++) {
		
		echoString = event_string();
		echoStringLen = strlen(echoString);          /* Determine input length */
		
		if (send(sock, echoString, echoStringLen, 0) != echoStringLen) error("send() sent a different number of bytes than expected"); /* Send the string to the server */
		
		avg += my_sleep(sleep_time);
		avg = avg/2;
	}
	
    printf("%d:%d",avg, i);   
    printf("\n");    /* Print a final linefeed */

    close(sock);
    exit(0);
}
示例#6
0
int read_event(int sfd)
{
	uint8_t data[sizeof(struct l2tp_event) + 8];
	struct l2tp_event *event = (struct l2tp_event *)&data[0];
	bool done = false;
	uint8_t *eptr = (uint8_t *)event;
	int len, remaining = sizeof(*event);

	/* Get header from client */
	while (!done) {
		len = recv(sfd, eptr, remaining, 0); 
		if (len < 0) {
			if (errno == EINTR) {
				continue;
			} else {
				break;
			}
		} else if (len == 0) {
			return -ENOTCONN;
		} else {
			remaining -= len;
			eptr += len;
			if (!remaining)
				done = true;
		}
	}

	/* Get rest of message */
	remaining = event->len;
	done = false;
	while (!done) {
		len = recv(sfd, eptr, remaining, 0); 
		if (len < 0) {
			if (errno == EINTR) {
				continue;
			} else {
				break;
			}
		} else if (len == 0) {
			return -ENOTCONN;
		} else {
			remaining -= len;
			if (!remaining)
				done = true;
		}
	}

	fprintf(stdout, "Received %s event and %d bytes\n",
		event_string(event->event),
		event->len);

	return EXIT_SUCCESS;
}
unsigned long get_cable_type(void)
{
	unsigned long ret = 0;

	if (!u_notify) {
		ret = create_usb_notify();
		if (ret) {
			pr_err("unable create_usb_notify\n");
			return -EFAULT;
		}
	}
	pr_info("%s cable type =%s\n", __func__,
			event_string(u_notify->c_type));
	ret = u_notify->c_type;
	return ret;
}
static int extra_notifier_callback(struct notifier_block *nb,
		unsigned long event, void *param)
{
	pr_info("%s event=%s(%lu)\n", __func__,
			event_string(event), event);

	if (!u_notify) {
		pr_err("u_notify is NULL\n");
		return NOTIFY_DONE;
	}

	if (event > NOTIFY_EVENT_VBUSPOWER) {
		pr_err("%s event is invalid\n", __func__);
		return NOTIFY_DONE;
	}

	extra_notify_state(event, *(int *)param);

	return NOTIFY_OK;
}
void send_otg_notify(struct otg_notify *n,
				unsigned long event, int enable)
{
	int type = 0;

	if (!n) {
		pr_err("%s otg_notify is null\n", __func__);
		return;
	}

	pr_info("%s event=%s(%lu) enable=%d\n", __func__,
			event_string(event), event, enable);

	type = check_event_type(event);

	if (type & NOTIFY_EVENT_DELAY) {
		if (n->booting_delay_sec) {
			if (u_notify) {
				u_notify->b_delay.reserve_state =
					(enable) ? event : NOTIFY_EVENT_NONE;
				pr_info("%s reserve event\n", __func__);
			} else
				pr_err("%s u_notify is null\n", __func__);
			goto end;
		}
	}

	if (type & NOTIFY_EVENT_EXTRA)
		blocking_notifier_call_chain
			(&n->extra_notifier, event, &enable);
	else if (type & NOTIFY_EVENT_STATE)
		atomic_notifier_call_chain
			(&n->otg_notifier, event, &enable);
	else
		goto end;
end:
	return;
}
示例#10
0
void record_event(EventCode code, Sprite *by, Background *floor,
						Sprite *subject, boolean type_of_subject_fixed,
						int key, AddToWorkingSet add_to_working_set,
						boolean notebook_page_really_selected,
						int label_index
#if TT_POST3187
						,Sprite *original_subject
#endif		
						) {
#if TT_DEBUG_ON
 	if (tt_debug_mode == 5050) {
		tt_error_file() << timeGetTime() << " ";
      Event *event = new Event(code,NULL);
		event->debug(NULL);
		delete event;
	};
#endif
	// until I generate instructions programmer actions aren't recorded
	if (tt_log_version_number >= 22) {
		if (by == NULL || tt_recording_off || (by->kind_of() != ROBOT && by->kind_of() != ROBOT_IN_TRAINING) || tt_shutting_down) return;
	} else {
		if (by == NULL || tt_recording_off || by->kind_of() == PROGRAMMER || tt_shutting_down) return;
	};
	// third condition prior to 050400 was by->kind_of() == PROGRAMMER but by might be a bird for example
	boolean body_cubby;
	if (by->kind_of() == ROBOT) {
		body_cubby = (subject == ((Robot *) by)->pointer_to_working_cubby());
	} else if (floor != NULL || tt_log_version_number < 22) { // condition added 050400
		body_cubby = (subject == floor->pointer_to_body_cubby());
	} else {
		body_cubby = FALSE;
	};
	// doesn't count that its main cubby if put somewhere
//	if (body_cubby) {
//		body_cubby = (subject->pointer_to_leader() == NULL ||
//						  subject->pointer_to_leader()->kind_of() == ROBOT_IN_TRAINING);
//	};
	const boolean notebook = (tt_toolbox != NULL && subject == tt_toolbox_notebook);
// following screws up if main cubby put into something and then taken out
// also bad to have just 1 optimization like this
// restored for notebook since it is shared and shouldn't be moved by robots
	if (code == RELEASE_ITEM && notebook) {
//		 ((body_cubby && subject->pointer_to_leader() == NULL) || notebook)) {
		// could be more clever and if anything is released right
		// after being picked up it is ignored
		// picked up and released main cubby or notebook
		// (or vacuumed up and restored)
		// robot shouldn't be doing this so ok to assume floor
		if (tt_events != NULL) {
			Event *last_event = tt_events->last()->first();
			if (last_event->event_code() == GRASP_ITEM || last_event->event_code() == VACUUM_APPLY) { 
				// test new on 120305 since can be keyboard event, for example
				floor->remove_last_n_events(1); // must have been a grasp_item (or apply_vacuum)
				return;
			};
		}; // else should be OK since there are no events to remove, right?
	};
	if (code == RELEASE_ITEM_ON && by->kind_of() == ROBOT_IN_TRAINING) {
      if (subject->kind_of() == NEST && subject->infinite_stack()) {
		   // returning a nest with egg back to stack but already
		   // generated a hatch_bird message
		   floor->remove_last_n_events(1);
		   ((Robot *) by)->remove_last_working_set_item();
// taken care of by :now_part_of_somthing()
//      } else { // Happens in event.cpp so needs to happen here as well
//         ((Robot *) by)->remove_tool_from_working_set(subject);
      };
	};
	Path *path = NULL;
	Event *new_item_event = NULL;
	if (body_cubby || notebook) {
		add_to_working_set = DONT_ADD_TO_WORKING_SET;
	};
	if (code == NEW_ITEM || code == HATCH_BIRD || 
		 code == RELEASE_ITEM || code == VACUUM_APPLY_RESTORE) {
		if (subject != NULL && !body_cubby &&
          !(tt_toolbox != NULL && toolbox_tool(subject))) {
			// either defining a body so add to this
			// or by is a robot so add to its
			// or by is programmer so ignore
			switch (by->kind_of()) {
				case ROBOT_IN_TRAINING:
//					if (!by->still_running()) {
						if (add_to_working_set != DONT_ADD_TO_WORKING_SET) {
							int index = ((Robot *) by)->add_to_working_set(subject,(add_to_working_set == ADD_TO_WORKING_SET_IF_NEW));
							if (type_of_subject_fixed) {
								path = new Path(index,new Path(subject->fine_kind_of()));
							} else if (code == VACUUM_APPLY_RESTORE) {
								path = new Path(index,new Path(NONE_GIVEN));
								subject = NULL;
							};
	//						} else if (code == HATCH_BIRD) {
	//							path = new Path(index,new Path(BIRD));
	//						} else {
	//							path = new Path(index,new Path(NONE_GIVEN));
						};
						break;
//					}; // otherwise fall thru to the following
				case ROBOT:
					if (add_to_working_set != DONT_ADD_TO_WORKING_SET) {
						((Robot *) by)->add_to_working_set(subject,(add_to_working_set == ADD_TO_WORKING_SET_IF_NEW));
					};
					break;
			};
//			floor->add_to_some_working_set(subject,by);
			if (code != GRASP_ITEM && code != GRASP_NEST && code != VACUUM_APPLY_RESTORE &&
				 notebook_page_really_selected) {
				subject->set_available_for_indexing(TRUE);
			};
		};
// following commented out so path is recorded for generating Java properly
//		if (code == VACUUM_APPLY_RESTORE) subject = NULL;
		if (path != NULL) {
			new_item_event = new Event(NEW_ITEM,path,0);
			if (code != VACUUM_APPLY_RESTORE) {
				if (tt_events == NULL) {
					tt_events = new Events(new_item_event,tt_events);
				} else {
					tt_events->insert_at_end(new_item_event);
				};
				new_item_event = NULL;
			}; // else add it after this event
		};
		// following just are used to update working set
		// can combine them to one?? except for descriptions?
		if (code == NEW_ITEM || code == HATCH_BIRD) return;
	};
	if (by->kind_of() != ROBOT_IN_TRAINING) {
		if (code == NEW_MAIN_CUBBY) {
			floor->set_body_cubby((Cubby *) subject, by);
		};
		return; // already knows the path
	};
	if (subject != NULL && code == GRASP_ITEM) {
		if (subject->kind_of() == NEST) {
			code = GRASP_NEST; // the whole thing not the top of its stack
		} else if (tt_toolbox != NULL) {
			// used to do switch (subject->kind_of()) but copies of tools break
			if (subject == tt_toolbox_copier) {
				code = GRASP_COPIER;
			} else if (subject == tt_toolbox_vacuum) {
				code = GRASP_VACUUM;
			} else if (subject == tt_toolbox_expander) {
				code = GRASP_EXPANDER;
			} else if (subject == tt_toolbox) {  
				return; // no semantic meaning
			};
		} else { // e.g. puzzle game
			switch (subject->kind_of()) {
				case COPIER:
					code = GRASP_COPIER;
					break;
				case VACUUM:
					code = GRASP_VACUUM;
					break;
				case EXPANDER:
					code = GRASP_EXPANDER;
					break;
			};
		};
	};
	if (subject != NULL && subject->kind_of() == NEST) {
		// don't wait for subject to receieve something to apply tool
		switch (code) {
			case COPIER_APPLY:
				code = COPIER_APPLY_NEST; 
				break;
			case VACUUM_APPLY:
				code = VACUUM_APPLY_NEST; 
				break;
			case APPLY_GRASPED_ITEM:
				code = APPLY_GRASPED_NEST;
				break;
		};
	};
	if (subject != NULL && code == RELEASE_ITEM) {
		subject->set_available_for_indexing(TRUE);
//		switch (subject->kind_of()) {
      if (tt_toolbox != NULL) {
		   if (subject == tt_toolbox_copier) {
			   code = RELEASE_COPIER;
		   } else if (subject == tt_toolbox_vacuum) {
			   code = RELEASE_VACUUM;
         } else if (subject == tt_toolbox_expander) {
			   code = RELEASE_EXPANDER;
		   } else if (subject == tt_toolbox) { // was subject == tt_toolbox_expander || 
			   return;
		   };
      } else { // puzzle game
			switch (subject->kind_of()) {
				case COPIER:
					code = RELEASE_COPIER;
					break;
				case VACUUM:
					code = RELEASE_VACUUM;
					break;
				case EXPANDER:
					code = RELEASE_EXPANDER;
					break;
			};
		};
	};
	// safe cast?
	path = ((Floor *) floor)->compute_path(subject,code,(Robot *) by,notebook_page_really_selected
#if TT_POST3187
								 ,original_subject
#endif		
		     );
#if TT_CAREFUL
	if (path == NULL && subject != tt_toolbox) { // ignore actions on Toolbox...
#if TT_DEBUG_ON
#if TT_NEW_IO
		output_string_stream err_message;
#else
		string buffer = new char[10000];
		output_string_stream err_message(buffer,10000);
#endif
		err_message << "Warning: Robot is confused and couldn't find ";
		subject->describe(err_message,INDEFINITE_ARTICLE);
		err_message << ".";
		err_message.put('\0');
		say_error(err_message.STR,TRUE);
#if !TT_NEW_IO
		delete [] buffer;
#endif
		log(event_string(code));
#endif
		return;
//      working_set->insert_at_end_if_not_member(subject);
//      path = compute_path(subject);
	};
#endif
//	if (code == RELEASE_ITEM_ON && by->kind_of() == ROBOT_IN_TRAINING &&
//		 subject->kind_of() != PROGRAM_PAD && subject->is_container()) {  // notebooks use this as well as cubbies
////		 && subject->pointer_to_leader() != NULL) {
//      // is now part of something and should be accessed via that container
//		((Robot *) by)->remove_tool_from_working_set(subject);
//	};
   //on 5/27 re-wrote the above to match the similar situation in event.cpp
   // handled by now_released_on
//   if (code == RELEASE_ITEM_ON && by->kind_of() == ROBOT_IN_TRAINING &&
//       // except when dropping a cubby on a number since both are around afterwards
//       !(item_underneath != NULL && item_underneath->kind_of() == INTEGER &&
//         subject->kind_of() == CUBBY)) {
//      ((Robot *) by)->remove_tool_from_working_set(subject);
//   };
	if (code == LABEL_CHARACTER) {
		path->add_to_end(new Path(label_index));
	};
	if (code == NEW_MAIN_CUBBY) { // do this after computing the path
		floor->set_body_cubby((Cubby *) subject, by);
	};
	if ((code == GRASP_ITEM || code == GRASP_NEST) && !notebook_page_really_selected) {
		subject->set_available_for_indexing(FALSE); // does this ever get restored??
	};
	Event *event = new Event(code,path,key);
	if (tt_events == NULL) {
		tt_events = new Events(event,tt_events);
	} else {
		tt_events->insert_at_end(event);
	};
	if (new_item_event != NULL) {
		tt_events->insert_at_end(new_item_event);
	};
   if (by->kind_of() == ROBOT_IN_TRAINING &&
       code != SELECT_STACK_ITEM) {
       if (subject != ((Robot *) by)->pointer_to_initial_tool()) {
          ((Robot *) by)->decrement_training_counter();
       };
   };
};
static void extra_notify_state(unsigned long event, int enable)
{
	struct otg_notify *notify = NULL;

	if (!u_notify) {
		pr_err("u_notify is NULL\n");
		goto err;
	}

	pr_info("%s+ event=%s(%lu), enable=%s\n", __func__,
		event_string(event), event, enable == 0 ? "off" : "on");

	notify = get_otg_notify();

	switch (event) {
	case NOTIFY_EVENT_NONE:
		break;
	case NOTIFY_EVENT_OVERCURRENT:
		if (!u_notify->ndev.dev) {
			pr_err("ndev is NULL. Maybe usb host is not supported.\n");
			break;
		}
		host_state_notify(&u_notify->ndev,
						NOTIFY_HOST_OVERCURRENT);
		pr_err("OTG overcurrent!!!!!!\n");
		break;
	case NOTIFY_EVENT_VBUSPOWER:
		 if (enable)
			u_notify->ndev.booster = NOTIFY_POWER_ON;
		 else
			u_notify->ndev.booster = NOTIFY_POWER_OFF;
		break;
	case NOTIFY_EVENT_SMSC_OVC:
		if (enable)
			ovc_start(u_notify);
		else
			ovc_stop(u_notify);
		break;
	case NOTIFY_EVENT_SMTD_EXT_CURRENT:
		if (u_notify->c_type != NOTIFY_EVENT_SMARTDOCK_TA) {
			pr_err("No smart dock!!!!!!\n");
			break;
		}
		if (notify->set_battcall)
			notify->set_battcall
				(NOTIFY_EVENT_SMTD_EXT_CURRENT, enable);
		break;
	case NOTIFY_EVENT_MMD_EXT_CURRENT:
		if (u_notify->c_type != NOTIFY_EVENT_MMDOCK) {
			pr_err("No mmdock!!!!!!\n");
			break;
		}
		if (notify->set_battcall)
			notify->set_battcall
				(NOTIFY_EVENT_MMD_EXT_CURRENT, enable);
		break;
	default:
		break;
	}

	pr_info("%s- event=%s(%lu), cable=%s\n", __func__,
		event_string(event), event,
		event_string(u_notify->c_type));
err:
	return;
}
static void otg_notify_state(unsigned long event, int enable)
{
	struct otg_notify *notify = NULL;

	if (!u_notify) {
		pr_err("u_notify is NULL\n");
		goto no_save_event;
	}

	pr_info("%s+ event=%s(%lu), enable=%s\n", __func__,
		event_string(event), event, enable == 0 ? "off" : "on");

	notify = get_otg_notify();

	switch (event) {
	case NOTIFY_EVENT_NONE:
		break;
	case NOTIFY_EVENT_SMARTDOCK_USB:
	case NOTIFY_EVENT_VBUS:
		if (enable) {
			u_notify->ndev.mode = NOTIFY_PERIPHERAL_MODE;
			if (notify->is_wakelock)
				wake_lock(&u_notify->wlock);
			if (gpio_is_valid(notify->redriver_en_gpio))
				gpio_direction_output
					(notify->redriver_en_gpio, 1);
			if (notify->set_peripheral)
				notify->set_peripheral(true);
		} else {
			u_notify->ndev.mode = NOTIFY_NONE_MODE;
			if (notify->set_peripheral)
				notify->set_peripheral(false);
			if (gpio_is_valid(notify->redriver_en_gpio))
				gpio_direction_output
					(notify->redriver_en_gpio, 0);
			if (notify->is_wakelock)
				wake_unlock(&u_notify->wlock);
		}
		break;
	case NOTIFY_EVENT_LANHUB_TA:
		u_notify->diable_v_drive = enable;
		if (enable)
			u_notify->oc_noti = 0;
		if (notify->set_lanhubta)
			notify->set_lanhubta(enable);
		break;
	case NOTIFY_EVENT_LANHUB:
		if (notify->unsupport_host) {
			pr_err("This model doesn't support usb host\n");
			goto err;
		}
		u_notify->diable_v_drive = enable;
		if (enable) {
			u_notify->oc_noti = 0;
			u_notify->ndev.mode = NOTIFY_HOST_MODE;
			if (notify->is_wakelock)
				wake_lock(&u_notify->wlock);
			host_state_notify(&u_notify->ndev, NOTIFY_HOST_ADD);
			if (gpio_is_valid(notify->redriver_en_gpio))
				gpio_direction_output
					(notify->redriver_en_gpio, 1);
			if (notify->set_host)
				notify->set_host(true);
		} else {
			u_notify->ndev.mode = NOTIFY_NONE_MODE;
			if (notify->set_host)
				notify->set_host(false);
			if (gpio_is_valid(notify->redriver_en_gpio))
				gpio_direction_output
					(notify->redriver_en_gpio, 0);
			host_state_notify(&u_notify->ndev, NOTIFY_HOST_REMOVE);
			if (notify->is_wakelock)
				wake_unlock(&u_notify->wlock);
		}
		break;
	case NOTIFY_EVENT_HOST:
		if (notify->unsupport_host) {
			pr_err("This model doesn't support usb host\n");
			goto err;
		}
		u_notify->diable_v_drive = 0;
		if (enable) {
			u_notify->ndev.mode = NOTIFY_HOST_MODE;
			if (notify->is_wakelock)
				wake_lock(&u_notify->wlock);
			host_state_notify(&u_notify->ndev, NOTIFY_HOST_ADD);
			if (gpio_is_valid(notify->redriver_en_gpio))
				gpio_direction_output
					(notify->redriver_en_gpio, 1);
			if (notify->auto_drive_vbus) {
				u_notify->oc_noti = 1;
				if (notify->vbus_drive)
					notify->vbus_drive(1);
			}
			if (notify->set_host)
				notify->set_host(true);
		} else {
			u_notify->ndev.mode = NOTIFY_NONE_MODE;
			if (notify->auto_drive_vbus) {
				u_notify->oc_noti = 0;
				if (notify->vbus_drive)
					notify->vbus_drive(0);
			}
			if (notify->set_host)
				notify->set_host(false);
			if (gpio_is_valid(notify->redriver_en_gpio))
				gpio_direction_output
					(notify->redriver_en_gpio, 0);
			host_state_notify(&u_notify->ndev, NOTIFY_HOST_REMOVE);
			if (notify->is_wakelock)
				wake_unlock(&u_notify->wlock);
		}
		break;
	case NOTIFY_EVENT_CHARGER:
		if (notify->set_charger)
			notify->set_charger(enable);
		break;
	case NOTIFY_EVENT_MMDOCK:
		enable_ovc(u_notify, enable);
		/* To detect overcurrent, ndev state is initialized */
		if (enable)
			host_state_notify(&u_notify->ndev,
							NOTIFY_HOST_NONE);
	case NOTIFY_EVENT_SMARTDOCK_TA:
	case NOTIFY_EVENT_AUDIODOCK:
		if (notify->unsupport_host) {
			pr_err("This model doesn't support usb host\n");
			goto err;
		}
		u_notify->diable_v_drive = enable;
		if (enable) {
			u_notify->ndev.mode = NOTIFY_HOST_MODE;
			if (notify->is_wakelock)
				wake_lock(&u_notify->wlock);
			if (notify->set_host)
				notify->set_host(true);
		} else {
			u_notify->ndev.mode = NOTIFY_NONE_MODE;
			if (notify->set_host)
				notify->set_host(false);
			if (notify->is_wakelock)
				wake_unlock(&u_notify->wlock);
		}
		break;
	case NOTIFY_EVENT_DRIVE_VBUS:
		if (notify->unsupport_host) {
			pr_err("This model doesn't support usb host\n");
			goto no_save_event;
		}
		if (u_notify->diable_v_drive) {
			pr_info("cable type=%s disable vbus draw\n",
					event_string(u_notify->c_type));
			goto no_save_event;
		}
		u_notify->oc_noti = enable;
		if (notify->vbus_drive)
			notify->vbus_drive((bool)enable);
		goto no_save_event;
	default:
		break;
	}
err:
	if (enable)
		u_notify->c_type = event;
	else
		u_notify->c_type = NOTIFY_EVENT_NONE;

no_save_event:
	pr_info("%s- event=%s, cable=%s\n", __func__,
		event_string(event),
			event_string(u_notify->c_type));
}
示例#13
0
void run_gp(multipop *mpop, int startgen, event *t_eval, event *t_breed,
		int startfromcheckpoint) {
	char *param;
	int gen;
	int maxgen;
	int exch_gen;
	int i, j;
	int checkinterval;
	char *checkfileformat;
	char *checkfilename = NULL;
	event start, end, diff;
	int term = 0;
	termination_override =0;
	int stt_interval;
	int bestn;

	if (!startfromcheckpoint) {

		/* get the number of top individuals to track. */
		bestn = atoi(get_parameter("output.bestn"));
		if (bestn < 1) {
			error( E_WARNING,
					"\"output.bestn\" must be at least 1.  defaulting to 1.");
			bestn = 1;
		}

		/* allocate statistics for overall run. */
		run_stats = (popstats *) MALLOC((mpop->size + 1) * sizeof(popstats));
		for (i = 0; i < mpop->size + 1; ++i) {
			run_stats[i].bestn = bestn;
			run_stats[i].size = -1;
		}

		/* initialize the linked list of saved individuals. */
		saved_head = (saved_ind *) MALLOC(sizeof(saved_ind));
		saved_head->ind = NULL;
		saved_head->refcount = 0;
		saved_head->next = NULL;
		saved_tail = saved_head;
	}

	/* get the maximum number of generations. */
	param = get_parameter("max_generations");
	if (param == NULL)
		error( E_FATAL_ERROR, "no value specified for \"max_generations\".");
	maxgen = atoi(param);
	if (maxgen <= 0)
		error( E_FATAL_ERROR, "\"max_generations\" must be greater than zero.");

	/* get the interval for subpopulation exchanges, if there is more than
	 one subpopulation. */
	if (mpop->size > 1) {
		param = get_parameter("multiple.exch_gen");
		if (param == NULL)
			error( E_FATAL_ERROR,
					"no value specified for \"multiple.exch_gen\".");
		exch_gen = atoi(param);
		if (exch_gen <= 0)
			error( E_FATAL_ERROR,
					"\"multiple.exch_gen\" must be greater than zero.");
	}

	/* get the interval for doing checkpointing. */
	param = get_parameter("checkpoint.interval");
	if (param == NULL)
		/* checkpointing disabled. */
		checkinterval = -1;
	else
		checkinterval = atoi(param);

	/* get the format string for the checkpoint filenames. */
	checkfileformat = get_parameter("checkpoint.filename");
	checkfilename = (char *) MALLOC(strlen(checkfileformat) + 50);

	/* get the interval for writing information to the .stt file. */
	stt_interval = atoi(get_parameter("output.stt_interval"));
	if (stt_interval < 1)
		error( E_FATAL_ERROR,
				"\"output.stt_interval\" must be greater than zero.");

	oputs( OUT_SYS, 10, "\n\nstarting evolution.\n");

	/* print out how often we'll be doing checkpointing. */
	if (checkinterval > 0)
		oprintf( OUT_SYS, 20,
				"checkpointing will be done every %d generations and "
						"after the last generation.\n", checkinterval);
	else if (checkinterval == 0)
		oprintf( OUT_SYS, 20, "checkpointing will be done only after the last "
				"generation.\n");
	else
		oprintf( OUT_SYS, 20, "no checkpointing will be done.\n");

	/* the big loop. */
	for (gen = startgen; gen < maxgen && !term; ++gen) {
		oprintf( OUT_SYS, 20, "=== generation %d.\n", gen);
		generation_No = gen;
		/* unless this is the first generation after loading a checkpoint
		 file... */
		if (!(startfromcheckpoint && gen == startgen)) {

			/* evaluate the population. */
			event_mark(&start);
			for (i = 0; i < mpop->size; ++i) { //generation_No = i;
				evaluate_pop(mpop->pop[i]);
			}
			event_mark(&end);
			event_diff(&diff, &start, &end);

#ifdef TIMING_AVAILABLE
			oprintf( OUT_SYS, 40, "    evaluation complete.  (%s)\n",
					event_string(&diff));
#else
			oprintf ( OUT_SYS, 40, "    evaluation complete.\n" );
#endif

			event_accum(t_eval, &diff);

			/* calculate and print statistics.  returns 1 if user termination
			 criterion was met, 0 otherwise. */
			term = generation_information(gen, mpop, stt_interval,
					run_stats[0].bestn);
			if (term) {
				//oprintf( OUT_SYS, 30, "user termination criterion met.\n");
				/*extern float *optimal_in_generation;
				extern int *optimal_index_in_generation;
				extern int same_optimal_count;
				int i;
				for (i = 0; i < generationSIZE; i++) {
					if ((int) optimal_in_generation[i] == -1) {
						printf("tried to Break");
						break;
					}
					printf("Index: %d ERR : %f -Index %d Same : %i\n", i,
							optimal_in_generation[i],
							optimal_index_in_generation[i], same_optimal_count);
				}*/
			}
			flush_output_streams();

		}

		/** write a checkpoint file if checkinterval is non-negative and:
		 we've reached the last generation, or
		 the user termination criterion has been met, or
		 we've reached the specified checkpoint interval. **/
		if (checkinterval >= 0
				&& (gen == maxgen || term
						|| (checkinterval > 0 && gen > startgen
								&& (gen % checkinterval) == 0))) {
			sprintf(checkfilename, checkfileformat, gen);
			write_checkpoint(gen, mpop, checkfilename);
		}

		/** if this is not the last generation and the user criterion hasn't
		 been met, then do breeding. **/
		if (gen != maxgen && !term) {

			/** exchange subpops if it's time. **/
			if (mpop->size > 1 && gen && (gen % exch_gen) == 0) {
				exchange_subpopulations(mpop);
				oprintf( OUT_SYS, 10, "    subpopulation exchange complete.\n");
			}

			/* breed the new population. */
			event_mark(&start);
			for (i = 0; i < mpop->size; ++i)
				mpop->pop[i] = change_population(mpop->pop[i], mpop->bpt[i]);
			event_mark(&end);
			event_diff(&diff, &start, &end);

			/* call the application end-of-breeding callback. */
			app_end_of_breeding(gen, mpop);

#ifdef TIMING_AVAILABLE
			oprintf( OUT_SYS, 30, "    breeding complete.    (%s)\n",
					event_string(&diff));
#else
			oprintf ( OUT_SYS, 30, "    breeding complete.\n" );
#endif

			event_accum(t_breed, &diff);

		}

		/* free unused ERCs. */
		ephem_const_gc();

		flush_output_streams();

	}

	/** free up a lot of stuff before returning. */

	if (checkfilename)
		FREE(checkfilename);

	ephem_const_gc();

	for (i = 0; i < mpop->size + 1; ++i) {
		for (j = 0; j < run_stats[i].bestn; ++j)
			--run_stats[i].best[j]->refcount;
		FREE(run_stats[i].best);
	}
	FREE(run_stats);

	saved_individual_gc();
	FREE(saved_head);
}