static int is_magenta(IplImage *img, int x, int y) { uint8_t *data = (uint8_t*)img->imageData; data += y * img->widthStep + (x*img->nChannels); uint8_t r = data[0], g = data[1], b = data[2]; if (MAGENTA(r, g, b)) return 1; return 0; }
int main(void) { EMQ::Client client(ADDR, EMQ_DEFAULT_PORT); bool status; std::cout << MAGENTA("This is a simple example of using libemq++") << std::endl; if (!EMQ::compatible()) { std::cout << RED("[Warning]") << " Used incompatible version libemq" << std::endl; } if (client.connected()) { std::cout << YELLOW("[Success]") << " Connected to " << ADDR << ":" << EMQ_DEFAULT_PORT << std::endl; status = client.auth("eagle", "eagle"); CHECK_STATUS("Auth", status); status = client.queue.create(".queue-test", 10, 100, EMQ_QUEUE_FORCE_PUSH | EMQ_QUEUE_AUTODELETE); CHECK_STATUS("Queue create", status); status = client.queue.declare(".queue-test"); CHECK_STATUS("Queue declare", status); status = client.queue.subscribe(".queue-test", EMQ_QUEUE_SUBSCRIBE_MSG, queue_message_callback); CHECK_STATUS("Queue subscribe", status); std::thread thread = std::thread(worker); status = client.process(); CHECK_STATUS("Channel process", status); thread.join(); client.disconnect(); } else { std::cout << RED("[Error]") << " Error connect to " << ADDR << ":" << EMQ_DEFAULT_PORT << std::endl; } return 0; }
int main(void) { EMQ::Client client(ADDR, EMQ_DEFAULT_PORT); bool status; std::cout << MAGENTA("This is a simple example of using libemq++") << std::endl; if (!EMQ::compatible()) { std::cout << RED("[Warning]") << " Used incompatible version libemq" << std::endl; } if (client.connected()) { std::cout << YELLOW("[Success]") << " Connected to " << ADDR << ":" << EMQ_DEFAULT_PORT << std::endl; status = client.auth("eagle", "eagle"); CHECK_STATUS("Auth", status); status = client.channel.create(".channel-test", EMQ_CHANNEL_AUTODELETE | EMQ_CHANNEL_ROUND_ROBIN); CHECK_STATUS("Channel create", status); status = client.channel.psubscribe(".channel-test", "world.belarus.*", channel_message_callback); CHECK_STATUS("Channel psubscribe", status); std::thread thread1 = std::thread(worker); std::thread thread2 = std::thread(worker); status = client.process(); CHECK_STATUS("Channel process", status); thread1.join(); thread2.join(); client.disconnect(); } else { std::cout << RED("[Error]") << " Error connect to " << ADDR << ":" << EMQ_DEFAULT_PORT << std::endl; } return 0; }
void am_notice(const char *pretty_func, const char *_file, int line, const char *_format, ...) { init(); if (AM_UNLIKELY(AM_LOG_LEVEL_NOTICE <= logLevel)) { char text[2*1024] = {0}; char module[256] = {0}; char func[256] = {0}; char file[256] = {0}; char format[2*1024] = {0}; va_list vlist; function_name(func, sizeof(func), pretty_func); class_name(module, sizeof(module), pretty_func); file_name(file, sizeof(file), _file); snprintf(format, sizeof(format), "%s", _format); if (format[strlen(format) - 1] == '\n') { //Eat trailing \n, \n will be added automatically! format[strlen(format) - 1] = '\0'; } if (logTarget == AM_LOG_TARGET_SYSLOG) { sprintf(text, "[%6s][%s:%d: %s]: %s", "NOTICE", file, line, func, format); } else if (logTarget == AM_LOG_TARGET_FILE) { sprintf(text, "[%20s][%6s][%s:%d: %s]: %s", module, "NOTICE", file, line, func, format); } else { sprintf(text, "["B_GREEN("%20s")"]["B_MAGENTA("%6s")"]"\ CYAN("[%s:%d: %s]: ")MAGENTA("%s"), module, "NOTICE", file, line, func, format); } va_start(vlist, _format); am_level_logv(module, AM_LOG_LEVEL_NOTICE, text, vlist); va_end(vlist); } }
int main(int argc, char *argv[]) { struct termios tp; struct timeval tv; int fds; fd_set watchset; char ch = 0; int song; MAGENTA(); printf("NDS Music Player, libao edition\n"); printf("Version 4.0\n"); printf("Using vio2sf 0.15\n"); NORMAL(); // check if an argument was given if (argc < 2) { RED(); printf("Error: must specify a filename or names!\n"); NORMAL(); return -1; } GREEN(); printf("Press ESC or Q to stop. p = previous song, n = next song\n\n", argv[1]); NORMAL(); if (setup_playback(argv[1]) < 0) { return -1; } tcgetattr(STDIN_FILENO, &tp); tp.c_lflag &= ~ICANON; tp.c_lflag &= ~(ECHO | ECHOCTL | ECHONL); tcsetattr(STDIN_FILENO, TCSANOW, &tp); ch = 0; song = 1; while ((ch != 27) && (ch != 'q') && (ch != 'Q')) { fds = STDIN_FILENO; FD_ZERO(&watchset); FD_SET(fds, &watchset); tv.tv_sec = 0; tv.tv_usec = 16666/2; // timeout every 1/120th of a second if (select(fds+1, &watchset, NULL, NULL, &tv)) { ch = getchar(); // (blocks until something is pressed) } else { ch = 0; } m1sdr_TimeCheck(); // Added the ability to press the n key to goto the next song if ((ch == 'n') && ((song+1) < argc)) { xsf_term(); m1sdr_Exit(); if (c) { free(c); c = NULL; } free(buffer); song++; if (setup_playback(argv[song]) < 0) { ch = 27; } } if ((ch == 'p') && (song > 1)) { xsf_term(); m1sdr_Exit(); if (c) { free(c); c = NULL; } free(buffer); song--; if (setup_playback(argv[song]) < 0) { ch = 27; } } } xsf_term(); tcgetattr(STDIN_FILENO, &tp); tp.c_lflag |= ICANON; tp.c_lflag |= (ECHO | ECHOCTL | ECHONL); tcsetattr(STDIN_FILENO, TCSANOW, &tp); free(buffer); return 1; }
// load and set up a 2sf file int read_in_file(char *name) { FILE *file; uint32 filesig; uint8 *filedata; uint64 file_len; unsigned int size; struct stat st; c = NULL; file = fopen(name, "rb"); if (!file) { RED(); printf("ERROR: could not open file %s\n", name); NORMAL(); return -1; } // get the length of the file by using fstat fstat(fileno(file), &st); if (st.st_size > UINT_MAX) { fclose(file); RED(); printf("ERROR: file size of %zu bytes is larger than maximum supported value of %u\n", st.st_size, UINT_MAX); NORMAL(); return -1; } size = (unsigned int) st.st_size; buffer = malloc((size_t) size); if (!buffer) { fclose(file); RED(); printf("ERROR: could not allocate %d bytes of memory\n", size); NORMAL(); return -1; } // read the file fread(buffer, size, 1, file); fclose(file); // init our *SF engine so we can get tags if (corlett_decode(buffer, size, &filedata, &file_len, &c) != AO_SUCCESS) { RED(); printf("ERROR: Tag format unreadable in file "); MAGENTA(); printf("%s\n", name); NORMAL(); return -1; } free(filedata); // we don't use this if (xsf_start(buffer, size) != XSF_TRUE) { RED(); printf("ERROR: vio2sf failed to load file \n"); MAGENTA(); printf("%s\n", name); NORMAL(); return -1; } return 0; }