source: trunk/Cocoa/F-Script Anywhere/Source/SCPatch/SCPatchClient/SCPatchClient.cpp@ 226

Last change on this file since 226 was 217, checked in by rchin, 19 years ago
  • Updated to new mach_inject with support for x86
  • Updated nib files to 10.2+ format so that future updates to the f-script framework won't break fsa
  • Adjusted some code to work with the new x86 mach_inject (sends an additional argument)
  • Updates code to work with newer defines in cctools
File size: 2.1 KB
Line 
1#include <mach/mach_init.h>
2extern "C"
3{
4 #include <mach/thread_act.h>
5 #include <pthread.h>
6 #include <unistd.h>
7}
8
9#include <Carbon/Carbon.h>
10#include "mach_inject.h"
11#include "SCPatchClient.h"
12
13#ifdef __MWERKS__
14#pragma export on
15#endif
16
17//-------------------------------------------------------------------------------------------------------------
18mach_error_t SCPatchInit( SCPatchParams *params )
19{
20 ProcessSerialNumber psn;
21 mach_error_t err = err_none;
22 SCPatchClient *client = SCPatchClient::GetPatchClientPointer();
23
24 if(client == NULL)
25 {
26 fprintf(stderr, "SCPc: sGlobalPatchClientInstance is not set!\n");
27 return err_sub(EFAULT);
28 }
29
30 client->mPatchParams = *params;
31 client->mClientBundleID = CFStringCreateWithCharacters(NULL, params->patchBundleID.unicode, params->patchBundleID.length);
32 client->mControllerBundleID = CFStringCreateWithCharacters(NULL, client->mPatchParams.parentBundleID.unicode, client->mPatchParams.parentBundleID.length);
33
34 // Just in case
35 if(client->mClientBundleID == NULL || client->mControllerBundleID == NULL)
36 return err_sub(ENOMEM);
37
38 if(client->Initialize(client->mClientBundleID, client->mControllerBundleID, getpid()) != noErr)
39 return err_threadEntry_image_not_found;
40
41 // Create a port to receive messages from our patch controller
42 if((err = client->StartListening(client->mClientBundleID, true, true)) != noErr)
43 return err_threadEntry_image_not_found;
44
45 if((err = GetCurrentProcess(&psn)) != noErr ||
46 (err = client->SendMessage(client->mControllerBundleID, NULL, kSCMessageClass, kSCPatchSuccess,
47 "bndl: TEXT(@), proc: psn (@)",
48 CFStringGetCStringPtr(client->mClientBundleID, kCFStringEncodingMacRoman),
49 sizeof(ProcessSerialNumber), &psn)) != noErr)
50 return err_threadEntry_image_not_found;
51
52 return noErr;
53}
54#ifdef __MWERKS__
55#pragma export off
56#endif
57
58//-------------------------------------------------------------------------------------------------------------
59SCPatchClient::SCPatchClient(void)
60{
61}
62
63//-------------------------------------------------------------------------------------------------------------
64SCPatchClient::~SCPatchClient(void)
65{
66}
Note: See TracBrowser for help on using the repository browser.