Пример #1
0
extern "C" void Start(Baton *baton) {
    struct _pthread self;
    $bzero(&self, sizeof(self));

    const mach_header_xx *pthread(Library(baton, "/usr/lib/system/libsystem_pthread.dylib"));
    if (pthread == NULL)
        pthread = Library(baton, "/usr/lib/system/libsystem_c.dylib");

    void (*$__pthread_set_self)(pthread_t);
    cyset($__pthread_set_self, "___pthread_set_self", pthread);

    self.tsd[0] = &self;
    $__pthread_set_self(&self);

    int (*$pthread_create)(pthread_t *, const pthread_attr_t *, void *(*)(void *), void *);
    cyset($pthread_create, "_pthread_create", pthread);

    pthread_t thread;
    $pthread_create(&thread, NULL, &Routine, baton);

    const mach_header_xx *kernel(Library(baton, "/usr/lib/system/libsystem_kernel.dylib"));

    mach_port_t (*$mach_thread_self)();
    cyset($mach_thread_self, "_mach_thread_self", kernel);

    kern_return_t (*$thread_terminate)(thread_act_t);
    cyset($thread_terminate, "_thread_terminate", kernel);

    $thread_terminate($mach_thread_self());
}
Пример #2
0
/** Load library. If dir is non-empty then find library there (dir MUST include trailing '/'), otherwise use runtime linker's search path (LD_LIBRARY_PATH) */
library::Library library::load (Libname libname, std::string dir) {
	std::string err;
	void* lib = dlopen ((dir + "lib" + libname + ".so").c_str(), RTLD_LAZY);
	if (!lib) {
		err += std::string (dlerror());
		lib = dlopen ((dir + "lib" + libname + ".dylib").c_str(), RTLD_LAZY);
	}
	if (!lib) {
		err += "\n" + std::string (dlerror());
		throw std::runtime_error ("Cannot open library " + dir + "lib" + libname + ".so(.dylib):\n" + err);
	}
	return Library (libname, lib);
}
Пример #3
0
void *Routine(void *arg) {
    Baton *baton(reinterpret_cast<Baton *>(arg));

    const mach_header_xx *dyld(Library(baton, "/usr/lib/system/libdyld.dylib"));

    Dynamic dynamic;
    cyset(dynamic.dlerror, "_dlerror", dyld);
    cyset(dynamic.dlsym, "_dlsym", dyld);

    int (*pthread_detach)(pthread_t);
    dlset(&dynamic, pthread_detach, "pthread_detach");

    pthread_t (*pthread_self)();
    dlset(&dynamic, pthread_self, "pthread_self");

    pthread_detach(pthread_self());

    void *(*dlopen)(const char *, int);
    dlset(&dynamic, dlopen, "dlopen");

    void *handle(dlopen(baton->library, RTLD_LAZY | RTLD_LOCAL));
    if (handle == NULL) {
        dynamic.dlerror();
        return NULL;
    }

    void (*CYHandleServer)(pid_t);
    dlset(&dynamic, CYHandleServer, "CYHandleServer", handle);
    if (CYHandleServer == NULL) {
        dynamic.dlerror();
        return NULL;
    }

    CYHandleServer(baton->pid);
    return NULL;
}
Пример #4
0
 int main()
 {
	 string keep;
	 bool run=true;
	 int bookOrder=0;

	 Library ustcLibrary=Library();
	 while(run)
	 {
		 cout<<"-------------------主菜单---------------------\n";
		cout<<"0.退出\t1.添加\t2.查询\t3.借书\t4.还书\t5.费用\n";
		cout<<"请选择操作:\n";

		int  mainOperator=0;
		cin>>mainOperator;
	
		switch(mainOperator)
		{
		case 0:
			run=false;
			break;
		case 1:
			cout<<"------------添加子菜单------------\n";
			cout<<"0.返回\t1.添加图书\t2.添加读者\n";
			cout<<"请选择操作:\n";

			int addOperator=0;
			cin>>addOperator;

			switch(addOperator)
			{
			case 0:
				break;
			case 1:
				
				bookOrder=2;

				string strISBN;
				string strName;
				string strAuthor;
				string strPulishedDate;
				string getId;
				string getName;
				string getAuthor;
				string getPublishedDate;
				cout<<"----------添加图书----------\n";
				cout<<"请依次输入图书的ISBN码,书名,作者和出版日期:\n";
				cin>>strISBN>>strName>>strAuthor>>strPulishedDate;

				Book  newBook=Book(strISBN,strName,strAuthor,strPulishedDate);
				getId=newBook.GetISBNNum();
				bool wrongOnce=false;
				while(getId=="") 
				{
					wrongOnce=true;
					cout<<"请重新输入:\n";
					cin>>strISBN>>strName>>strAuthor>>strPulishedDate;
					Book newBook=Book(strISBN,strName,strAuthor,strPulishedDate);
					getId=newBook.GetISBNNum();
					getName=newBook.GetName();
					getAuthor=newBook.GetAuthor();
					getPublishedDate=newBook.GetDat();
				}
				if(wrongOnce)
				{
					Book rightBook=Book(getId,getName,getAuthor,getPublishedDate);
					ustcLibrary.AddBook(rightBook);
				}
				else
				{
					ustcLibrary.AddBook(newBook);
				}
				

			}

			break;
		}
	 }
	

	
	/*图书
	 //1.1初始化图书信息
	 Book newBook1= Book("1-2-2-s","面向对象技术1","林典鹏","2013-09-12");		//right
	 Book newBook2= Book("1-3-s-s","面向对象技术2","胡希望能","2013-09-12");		//wrong
	 Book newBook3=Book("1-2-3-w","C++ program","Jhon Tom","2012-10-19");
	 //1,2返回图书信息
	 cout<< newBook1.GetAuthor()<<endl;
	 cout<<newBook1.GetDat()<<endl;
	 cout<<newBook1.GetISBNNum()<<endl;
	 cout<<newBook1.GetIsOut()<<endl;
	 cout<<newBook1.GetName()<<endl;
	 newBook1.DisplayInfo();	//总体显示信息
// 


 ///*读者
	 //2.1初始化读者信息
	 Patron linPatron =Patron("林弘伟","PB11210245");
	 Patron wangPatron=Patron("王云峰","PB11210234");
	 Patron liPatron=Patron("李敏","SA11023234");
	 Patron xPatron=Patron("XJhon","PB12210345");
	 //2.2显示读者信息
	 linPatron.DisplayInfo();
	 wangPatron.DisplayInfo();
	 liPatron.DisplayInfo();
	 //2.3设定借书费
	 linPatron.SetOweCount(23.4);
	 //2.4显示是否欠费
	 linPatron.IsOwed();
	 linPatron.DisplayInfo();
// 

 ///*图书馆
	 //3.1新建图书馆
	 Library ustcLibrary=Library();
	 //3.2添加图书
	 ustcLibrary.AddBook(newBook1);					//right
	 ustcLibrary.AddBook(newBook2);					//wrong
	 ustcLibrary.AddBook(newBook3);
	 //3.3添加读者
	 ustcLibrary.AddPatron(linPatron);
	 ustcLibrary.AddPatron(wangPatron);
	 ustcLibrary.AddPatron(xPatron);
	 //3.4借书
	 ustcLibrary.LendABookToPatron(newBook1,wangPatron);		//欠费
	 ustcLibrary.LendABookToPatron(newBook1,wangPatron);	//未欠费
	 ustcLibrary.LendABookToPatron(newBook3,xPatron);
	// ustcLibrary.LendABookToPatron(newBook1,liPatron);		//已经借出
	 //3.5显示欠费读者列表
	 ustcLibrary.GetOwedInfo();
	 ustcLibrary.DisplayOut();
	 ustcLibrary.ReturnBook(newBook1,wangPatron);
	 ustcLibrary.DisplayOut();
//*/

	// cin>>keep;
 }
Пример #5
0
Library::~Library()
{

}

GCOFactory* Library::getFactory(FrComponentType ct)
{
    std::map<FrItemType, GCOFactory*>::iterator iter = _factories.find(ct);
    if (iter != _factories.end())
    {
        return iter->second;
    }
    return NULL;
}

Library theLibrary = Library();


FrItem gioCreateItem(FrItemType ct, FrMsg m, FrMsgLength l)
{
    GCOFactory* f = theLibrary.getFactory(ct);
    if (f != NULL) {
        return f->createItem(m, l);
    }
    else {
        return NULL;
    }
}

void gioDestroyItem(FrComponentType ct, FrItem it)
{
Пример #6
0
static _finline const mach_header_xx *Library(Baton *baton, const char *name) {
    struct dyld_all_image_infos *infos(reinterpret_cast<struct dyld_all_image_infos *>(baton->dyld));
    return Library(infos, name);
}