1/* BEGIN LICENSE BLOCK 2 * Version: CMPL 1.1 3 * 4 * The contents of this file are subject to the Cisco-style Mozilla Public 5 * License Version 1.1 (the "License"); you may not use this file except 6 * in compliance with the License. You may obtain a copy of the License 7 * at www.eclipse-clp.org/license. 8 * 9 * Software distributed under the License is distributed on an "AS IS" 10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 11 * the License for the specific language governing rights and limitations 12 * under the License. 13 * 14 * The Original Code is The ECLiPSe Constraint Logic Programming System. 15 * The Initial Developer of the Original Code is Cisco Systems, Inc. 16 * Portions created by the Initial Developer are 17 * Copyright (C) 1997-2006 Cisco Systems, Inc. All Rights Reserved. 18 * 19 * Contributor(s): 20 * 21 * END LICENSE BLOCK */ 22 23/* 24 * DESCRIPTION: 25 * Example of posting events to ECLiPSe 26 */ 27 28#include "eclipseclass.h" 29#include <iostream> 30#include <signal.h> 31#include <unistd.h> 32 33void 34handle_alarm(int i) 35{ 36 post_event(EC_atom("abort")); 37} 38 39 40int 41main(int argc,char ** argv) 42{ 43 ec_init(); 44 int res; 45 46 signal(SIGALRM, handle_alarm); 47 48 alarm(1); /* or setitimer(...) */ 49 50 post_goal("between(1,99999,1,X), writeln(X), fail"); 51 switch (EC_resume()) 52 { 53 case EC_succeed: std::cout << "Succeeded\n"; break; 54 case EC_fail: std::cout << "Failed\n"; break; 55 case EC_throw: std::cout << "Aborted\n"; break; 56 default: std::cout << "???\n"; break; 57 } 58 59 ec_cleanup(); 60 exit(0); 61} 62 63